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: city builders and project build fixture coverage from the slice A and B reviews (Refs #1700) (#2440)

Eyal Golanca7c333a4c2e
diff --git a/sim/Statecraft.Sim.Tests/CityBuildersTests.cs b/sim/Statecraft.Sim.Tests/CityBuildersTests.cs
index a101fcb2c..3a7a24910 100644
--- a/sim/Statecraft.Sim.Tests/CityBuildersTests.cs
+++ b/sim/Statecraft.Sim.Tests/CityBuildersTests.cs
@@ -114,23 +114,34 @@ public class CityBuildersTests
[InlineData("industry", 2)]
public void Gdd03BuiltInTodaysTurns(string kind, int turns)
{
- var (c, s) = Game();
- s.Policies[MapActions.MaabarotPolicy] = 1;
- var k = c.ProjectKinds.Single(x => x.Id == kind);
- var state = Step(c, s, new StartProject(kind, "town_a", 1, 1)).State;
- var id = state.CityProjects.Keys.Single();
- Assert.True(state.CityProjects[id].Builder || state.CityProjects[id].BuiltOn != null);
- for (int i = 1; i < turns; i++)
+ // town_a's condition at 0.8: the kind's change (the transit camp's -0.1) is never cut at 0 or 1 (R-HOUSE-001), and
+ // it stays above the gdd-0.3 surcharge and cohesion thresholds (R-HOUSE-005), so only the condition differs below.
+ (City Was, City Built, City Later, ProjectKind K) Run(string projects)
{
- Assert.Null(state.CityProjects[id].BuiltOn);
- state = Step(c, state).State;
+ var (c, s) = Game(projects: projects);
+ s.Policies[MapActions.MaabarotPolicy] = 1;
+ s.Cities["town_a"] = s.Cities["town_a"].WithCondition(0.8);
+ var row = c.ProjectKinds.Single(x => x.Id == kind);
+ var state = Step(c, s, new StartProject(kind, "town_a", 1, 1)).State;
+ var id = state.CityProjects.Keys.Single();
+ Assert.True(state.CityProjects[id].Builder || state.CityProjects[id].BuiltOn != null);
+ for (int i = 1; i < turns; i++)
+ {
+ Assert.Null(state.CityProjects[id].BuiltOn);
+ state = Step(c, state).State;
+ }
+ Assert.NotNull(state.CityProjects[id].BuiltOn);
+ return (s.Cities["town_a"], state.Cities["town_a"], Step(c, state).State.Cities["town_a"], row);
}
- Assert.NotNull(state.CityProjects[id].BuiltOn);
- var was = s.Cities["town_a"];
- var built = state.Cities["town_a"];
+ var (was, built, later, k) = Run(Fixture.GddProjects + ArmsWorkshopTests.Row);
Assert.Equal((was.HousingCapacity + k.Capacity, was.JobSlots + k.JobSlots), (built.HousingCapacity, built.JobSlots));
- var later = Step(c, state).State.Cities["town_a"];
Assert.Equal((built.HousingCapacity, built.JobSlots), (later.HousingCapacity, later.JobSlots));
+ // The condition, against the same run with the kinds' condition at 0: the gdd-0.3 housing step (R-HOUSE-002) moves
+ // both runs alike, so the difference is the kind's condition, on the turn it is built and, added once, after it.
+ var (_, plain, plainLater, zeroed) = Run(Fixture.GddProjects.Replace("condition: -0.1", "condition: 0") + ArmsWorkshopTests.Row);
+ Assert.Equal(0.0, zeroed.Condition); // the comparison run's kind has no condition change, so the difference is k's
+ Assert.Equal(plain.Condition!.Value + k.Condition, built.Condition!.Value, 9);
+ Assert.Equal(plainLater.Condition!.Value + k.Condition, later.Condition!.Value, 9);
}
// R-PROJ-003: Money is never an input to progress.
@@ -318,6 +329,9 @@ public class CityBuildersTests
Assert.Equal("5:housing@town_a,1,1/2", p.Canonical());
Assert.Equal("5:housing@town_a,1,1/2;builder", p.WithBuilder(true).Canonical());
Assert.Equal("5:housing@town_a,1,1/done,1948-05-15", p.WithBuilder(true).Built(new DateTime(1948, 5, 15)).Canonical());
+ // The hash leaves the flag out once built, so check the record itself: Built frees the builder, and Builders,
+ // which counts the flag, never counts a built project (#1700 slice A review NIT).
+ Assert.False(p.WithBuilder(true).Built(new DateTime(1948, 5, 15)).Builder);
}
// R-SAVE with R-CITY-011 (review MUST-1): a save is the command log, so a game with builders, saved and loaded, replays to
// the same state, the builders included, and goes on identically.
@@ -486,4 +500,21 @@ public class CityBuildersTests
var id = one.State.CityProjects.Keys.Single();
Assert.NotNull(Step(c, one.State).State.CityProjects[id].BuiltOn);
}
+
+ // R-PROJ-001, R-PROJ-003 with R-CITY-011 (#1700 slice A review: a gdd-0.1 hash check, plan test 14): under gdd-0.1 a
+ // start takes no builder, so a job order up to all the city's people is accepted before or after it and the whole state
+ // hash is the same either way, on the start's turn and the turn it is built. Under gdd-0.3 the same two orders differ
+ // (Gdd03AutoBuilderFollowsQueueOrderWithAJobOrder). Compared in the same run: no literal hash outside the golden manifest.
+ [Fact]
+ public void Gdd01StartOrderLeavesTheHashUnchanged()
+ {
+ var (c, s) = Game(civilians: 10, employed: 9, jobs: 10, gdd03: false); // one person without a job
+ s.Attention = 10; // gdd-0.1 charges Attention for both orders: enough for the two in one turn
+ var jobFirst = Step(c, s, new AssignWorkers("town_a", "job", 10), Housing());
+ var startFirst = Step(c, s, Housing(), new AssignWorkers("town_a", "job", 10));
+ Assert.Empty(jobFirst.Rejected);
+ Assert.Empty(startFirst.Rejected);
+ Assert.Equal(jobFirst.State.Hash(), startFirst.State.Hash());
+ Assert.Equal(Step(c, jobFirst.State).State.Hash(), Step(c, startFirst.State).State.Hash());
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs b/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs
index 35b89c53b..e8a202676 100644
--- a/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs
+++ b/sim/Statecraft.Sim.Tests/Gdd03ProjectBuildFixtureTests.cs
@@ -150,6 +150,21 @@ public class Gdd03ProjectBuildFixtureTests
Assert.Equal(4, f.Projects.Count);
}
+ // A start the city's limit refuses uses neither the city's slot nor a national one (#1700 slice B review): after A,
+ // a refused second A, a start in a second city B is still accepted, and only then is the national 2 used up.
+ [Fact]
+ public void ARefusedSecondStartInOneCityLeavesTheNationalSlot()
+ {
+ var f = New(100m);
+ f.Start("industry", "town_a");
+ var e = Assert.Throws<System.InvalidOperationException>(() => f.Start("industry", "town_a"));
+ Assert.Equal("town_a has started a city project this turn", e.Message);
+ f.Start("industry", "town_b");
+ Assert.Equal((80m, 0m, 2), (f.Money, f.Debt, f.Projects.Count));
+ var national = Assert.Throws<System.InvalidOperationException>(() => f.Start("industry", "town_c"));
+ Assert.Equal("No more than 2 city starts are allowed a turn", national.Message);
+ }
+
// The fixture's national 2 is the live game's map_actions_per_turn (content/rules.yaml), which the ruling keeps.
[Fact]
public void TheNationalTwoIsTheGamesMapActionsPerTurn()