Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

test(sim): pin cause arguments and editor digest validation (#1995)

Eyal Golanc192c17740e3
diff --git a/changelog.d/release-cause-parser-coverage.md b/changelog.d/release-cause-parser-coverage.md
new file mode 100644
index 000000000..3d11c1f60
--- /dev/null
+++ b/changelog.d/release-cause-parser-coverage.md
@@ -0,0 +1,2 @@
+### Tests
+- Cover invariant economic cause arguments, political cause argument ordering and IDs, and map-editor digest validation boundaries.
diff --git a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
index a618ec47f..f1ab42439 100644
--- a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
@@ -330,4 +330,29 @@ public class MapOverridesTests
Assert.Contains(code, Assert.Throws<ContentException>(() => MapEditorOverlay.Serialize(value)).Message);
}
}
+
+ // R-MEDIT-002: base_digest is exactly 64 lowercase hex characters; parse and object serialization agree.
+ [Theory]
+ [InlineData('A', 64)] // uppercase hex: right length, wrong alphabet
+ [InlineData('g', 64)] // lowercase non-hex letter
+ [InlineData('٣', 64)] // non-ASCII digit
+ [InlineData('a', 63)] // one short
+ [InlineData('a', 65)] // one long
+ public void BaseDigestMustBeSixtyFourLowercaseHexOnParseAndSerialize(char c, int length)
+ {
+ var digest = new string(c, length);
+ var yaml = EditorFixture.Replace(new string('a', 64), digest);
+ var parsed = Assert.Throws<ContentException>(() => MapEditorOverlay.Parse(yaml, SaveGame.Gdd03Ruleset));
+ Assert.Contains("MAPEDIT_BASE", parsed.Message);
+ Assert.Equal("base", parsed.Field);
+ Assert.Equal(MapOverrides.FileName, parsed.File);
+
+ var value = MapEditorOverlay.Parse(EditorFixture, SaveGame.Gdd03Ruleset);
+ value.BaseDigest = digest;
+ var written = Assert.Throws<ContentException>(() => MapEditorOverlay.Serialize(value));
+ Assert.Contains("MAPEDIT_BASE", written.Message);
+ Assert.Equal("base", written.Field);
+ Assert.Equal(MapOverrides.FileName, written.File);
+ }
+
}
diff --git a/sim/Statecraft.Sim.Tests/PoliticsTests.cs b/sim/Statecraft.Sim.Tests/PoliticsTests.cs
index 8ce0884b4..3feb543da 100644
--- a/sim/Statecraft.Sim.Tests/PoliticsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoliticsTests.cs
@@ -75,4 +75,21 @@ public class PoliticsTests
PoliticsSystem.ReportChanges(C, new System.DateTime(1949, 3, 1), new System.DateTime(1949, 3, 15), why);
Assert.Contains(why, w => w.Message == "Government Two took office (Alpha, Beta)");
}
+
+ [Fact]
+ public void PoliticalProducerArgsKeepSeatOrderAndPartyIds()
+ {
+ var legislature = new List<Cause>();
+ PoliticsSystem.ReportChanges(C, new DateTime(1949, 2, 1), new DateTime(1949, 3, 1), legislature);
+ var convened = Assert.Single(legislature, w => w.Target == "house");
+ Assert.Equal(CauseKeys.LegislatureConvened, convened.Key);
+ Assert.Equal(new[] { "4", "10" }, convened.Args); // unequal fixture counts discriminate a swap
+ var government = new List<Cause>();
+ PoliticsSystem.ReportChanges(C, new DateTime(1949, 3, 1), new DateTime(1949, 3, 15), government);
+ var installed = Assert.Single(government, w => w.Target == "gov2");
+ Assert.Equal(CauseKeys.GovernmentTookOffice, installed.Key);
+ Assert.Equal(new[] { "alpha|beta" }, installed.Args);
+ Assert.Equal("Government Two took office (Alpha, Beta)", installed.Message);
+ }
+
}
diff --git a/sim/Statecraft.Sim.Tests/PoolsTests.cs b/sim/Statecraft.Sim.Tests/PoolsTests.cs
index 15eddda0f..d8130f884 100644
--- a/sim/Statecraft.Sim.Tests/PoolsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoolsTests.cs
@@ -1,4 +1,6 @@
using System;
+using System.Globalization;
+using System.Threading;
using System.Collections.Generic;
using System.Linq;
using Statecraft.Sim;
@@ -319,4 +321,48 @@ public class PoolsTests
Assert.Equal(g.State.Hash(), loaded.Hash());
Assert.Equal(Real.Rules.Mvp!.ArmsStart!.Value + 25, loaded.Arms);
}
+
+ // R-ARMS-002, R-FOOD-002: the keyed lines carry the values the UI words, as invariant text whatever the culture.
+ [Fact]
+ public void TheArmsAndFoodLinesCarryTheirKeyedValuesInvariantly()
+ {
+ var culture = Thread.CurrentThread.CurrentCulture;
+ try
+ {
+ Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");
+ var c = Gdd();
+
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ var why = new List<Cause>();
+ Assert.Null(Pools.BuyArms(c, s, 3, why)); // fixture arms_price 0.25: cost 0.75
+ var bought = Assert.Single(why, w => w.Key == CauseKeys.ArmsBought);
+ Assert.Equal(("economy", "arms", 3.0), (bought.System, bought.Target, bought.Delta));
+ Assert.Equal(new[] { "0.75" }, bought.Args); // the cost, not the count; never "0,75"
+
+ var f = Simulation.NewGame(c, 1, Mode.Historical);
+ f.ActiveSituations.Add(EconomySystem.FxCrisis);
+ f.Food = 40; // need is 100 (1000 people / 10)
+ why = new List<Cause>();
+ Pools.Consume(c, f, c.RulesAt(f.Date).Mvp!, why);
+ var keyed = why.Where(w => w.Key != "").ToList();
+ Assert.Equal(new[] { CauseKeys.FoodShortage, CauseKeys.FoodWithoutImports }, keyed.Select(w => w.Key));
+ Assert.Equal(-60.0, keyed[0].Delta);
+ Assert.Equal(new[] { "100" }, keyed[0].Args); // the need; unmet is -Delta
+ Assert.Equal("Food ran out: 60 of 100 units of the month's need went unmet", keyed[0].Message);
+ Assert.Equal(-40.0, keyed[1].Delta);
+ Assert.Equal(new[] { "0" }, keyed[1].Args); // the stock after eating
+ Assert.Equal("No Food imported (foreign currency crisis): the stock fell to 0 units", keyed[1].Message);
+ Assert.Equal(0, f.Food); // no import in the crisis
+
+ var stocked = Simulation.NewGame(c, 1, Mode.Historical);
+ stocked.ActiveSituations.Add(EconomySystem.FxCrisis);
+ stocked.Food = 150;
+ why = new List<Cause>();
+ Pools.Consume(c, stocked, c.RulesAt(stocked.Date).Mvp!, why);
+ var withoutImports = Assert.Single(why, w => w.Key == CauseKeys.FoodWithoutImports);
+ Assert.Equal(new[] { "50" }, withoutImports.Args); // the remaining stock, not the zero import quantity
+ }
+ finally { Thread.CurrentThread.CurrentCulture = culture; }
+ }
+
}