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 the 7 MUST and 9 SHOULD test gaps from the 3 Nov sim audit (#2347)

Eyal Golanb32b73f6fc02
diff --git a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
index de6562fa6..5e14091e2 100644
--- a/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
+++ b/sim/Statecraft.Sim.Tests/ArmsWorkshopTests.cs
@@ -161,6 +161,19 @@ public class ArmsWorkshopTests
Assert.Equal("Town A has 9 civilians and craftsmen", Assert.Single(refused.Rejected).Reason);
}
+ // R-ARMS-005 with R-CITY-001 (#2270): Cities.MaxWorkers(GameState, City) stops at 0 when staffed workshops outnumber the
+ // city's people, so the job default never sets a negative Employed.
+ [Fact]
+ public void AStaffedWorkshopCannotMakeTheMaximumOrDefaultJobsNegative()
+ {
+ var (c, s, id) = Built(civilians: 0, employed: 0, jobs: 10);
+ s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary));
+ Assert.Equal(0, Cities.MaxWorkers(s, s.Cities["town_a"]));
+ var r = Step(c, s);
+ Assert.Equal(0, r.State.Cities["town_a"].Employed);
+ Assert.DoesNotContain(r.Why, w => w.Key == CauseKeys.WorkersAssigned && w.Target == "town_a");
+ }
+
public static IEnumerable<object[]> StaffRefusals() => new List<object[]>
{
new object[] { "gdd-0.1", "There is no such role" },
@@ -205,6 +218,41 @@ public class ArmsWorkshopTests
Assert.Equal(new[] { "0" }, off.Why.Single(x => x.Key == CauseKeys.WorkshopWorkers).Args);
}
+ // R-ARMS-005 (#2270): Workshops.Staff applies the count to built workshops in ascending project-id order.
+ [Fact]
+ public void StaffingCountSelectsTheLowestProjectIdsAndKeepsLaterRecords()
+ {
+ var (c, s, first) = Built(civilians: 10, employed: 0, jobs: 0, jobsDefault: false);
+ var firstProject = s.CityProjects[first];
+ s.CityProjects.Remove(first);
+ var second = s.NextId++;
+ s.CityProjects.Add(second, new CityProject(second, Workshops.ArmsWorkshop, "town_a", 2, 0, 0, s.Date));
+ s.CityProjects.Add(first, firstProject); // inserted after the higher id; SortedList still orders it first
+
+ var one = Step(c, s, Staff(1));
+ Assert.True(one.State.Workshops[first].Staffed);
+ Assert.False(one.State.Workshops.ContainsKey(second));
+
+ var two = Step(c, one.State, Staff(2));
+ Assert.True(two.State.Workshops[first].Staffed);
+ Assert.True(two.State.Workshops[second].Staffed);
+
+ var oneAgain = Step(c, two.State, Staff(1));
+ Assert.True(oneAgain.State.Workshops[first].Staffed);
+ Assert.False(oneAgain.State.Workshops[second].Staffed);
+ }
+
+ // R-ARMS-005 (#2270): Workshops.Staff adds no record for a never-staffed workshop that the order leaves off.
+ [Fact]
+ public void LeavingANeverStaffedWorkshopOffCreatesNoRecord()
+ {
+ var (c, s, id) = Built(jobsDefault: false);
+ var r = Step(c, s, Staff(0));
+ Assert.Empty(r.Rejected);
+ Assert.False(r.State.Workshops.ContainsKey(id));
+ Assert.DoesNotContain("wshop", r.State.Describe());
+ }
+
// R-ARMS-005 (#1722 slice E): Workshops.Check, which the hex panel asks before it offers a staffing order, gives exactly
// the refusal the order gets at End turn, and changes nothing.
[Theory]
@@ -265,6 +313,20 @@ public class ArmsWorkshopTests
Assert.True(r.State.Workshops[first].Staffed && r.State.Workshops[second].Staffed);
}
+ // R-ARMS-005 (#2270): Workshops.BuiltIn counts only this city's built projects whose kind has a worker slot.
+ [Fact]
+ public void BuiltCountsOnlyThisCitysProjectsWithWorkerSlots()
+ {
+ var (c, s, _) = Built(jobsDefault: false);
+ var industry = s.NextId++;
+ s.CityProjects.Add(industry, new CityProject(industry, "industry", "town_a", 2, 0, 0, s.Date));
+ var elsewhere = s.NextId++;
+ s.CityProjects.Add(elsewhere, new CityProject(elsewhere, Workshops.ArmsWorkshop, "town_b", 3, 0, 0, s.Date));
+
+ Assert.Equal(1, Workshops.Built(c, s, "town_a"));
+ Assert.Equal("Town A has 1 arms workshop", Assert.Single(Step(c, s, Staff(2)).Rejected).Reason);
+ }
+
// R-ARMS-005 with R-CITY-001 (#1722 slice E): with this turn's queue, Check counts a pending "job" order's jobs (which turn
// the job default off) and every Train or reassignment there, so an order it accepts is still accepted if the job order
// runs first. Here the job order takes the last free person, and the turn refuses the staffing with Check's words.
@@ -281,6 +343,24 @@ public class ArmsWorkshopTests
Assert.Equal(reason, Assert.Single(Step(c, s, job, Staff(1)).Rejected).Reason);
}
+ // R-ARMS-005 with R-CITY-001 (#2289): Workshops.Check subtracts this turn's queued Train and pioneer-reassignment orders.
+ [Theory]
+ [InlineData(false)]
+ [InlineData(true)]
+ public void CheckCountsThisTurnsTrainingOrders(bool reassign)
+ {
+ var (c, s, _) = Built(civilians: 10, employed: 9, jobs: 10, jobsDefault: false);
+ var x = s.Cities["town_a"];
+ s.Cities["town_a"] = x.WithQualified(new Qualified(0, 0, new[] { 1 }));
+ Command order = reassign
+ ? new ReassignPioneers("town_a", "halutz", 1)
+ : new Train("town_a", "halutz", 1);
+ const string reason = "Town A has 0 civilians and craftsmen without a job";
+
+ Assert.Equal(reason, Workshops.Check(c, s, "town_a", 1, new[] { order, Staff(1) }));
+ Assert.Equal(reason, Assert.Single(Step(c, s, order, Staff(1)).Rejected).Reason);
+ }
+
// R-ARMS-005 with R-CITY-001 (#1722 slice E): the jobs stepper's limit counts a pending staffing order's newly staffed
// workers, as Training.Available does, so a jobs count it allows is still accepted if the staffing runs first.
[Fact]
@@ -394,6 +474,13 @@ public class ArmsWorkshopTests
Assert.NotEqual(staffed.Hash(), other.Hash());
}
+ // R-ARMS-006 (#2270): Workshop.Canonical writes no "/COST,PROGRESS" suffix while no cycle is paid.
+ [Fact]
+ public void AnUnpaidWorkshopCanonicalHasNoCycleSuffix()
+ {
+ Assert.Equal("7:off,Ordinary", new Workshop(7, false, SyntheticWorkshopTier.Ordinary).Canonical());
+ }
+
// ---- R-ARMS-006: the monthly cycle at the production step (slice C) ----
static readonly SyntheticWorkshopRules Rules = SyntheticWorkshopRules.FromCatalogue(Load(true).Gdd03Balance!);
@@ -457,6 +544,26 @@ public class ArmsWorkshopTests
Assert.Equal((null, 0), (after.Workshops[id].PaidCost, after.Workshops[id].Progress));
}
+ // R-ARMS-006 (#2270): in Workshops.Produce, a complete paid cycle waits at a full Arms stock, never overflowing or charging again.
+ [Fact]
+ public void AFullArmsStockKeepsACompletedPaidCycleWaiting()
+ {
+ var (c, s, id) = Staffed(paid: 5m, progress: 2);
+ s.Arms = int.MaxValue;
+
+ var first = Step(c, s);
+ Assert.Equal(int.MaxValue, first.State.Arms);
+ Assert.Equal((5m, 3), (first.State.Workshops[id].PaidCost, first.State.Workshops[id].Progress));
+ Assert.Empty(Charges(first));
+ Assert.DoesNotContain(first.Why, w => w.Key == CauseKeys.WorkshopArms);
+
+ var second = Step(c, first.State);
+ Assert.Equal(int.MaxValue, second.State.Arms);
+ Assert.Equal((5m, 3), (second.State.Workshops[id].PaidCost, second.State.Workshops[id].Progress));
+ Assert.Empty(Charges(second));
+ Assert.DoesNotContain(second.Why, w => w.Key == CauseKeys.WorkshopArms);
+ }
+
static GameState Clear(GameState s) { var x = s.Clone(); x.Workshops.Clear(); return x; }
// R-ARMS-006 (27M-13: "The cost tier follows the worker (novice or ordinary / apprentice / expert)."; gdd03-balance
@@ -682,6 +789,40 @@ public class ArmsWorkshopTests
}
}
+ // R-TRAIN-001 with R-ARMS-005 (#2270): Training.Idle stops at 0 when a staffed workshop's worker leaves no free civilian,
+ // so a Train refusal never names a negative count.
+ [Fact]
+ public void TrainReportsZeroIdleWhenAStaffedWorkshopExceedsTheFreePopulation()
+ {
+ var (c, s, id) = Built(civilians: 3, employed: 3, jobs: 3, jobsDefault: false);
+ s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary));
+ var r = Step(c, s, new Train("town_a", "halutz", 1));
+ Assert.Equal("Town A has 0 civilians without work", Assert.Single(r.Rejected).Reason);
+ }
+
+ // R-QUAL-005 with R-ARMS-005 (#2270): the same Training.Idle floor keeps a pioneer-reassignment refusal from naming a
+ // negative count.
+ [Fact]
+ public void ReassignPioneersReportsZeroIdleWhenAStaffedWorkshopExceedsTheFreePopulation()
+ {
+ var (c, s, id) = Built(civilians: 3, employed: 3, jobs: 3, jobsDefault: false);
+ var x = s.Cities["town_a"];
+ s.Cities["town_a"] = x.WithQualified(new Qualified(0, 0, new[] { 0 }));
+ s.Workshops.Add(id, new Workshop(id, true, SyntheticWorkshopTier.Ordinary));
+ var r = Step(c, s, new ReassignPioneers("town_a", "halutz", 1));
+ Assert.Equal("Town A has 0 civilians without work", Assert.Single(r.Rejected).Reason);
+ }
+
+ // R-ARMS-005 with R-CITY-001 (#2289): Workshops.Check names 0, never a negative number, when this turn's Train orders
+ // take more people than are free.
+ [Fact]
+ public void CheckReportsZeroFreePeopleWhenPendingTrainingExceedsThem()
+ {
+ var (c, s, _) = Built(civilians: 10, employed: 9, jobs: 10, jobsDefault: false);
+ var pending = new Command[] { new Train("town_a", "halutz", 3) };
+ Assert.Equal("Town A has 0 civilians and craftsmen without a job", Workshops.Check(c, s, "town_a", 1, pending));
+ }
+
// R-TRAIN-001: Training.Available reads only a "job" AssignWorkers as a jobs order; a pending "workshop" order takes
// its newly staffed workers off the idle civilians instead, so a Train up to the limit stays accepted in either order.
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
index 52942758b..846914ccb 100644
--- a/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapOverridesTests.cs
@@ -442,6 +442,17 @@ public class MapOverridesTests
Assert.Equal(9, c.StartingForces[0].Q);
}
+ // R-MEDIT-003 (#2309): the force-anchor adapter blocks a scripted anchor hex that is not land, naming its row and hex.
+ [Fact]
+ public void ASeaScriptedAnchorBlocksWithItsIdAndExactHex()
+ {
+ var c = DependencyFixture();
+ c.StartingForces[0].Script = (3, 0);
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("anchors[unit_a]", row.Field);
+ Assert.Equal("scripted anchor hex q=3 r=0 is not a land hex of the map", row.Message);
+ }
+
[Fact]
public void ABrokenTargetBindingBlocksWithItsId()
{
@@ -455,6 +466,29 @@ public class MapOverridesTests
Assert.Equal((0, 0), (c.SettlementTargets[0].Q, c.SettlementTargets[0].R));
}
+ // R-MEDIT-003 (#2309): the target adapter blocks a target hex that is not land, even while it still matches its settlement.
+ [Fact]
+ public void ASeaTargetBlocksWithItsIdAndExactHex()
+ {
+ var c = DependencyFixture();
+ c.SettlementHexes.Add(new SettlementHex { Id = "town_b", Q = 3, R = 0 });
+ c.SettlementTargets.Add(new SettlementTarget { Id = "town_b", Q = 3, R = 0 });
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("targets[town_b]", row.Field);
+ Assert.Equal("target hex q=3 r=0 is not a land hex of the map", row.Message);
+ }
+
+ // R-MEDIT-003 (#2309): a target with no settlement hex gets that one row, and no "no longer matches" row after it.
+ [Fact]
+ public void ATargetWithoutASettlementHexProducesOnlyItsExactDiagnostic()
+ {
+ var c = DependencyFixture();
+ c.SettlementTargets.Add(new SettlementTarget { Id = "ghost", Q = 1, R = 0 });
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("targets[ghost]", row.Field);
+ Assert.Equal("settlement 'ghost' has no hex", row.Message);
+ }
+
[Fact]
public void RamlasTargetIsBoundToANeighbourOfItsSettlement()
{
@@ -482,4 +516,48 @@ public class MapOverridesTests
var moved = Broken(DependencyDiagnostics(DependencyFixture(), "[{ id: town_a, hex: { q: 2, r: 0 } }]"));
Assert.Contains(moved, x => x.Field == "objectives[objective_b]" && x.Message.Contains("site_a"));
}
+
+ // #2309: MapOverrides' objective dependency diagnostics inspect every SitesBuilt entry, not only SiteBuilt.
+ [Fact]
+ public void APluralSiteObjectiveBindingBlocksWithItsId()
+ {
+ var c = DependencyFixture();
+ c.Objectives[1].CompletesWhen = new ObjectiveCondition { SitesBuilt = new List<string> { "site_a" } };
+ c.SettlementTargets.Clear(); // isolate the objective adapter from the target moved by this overlay
+ var row = Assert.Single(Broken(DependencyDiagnostics(c, "[{ id: town_a, hex: { q: 2, r: 0 } }]")));
+ Assert.Equal("objectives[objective_b]", row.Field);
+ Assert.Equal("site 'site_a' hex q=2 r=0 now holds the settlement town_a", row.Message);
+ }
+
+ // #2309: in the objective dependency diagnostics, an unknown objective site produces one diagnostic and is not dereferenced.
+ [Fact]
+ public void AnUnknownObjectiveSiteBlocksOnceWithItsId()
+ {
+ var c = DependencyFixture();
+ c.Objectives[1].CompletesWhen = new ObjectiveCondition { SiteBuilt = "no_site" };
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("objectives[objective_b]", row.Field);
+ Assert.Equal("unknown site 'no_site'", row.Message);
+ }
+
+ // #2309: in the objective dependency diagnostics, an objective site without the yishuv kind is diagnosed.
+ [Fact]
+ public void ANonYishuvObjectiveSiteBlocksWithItsId()
+ {
+ var c = DependencyFixture();
+ c.Sites.Add(new Site { Id = "site_b", Q = 1, R = 0, Kinds = new List<string> { "industry" } });
+ c.Objectives[1].CompletesWhen = new ObjectiveCondition { SiteBuilt = "site_b" };
+ var row = Assert.Single(Broken(DependencyDiagnostics(c)));
+ Assert.Equal("objectives[objective_b]", row.Field);
+ Assert.Equal("site 'site_b' cannot be built as a yishuv", row.Message);
+ }
+
+ // R-MEDIT-003 (#2309): the objective adapter skips an objective with no completion condition (no row, no exception).
+ [Fact]
+ public void AnObjectiveWithoutACompletionConditionNeedsNoDependencyDiagnostic()
+ {
+ var c = DependencyFixture();
+ c.Objectives.Add(new Objective { Id = "objective_c" });
+ Assert.Empty(Broken(DependencyDiagnostics(c)));
+ }
}