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: refused Raid and EndOccupation refund a nonzero cost; EndPending's ordinal order pinned (Refs #2733 items 1 and 3) (#2741)

Beri10bcf809a3d7
diff --git a/sim/Statecraft.Sim.Tests/EndOccupationTests.cs b/sim/Statecraft.Sim.Tests/EndOccupationTests.cs
index 791265bd3..20e45a474 100644
--- a/sim/Statecraft.Sim.Tests/EndOccupationTests.cs
+++ b/sim/Statecraft.Sim.Tests/EndOccupationTests.cs
@@ -47,6 +47,13 @@ public class EndOccupationTests
var s = CombatTests.With(c, Soldier(1, 1, 0));
var result = Simulation.Step(c, s, new Command[] { new EndOccupation("town_a", SettlementControl.Annex) });
Assert.Contains("not awaiting the end of its occupation", Assert.Single(result.Rejected).Reason);
+ // #2733 item 1: with a cost the Attention could pay, the refused order's Attention comes back.
+ var costly = CaptureTests.Load(f => f["rules.yaml"] = f["rules.yaml"].Replace("end_occupation: 0", "end_occupation: 2"), CaptureTests.AllTargets);
+ s.Attention = 5;
+ Assert.InRange(AttentionSystem.Cost(costly, s, SettlementControl.EndKind), 0.1, s.Attention);
+ var refused = Simulation.Preview(costly, s, new Command[] { new EndOccupation("town_a", SettlementControl.Annex) });
+ Assert.Contains("not awaiting the end of its occupation", Assert.Single(refused.Rejected).Reason);
+ Assert.Equal(s.Attention, refused.State.Attention);
}
// R-CTRL-015: Annex then Withdraw, nothing else, no puppet.
diff --git a/sim/Statecraft.Sim.Tests/RaidTests.cs b/sim/Statecraft.Sim.Tests/RaidTests.cs
index adcfe6696..68730cb30 100644
--- a/sim/Statecraft.Sim.Tests/RaidTests.cs
+++ b/sim/Statecraft.Sim.Tests/RaidTests.cs
@@ -86,6 +86,13 @@ public class RaidTests
Assert.Equal(before.Describe(), s.Describe());
Assert.Equal(before.Hash(), s.Hash());
Assert.Single(Step(c, before, Raid()).Rejected);
+ // #2733 item 1: with a cost the Attention could pay, the refused order's Attention comes back.
+ var costly = CaptureTests.Load(f => f["rules.yaml"] = f["rules.yaml"].Replace("resolve_capture: 0,", "resolve_capture: 2,"), CaptureTests.AllTargets);
+ before.Attention = 5;
+ Assert.InRange(AttentionSystem.Cost(costly, before, SettlementControl.ResolveKind), 0.1, before.Attention);
+ var refused = Simulation.Preview(costly, before, new Command[] { Raid() });
+ Assert.Contains("A unit has no free hex", Assert.Single(refused.Rejected).Reason);
+ Assert.Equal(before.Attention, refused.State.Attention);
}
[Fact]
@@ -175,6 +182,20 @@ public class RaidTests
Assert.Equal((1, 0), (next.Units[6].Q, next.Units[6].R));
}
+ // R-CTRL-008 (#2733 item 3): the captures still waiting at the end resolve in ordinal id order, whatever order they were
+ // captured in: town_c (taken first) resolves after town_a.
+ [Fact]
+ public void PendingCapturesResolveAtTheEndInOrdinalOrder()
+ {
+ var c = Load();
+ var s = CombatTests.With(c, Soldier(1, 1, 0), Soldier(2, 4, 0));
+ s.Settlements["town_c"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);
+ s.Settlements["town_a"] = new SettlementControl(Movement.PlayerSide, SettlementControl.AwaitingChoice, s.Date);
+ s.Date = c.End.AddDays(-10); // the next turn ends on the game's end
+ var why = Step(c, s).Why;
+ Assert.Equal(new[] { "town_a", "town_c" }, why.Where(x => x.Key == CauseKeys.PendingBecameRaid).Select(x => x.Target));
+ }
+
// R-CTRL-010: a unit keeps its orders when it withdraws, as after a Move; a fortify names the place's hex, so the
// turn's order step drops it (R-ORDER-002), and hold goes with the unit.
[Fact]