A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
Assert non-empty filtered sets before content loops (Refs #2593) (#2875)
agamrafaeli-instinct5aaf069d13dd
diff --git a/changelog.d/2593-nonempty-filtered-sets.md b/changelog.d/2593-nonempty-filtered-sets.mdnew file mode 100644index 000000000..7417a1e71--- /dev/null+++ b/changelog.d/2593-nonempty-filtered-sets.md@@ -0,0 +1,3 @@+### Fixed+- Seven content-looping tests now assert their filtered set is non-empty before the loop, so they cannot pass while+ checking nothing (#2593).diff --git a/sim/Statecraft.Sim.Tests/CauseKeysTests.cs b/sim/Statecraft.Sim.Tests/CauseKeysTests.csindex cdc07184e..ecf892bb6 100644--- a/sim/Statecraft.Sim.Tests/CauseKeysTests.cs+++ b/sim/Statecraft.Sim.Tests/CauseKeysTests.cs@@ -66,7 +66,9 @@ public class CauseKeysTests[Fact]public void TheValuesAreTheNumbersTheLineNames(){- foreach (var w in Run(Real, 1000).Where(w => w.Key != ""))+ var keyed = Run(Real, 1000).Where(w => w.Key != "").ToList();+ Assert.NotEmpty(keyed);+ foreach (var w in keyed)switch (w.Key){case CauseKeys.MoneyFlows:diff --git a/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs b/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.csindex 1fbc9eeee..5dd981db5 100644--- a/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs+++ b/sim/Statecraft.Sim.Tests/EconomyCalibrationTests.cs@@ -81,7 +81,9 @@ public class EconomyCalibrationTests[Fact]public void ExportsCoverUnderAThirdOfImportsIn1950And1951(){- foreach (var s in History.Where(s => s.Date.Year == 1950 || s.Date.Year == 1951))+ var years = History.Where(s => s.Date.Year == 1950 || s.Date.Year == 1951).ToList();+ Assert.NotEmpty(years);+ foreach (var s in years){var ratio = C.Rules.ExportsPerYear / (C.Rules.ImportsPerCapitaPerYear * s.TotalPopulation);Assert.True(ratio < 1.0 / 3, $"[consistency: exports and imports were chosen to satisfy this] {s.Date:yyyy-MM-dd}: exports cover {ratio:P0} of imports");diff --git a/sim/Statecraft.Sim.Tests/FieldsTests.cs b/sim/Statecraft.Sim.Tests/FieldsTests.csindex 9110adbb0..991312211 100644--- a/sim/Statecraft.Sim.Tests/FieldsTests.cs+++ b/sim/Statecraft.Sim.Tests/FieldsTests.cs@@ -198,7 +198,9 @@ public class FieldsTestsvar c = ContentLoader.Load(RealContentTests.ContentRoot());var m = c.Rules.Mvp!;Assert.Equal((1, 3, 0.5), (m.FieldFoodPerTurn!.Value, m.PlowFieldsTurns, m.PlowFieldsCost!.Value));- foreach (var f in c.Sites.Where(x => x.Kinds.Contains(Projects.FieldKind)))+ var fields = c.Sites.Where(x => x.Kinds.Contains(Projects.FieldKind)).ToList();+ Assert.NotEmpty(fields);+ foreach (var f in fields)Assert.Contains(c.Sites, y => (y.Kinds.Contains(Projects.YishuvKind) || y.Kinds.Contains(Projects.SwampKind)) && (y.Q, y.R) == (f.Q, f.R));}}diff --git a/sim/Statecraft.Sim.Tests/Governments1952To1956Tests.cs b/sim/Statecraft.Sim.Tests/Governments1952To1956Tests.csindex 0e5cbe121..25fa87968 100644--- a/sim/Statecraft.Sim.Tests/Governments1952To1956Tests.cs+++ b/sim/Statecraft.Sim.Tests/Governments1952To1956Tests.cs@@ -28,8 +28,9 @@ public class Governments1952To1956Tests[Fact]public void EveryMinistersTermFromTheFourthGovernmentOnLiesInsideOneGovernment(){- foreach (var p in C.People)- foreach (var t in p.Offices.Where(t => !NotMinisters.Contains(t.Office) && (t.To ?? DateTime.MaxValue) > Fourth))+ var terms = C.People.SelectMany(p => p.Offices.Where(t => !NotMinisters.Contains(t.Office) && (t.To ?? DateTime.MaxValue) > Fourth).Select(t => (p, t))).ToList();+ Assert.NotEmpty(terms);+ foreach (var (p, t) in terms){var g = Offices.Government(C, t.From);Assert.True(g != null, $"{p.Id} {t.Office} from {t.From:yyyy-MM-dd}: no government");diff --git a/sim/Statecraft.Sim.Tests/SitesContentTests.cs b/sim/Statecraft.Sim.Tests/SitesContentTests.csindex f052db448..cd7bb84fb 100644--- a/sim/Statecraft.Sim.Tests/SitesContentTests.cs+++ b/sim/Statecraft.Sim.Tests/SitesContentTests.cs@@ -169,7 +169,9 @@ public class SitesContentTestspublic void EachYishuvSiteHasOneFieldSiteInItsHex(){var c = ContentLoader.Load(RealContentTests.ContentRoot());- foreach (var y in c.Sites.Where(x => x.Kinds.Contains("yishuv")))+ var yishuvs = c.Sites.Where(x => x.Kinds.Contains("yishuv")).ToList();+ Assert.NotEmpty(yishuvs);+ foreach (var y in yishuvs){var others = c.Sites.Where(x => x != y && x.Q == y.Q && x.R == y.R).ToList();var field = Assert.Single(others);diff --git a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs b/unity/Assets/Tests/EditMode/UnitsInPlayTests.csindex e74c20fd1..bcdafddfd 100644--- a/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs+++ b/unity/Assets/Tests/EditMode/UnitsInPlayTests.cs@@ -179,7 +179,9 @@ public class UnitsInPlayTests[Test]public void HebrewUnitNumbersAreSourcedAndAgentChecked(){- foreach (var u in Units.Where(u => !string.IsNullOrEmpty(u.NumberHe)))+ var withNumberHe = Units.Where(u => !string.IsNullOrEmpty(u.NumberHe)).ToList();+ Assert.IsNotEmpty(withNumberHe);+ foreach (var u in withNumberHe){StringAssert.IsMatch("[א-ת]", u.NumberHe, u.Id);Assert.AreEqual("agent-checked", u.NumberHeReview, u.Id);@@ -195,7 +197,9 @@ public class UnitsInPlayTests{var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");var state = StateAt(C.Rules.Start, 5, 0.8);- foreach (var u in Units.Where(u => !string.IsNullOrEmpty(u.NumberHe)))+ var withNumberHe = Units.Where(u => !string.IsNullOrEmpty(u.NumberHe)).ToList();+ Assert.IsNotEmpty(withNumberHe);+ foreach (var u in withNumberHe){var anchor = u.Anchors.FirstOrDefault() ?? new UnitAnchor { Place = "test position" };var placed = new PlacedToken(new UnitToken(u, anchor, 0, "", false), default);