A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
fix(sim): overlapping office terms must agree on party
eyalgolanea9e5aa3bfa5
diff --git a/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs b/sim/Statecraft.Sim.Tests/ContentLoaderTests.csindex 79b7b4fd6..b74ab6107 100644--- a/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs+++ b/sim/Statecraft.Sim.Tests/ContentLoaderTests.cs@@ -67,6 +67,20 @@ public class ContentLoaderTestsAssert.Equal("people[def_two].offices.finance_minister.party", ex.Field);}+ [Fact]+ public void OverlappingTermsMustAgreeOnParty()+ {+ var bad = Fixture.Files["people.yaml"]+ .Replace(" - office: prime_minister\n from: 1948-05-14\n", " - office: prime_minister\n from: 1948-05-14\n party: alpha\n")+ .Replace(" - office: defense_minister\n from: 1948-05-14\n", " - office: defense_minister\n from: 1948-05-14\n party: beta\n");+ Assert.Equal(2, bad.Split("party: ").Length - 1);+ var ex = Assert.Throws<ContentException>(() => ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = bad })));+ Assert.Equal("people.yaml", ex.File);+ Assert.Equal("people[pm_one].offices", ex.Field);+ Assert.Contains("overlapping terms disagree on party", ex.Message);+ ContentLoader.Load(Fixture.Write(new Dictionary<string, string> { ["people.yaml"] = bad.Replace("party: beta", "party: alpha") }));+ }+[Fact]public void OfficeTermEndingBeforeItStartsIsAnError(){diff --git a/sim/Statecraft.Sim/ContentLoader.cs b/sim/Statecraft.Sim/ContentLoader.csindex 5f3f61f7d..21c292011 100644--- a/sim/Statecraft.Sim/ContentLoader.cs+++ b/sim/Statecraft.Sim/ContentLoader.cs@@ -108,6 +108,15 @@ namespace Statecraft.Simif (t.To.HasValue && t.To.Value <= t.From) throw new ContentException("people.yaml", $"people[{p.Id}].offices.{t.Office}", FormattableString.Invariant($"term ends ({t.To:yyyy-MM-dd}) before it starts ({t.From:yyyy-MM-dd})"));}}+ foreach (var p in c.People)+ for (int i = 0; i < p.Offices.Count; i++)+ for (int j = i + 1; j < p.Offices.Count; j++)+ {+ var (a, b) = (p.Offices[i], p.Offices[j]);+ if (a.Party == "" || b.Party == "" || a.Party == b.Party) continue;+ if (a.From < (b.To ?? DateTime.MaxValue) && b.From < (a.To ?? DateTime.MaxValue))+ throw new ContentException("people.yaml", $"people[{p.Id}].offices", "overlapping terms disagree on party");+ }var terms = c.People.SelectMany(p => p.Offices.Select(t => (person: p.Id, term: t))).ToList();for (int i = 0; i < terms.Count; i++)for (int j = i + 1; j < terms.Count; j++)