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.

Tests: pin R-SAVE-003 refused open orders, R-LOOP-005 named parts, R-FOOD under gdd-0.3 (Fixes #2653) (#2716)

Beri3b94fb62a3ac
diff --git a/sim/Statecraft.Sim.Tests/DesignValuesGdd03Tests.cs b/sim/Statecraft.Sim.Tests/DesignValuesGdd03Tests.cs
index ebbb3c66b..538daddf4 100644
--- a/sim/Statecraft.Sim.Tests/DesignValuesGdd03Tests.cs
+++ b/sim/Statecraft.Sim.Tests/DesignValuesGdd03Tests.cs
@@ -163,6 +163,40 @@ public partial class DesignValuesTests
var c=Catalogue(); Assert.Equal("gdd-0.3", c["ruleset"]);
Assert.Equal(Gdd03Keys.OrderBy(x=>x,StringComparer.Ordinal), Row(c,"values").Keys.Cast<string>().OrderBy(x=>x,StringComparer.Ordinal));
}
+ // R-LOOP-005 (#2653): the named parts are pinned too, so an invented or dropped part fails until this list changes.
+ static readonly Dictionary<string, string[]> Gdd03Parts = new Dictionary<string, string[]>
+ {
+ ["reception.queue_cohesion_loss"] = new[] { "cadence_turns" },
+ ["combat.draw_count"] = new[] { "at_least_2", "below_0_5", "draw_band", "from_0_5_below_1", "from_1_below_2", "ratio_thresholds" },
+ ["maabara"] = new[] { "condition_pp", "cost", "housing", "upkeep", "work" },
+ ["permanent_housing"] = new[] { "condition_pp", "cost", "housing", "upkeep", "work" },
+ ["industry"] = new[] { "cost", "job_slots", "upkeep", "work" },
+ ["reception_camp"] = new[] { "cost", "standalone_application", "upkeep", "work" },
+ ["training_centre"] = new[] { "cost", "standalone_application", "upkeep", "work" },
+ ["arms_workshop"] = new[] { "cost", "upkeep", "work", "worker_slots" },
+ ["military_camp"] = new[] { "cost", "upkeep", "work" },
+ ["housing_repair"] = new[] { "condition_pp", "cost", "upkeep", "work" },
+ ["designated_yishuv"] = new[] { "cost", "upkeep", "work" },
+ ["hula_drainage"] = new[] { "cost", "upkeep", "work" },
+ ["road_segment"] = new[] { "cost", "upkeep", "work" },
+ ["rail_segment"] = new[] { "cost", "upkeep", "work" },
+ ["coastal_plain"] = new[] { "defence_percent", "movement" },
+ ["lowland"] = new[] { "defence_percent", "movement" },
+ ["valley"] = new[] { "defence_percent", "movement" },
+ ["hills"] = new[] { "defence_percent", "movement" },
+ ["mountains"] = new[] { "defence_percent", "movement" },
+ ["desert"] = new[] { "defence_percent", "movement" },
+ };
+ [Fact] public void Gdd03CatalogueHasEveryPinnedNamedPartExactlyOnce()
+ {
+ var v=Row(Catalogue(),"values");
+ string Line(string key, IEnumerable<string> parts) => key+": "+string.Join(" ", parts.OrderBy(x=>x,StringComparer.Ordinal));
+ var actual=v.Where(kv=>((Dictionary<object,object>)kv.Value).ContainsKey("parts"))
+ .Select(kv=>Line((string)kv.Key, Row((Dictionary<object,object>)kv.Value,"parts").Keys.Cast<string>()));
+ Assert.Equal(Gdd03Parts.Select(kv=>Line(kv.Key,kv.Value)).OrderBy(x=>x,StringComparer.Ordinal), actual.OrderBy(x=>x,StringComparer.Ordinal));
+ // A part has no parts of its own today; one that gains them would need pinning here too.
+ Assert.All(Gdd03Parts, kv=>Assert.All(kv.Value, p=>Assert.False(Row(Row(Row(v,kv.Key),"parts"),p).ContainsKey("parts"), kv.Key+"."+p)));
+ }
[Fact] public void Gdd03DistinguishesAgreedDefaultsAndDeferredExpressions()
{
var v=Row(Catalogue(),"values");
diff --git a/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs b/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs
index 1386cc333..1e1d2c336 100644
--- a/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs
+++ b/sim/Statecraft.Sim.Tests/GameSessionTurnTests.cs
@@ -81,6 +81,33 @@ public class GameSessionTurnTests
Assert.Equal(new[] { "move" }, loaded.Committed.Select(x => x.Kind));
}
+ // R-SAVE-003 (#2653): with the same content, an open-turn order the sim refuses on load means the save was edited.
+ [Fact]
+ public void ARefusedOpenOrderWithTheSameContentIsAnError()
+ {
+ var session = Fresh();
+ var unit = session.State.Units[0];
+ session.Save.SetOpen(new Command[] { new Move(0, unit.Q, unit.R) }); // refused: the unit is already there
+ var e = Assert.Throws<SaveException>(() => GameSession.Load(C, session.Save.Write(), out _));
+ Assert.Contains("The open turn's order 'move' was refused", e.Message);
+ }
+
+ // R-SAVE-003 (#2653): with other content, the first refused open order ends the replay: it and every later order
+ // are dropped, and the load warns that the replay differs.
+ [Fact]
+ public void ARefusedOpenOrderWithOtherContentDropsItAndTheRest()
+ {
+ var session = Fresh();
+ var unit = session.State.Units[0];
+ var valid = GoldenRun.SmokeMove(C, session.State);
+ session.Save.SetOpen(new Command[] { new Move(0, unit.Q, unit.R), valid });
+ var text = session.Save.Write().Replace("content " + C.Hash, "content " + new string('0', 64)); // other content
+ var loaded = GameSession.Load(C, text, out var warnings);
+ Assert.Equal(new[] { GameSession.ContentChanged, GameSession.ReplayDiffers }, warnings);
+ Assert.Empty(loaded.Committed);
+ Assert.Null(Fresh().Commit(valid)); // the dropped order after it would have been taken on its own
+ }
+
[Fact]
public void StepRefusesWhileOrdersAreCommitted()
{
diff --git a/sim/Statecraft.Sim.Tests/PoolsTests.cs b/sim/Statecraft.Sim.Tests/PoolsTests.cs
index 6b517cef0..cd8be04f0 100644
--- a/sim/Statecraft.Sim.Tests/PoolsTests.cs
+++ b/sim/Statecraft.Sim.Tests/PoolsTests.cs
@@ -96,6 +96,38 @@ public class PoolsTests
Assert.Equal(again.FoodNeed, again.FoodUnmet);
}
+ // R-FOOD-001 to R-FOOD-003 under the gdd-0.3 ruleset (#2653): the Food code is shared by every GDD loop, so the same
+ // start stock, monthly eating and imports hold there. The fixture with the real balance catalogue, as DefeatTests does.
+ [Fact]
+ public void TheFoodCasesHoldUnderGdd03()
+ {
+ var files = Fixture.Gdd();
+ files["eras.yaml"] = files["eras.yaml"].Replace("loop: gdd", "loop: gdd, ruleset: " + SaveGame.Gdd03Ruleset);
+ files[Gdd03BalanceCatalogue.FileName] = System.IO.File.ReadAllText(System.IO.Path.Combine(RealContentTests.ContentRoot(), Gdd03BalanceCatalogue.FileName));
+ var c = ContentLoader.Load(Fixture.Write(files));
+ Assert.Equal(SaveGame.Gdd03Ruleset, c.Ruleset);
+ var s = Simulation.NewGame(c, 1, Mode.Historical);
+ Assert.Equal(100, s.FoodNeed); // R-FOOD-001: 1000 people / 10 per unit
+ Assert.Equal(3 * 100, s.Food); // cover_months of the start's need
+ Assert.Equal(0, s.FoodUnmet);
+ Assert.Equal(0.4, s.Indicators["food_supply"]); // R-FOOD-003: a full stock adds no term
+ Assert.Equal(0.0, Pools.FoodTerm(c, s));
+
+ var next = Step(c, s); // R-FOOD-002: imports bring it back to its cover
+ Assert.Equal(next.FoodNeed * 3, next.Food);
+ Assert.Equal(0, next.FoodUnmet);
+ Assert.Equal(0.4, next.Indicators["food_supply"]);
+
+ s.ActiveSituations.Add(EconomySystem.FxCrisis); // R-FOOD-002: no imports, the stock falls and stops at 0
+ s.FxReserves = -1000;
+ s.Food = 40;
+ var r = StepWithWhy(c, s);
+ Assert.Equal(0, r.State.Food);
+ Assert.Equal(100 - 40, r.State.FoodUnmet);
+ Assert.Contains(r.Why, w => w.System == "economy" && w.Message.Contains("60 of 100"));
+ Assert.Equal(-0.1 - 0.6, Pools.FoodTerm(c, r.State), 12); // R-FOOD-003: empty, -k_food, and 60% unmet
+ }
+
// R-FOOD-003
[Fact]
public void FoodSupplyFollowsTheStock()