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: sim tests stop pinning routine real-content values (#2363)

Eyal Golan880312953deb
diff --git a/sim/Statecraft.Sim.Tests/DollarsTests.cs b/sim/Statecraft.Sim.Tests/DollarsTests.cs
index 8b188b7d3..f72c55dd0 100644
--- a/sim/Statecraft.Sim.Tests/DollarsTests.cs
+++ b/sim/Statecraft.Sim.Tests/DollarsTests.cs
@@ -276,77 +276,98 @@ options:
static (string, string, double, string)[] Lines(StepResult r) => r.Why.Select(w => (w.System, w.Target, w.Delta, w.Message)).ToArray();
+ static int FirstArmsPastDebtCeiling(Content c, GameState s, double moneyBeforePurchase = 0)
+ {
+ var m = c.RulesAt(s.Date).Mvp!;
+ var capacity = s.Treasury + moneyBeforePurchase + m.DebtCeiling!.Value - s.Debt;
+ // The smallest n with n * price > capacity (exactly at the ceiling is not past it, Pools.BorrowsPastDebtCeiling).
+ // Near an exact multiple, float rounding here and in Pools could disagree by one Arms, so fail loudly there.
+ var arms = capacity / m.ArmsPrice!.Value;
+ Assert.True(Math.Abs(arms - Math.Round(arms)) > 1e-6,
+ FormattableString.Invariant($"capacity {capacity} is an exact multiple of the Arms price {m.ArmsPrice.Value}; the boundary is ambiguous"));
+ return checked((int)Math.Floor(arms) + 1);
+ }
+
// R-MONEY-004, R-ARMS-002 (#2206; owner, 2 November 2026: "Conversion counts first (Recommended)"): a turn's dollar
// conversions run before its Arms purchases, so the purchase borrows only what the conversion leaves it short, whatever
- // the queue order. The real content's first turn: rung 5, Treasury IL 20m, no debt, IL 1m an Arms, IL 0.333 per $.
- // Queued before or after $4m (IL 1.332m), 271 Arms give the same turn: the same state, causes and rejections. With the
- // IL 250m debt ceiling (#2203), 271 Arms alone borrow IL 251m and are refused; after the conversion they borrow IL 249.668m,
- // so a purchase queued BEFORE the conversion is accepted too.
+ // the queue order. The accepted and refused boundary is derived from the real content's Treasury, debt ceiling, Arms price,
+ // monthly conversion allowance and dated exchange rate.
[Fact]
public void AConversionCountsForAnArmsPurchaseWhateverTheQueueOrder()
{
var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
var m = Real.RulesAt(s.Date).Mvp!;
- Assert.Equal((5, 20.0, 0.0, 250.0, 1.0, 0.333), (s.Rung, s.Treasury, s.Debt, m.DebtCeiling!.Value, m.ArmsPrice!.Value, m.IlPerDollarOn(s.Date)));
- Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(Simulation.Step(Real, s, new Command[] { new BuyArms(271) }).Rejected).Reason);
- var first = Simulation.Step(Real, s, new Command[] { new ConvertDollars(4), new BuyArms(271) });
- var last = Simulation.Step(Real, s, new Command[] { new BuyArms(271), new ConvertDollars(4) });
+ Assert.True(s.Rung >= EconomySystem.WarRung); // the first turn may convert (R-MONEY-004)
+ var converted = m.DollarsPerTurn!.Value;
+ var firstRefusedAfterConversion = FirstArmsPastDebtCeiling(Real, s, converted * m.IlPerDollarOn(s.Date));
+ var accepted = firstRefusedAfterConversion - 1;
+ // The amount the conversion makes affordable is refused without it, so the queue order matters.
+ Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(Simulation.Step(Real, s,
+ new Command[] { new BuyArms(accepted) }).Rejected).Reason);
+ var first = Simulation.Step(Real, s, new Command[] { new ConvertDollars(converted), new BuyArms(accepted) });
+ var last = Simulation.Step(Real, s, new Command[] { new BuyArms(accepted), new ConvertDollars(converted) });
Assert.Empty(first.Rejected);
Assert.Empty(last.Rejected);
Assert.Equal(first.State.Hash(), last.State.Hash());
Assert.Equal(Lines(first), Lines(last));
- Assert.Equal(s.Arms + 271, last.State.Arms);
- // The money adds up: the orders leave the Treasury at 0 and the debt at 271 - 20 - 4 * 0.333, and the turn ends the
+ Assert.Equal(s.Arms + accepted, last.State.Arms);
+ // The money adds up: the orders leave the Treasury at 0 and the debt at purchase cost minus starting cash and conversion, and the turn ends the
// purchase less and the conversion more than the turn with no order.
- var orders = Simulation.Preview(Real, s, new Command[] { new BuyArms(271), new ConvertDollars(4) }).State;
+ var orders = Simulation.Preview(Real, s, new Command[] { new BuyArms(accepted), new ConvertDollars(converted) }).State;
Assert.Equal(0.0, orders.Treasury, 9);
- Assert.Equal(271 - 20 - 4 * 0.333, orders.Debt, 9);
+ Assert.Equal(s.Debt + accepted * m.ArmsPrice!.Value - s.Treasury - converted * m.IlPerDollarOn(s.Date), orders.Debt, 9);
var none = Simulation.Step(Real, s, Array.Empty<Command>()).State;
- Assert.Equal(none.Treasury - none.Debt - 271 + 4 * 0.333, last.State.Treasury - last.State.Debt, 9);
+ Assert.Equal(none.Treasury - none.Debt - accepted * m.ArmsPrice.Value + converted * m.IlPerDollarOn(s.Date), last.State.Treasury - last.State.Debt, 9);
// One Arms more passes the ceiling in either order, refused with the same reason, and the conversion stands.
- var over = Simulation.Step(Real, s, new Command[] { new BuyArms(272), new ConvertDollars(4) });
- var overFirst = Simulation.Step(Real, s, new Command[] { new ConvertDollars(4), new BuyArms(272) });
+ var over = Simulation.Step(Real, s, new Command[] { new BuyArms(firstRefusedAfterConversion), new ConvertDollars(converted) });
+ var overFirst = Simulation.Step(Real, s, new Command[] { new ConvertDollars(converted), new BuyArms(firstRefusedAfterConversion) });
Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(over.Rejected).Reason);
Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(overFirst.Rejected).Reason);
Assert.Equal(overFirst.State.Hash(), over.State.Hash());
- Assert.Equal(4, over.State.DollarsConverted);
+ Assert.Equal(converted, over.State.DollarsConverted);
}
// R-ARMS-002, R-MONEY-004 (#2206): the Defence screen's ceiling warning counts the conversions queued this turn, as End
- // turn does (Pools.BorrowsPastDebtCeiling with the queue): after $4m, 271 Arms are allowed and 272 refused. A conversion
- // End turn refuses (past the month's $4m) counts for nothing.
+ // turn does (Pools.BorrowsPastDebtCeiling with the queue). A conversion End turn refuses for passing the monthly allowance
+ // counts for nothing.
[Fact]
public void TheCeilingCheckCountsTheQueuedConversionsAsEndTurnDoes()
{
var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
+ var hash = s.Hash();
+ var m = Real.RulesAt(s.Date).Mvp!;
+ var converted = m.DollarsPerTurn!.Value;
+ var afterConversion = FirstArmsPastDebtCeiling(Real, s, converted * m.IlPerDollarOn(s.Date));
// BuyArms(1) is the purchase already queued; the amount checked replaces it in its slot, as Buy does (SimBridge.Queue).
- var four = new Command[] { new BuyArms(1), new ConvertDollars(4) };
- Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, Array.Empty<Command>(), 271));
- Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, four, 271));
- Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, four, 272));
- Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, new Command[] { new ConvertDollars(5) }, 271));
- foreach (var count in new[] { 271, 272 })
- Assert.Equal(Pools.BorrowsPastDebtCeiling(Real, s, four, count),
- Simulation.Step(Real, s, new Command[] { new BuyArms(count), new ConvertDollars(4) }).Rejected.Any(x => x.Reason == Pools.RefusedDebtCeiling));
- Assert.Equal((20.0, 0), (s.Treasury, s.DollarsConverted)); // the queue is judged on a copy
+ var queued = new Command[] { new BuyArms(1), new ConvertDollars(converted) };
+ Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, Array.Empty<Command>(), afterConversion - 1));
+ Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, queued, afterConversion - 1));
+ Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, queued, afterConversion));
+ Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, new Command[] { new ConvertDollars(converted + 1) }, afterConversion - 1));
+ foreach (var count in new[] { afterConversion - 1, afterConversion })
+ Assert.Equal(Pools.BorrowsPastDebtCeiling(Real, s, queued, count),
+ Simulation.Step(Real, s, new Command[] { new BuyArms(count), new ConvertDollars(converted) }).Rejected.Any(x => x.Reason == Pools.RefusedDebtCeiling));
+ Assert.Equal(hash, s.Hash()); // the queue is judged on a copy
}
// R-ARMS-002 (#2206): the warning runs the whole queue as End turn will, so spending queued before the purchase counts
- // too. On the first turn (Treasury IL 20m, no debt, the IL 250m ceiling, IL 1m an Arms, IL 0.333 per $) one halutz group
- // (IL 0.5m, paid or borrowed at once) and $4m (IL 1.332m) leave IL 20.832m: 271 Arms borrow IL 250.168m, past the
- // ceiling, so End turn refuses them; 270 borrow IL 249.168m and pass. Counting only the conversion said IL 249.668m.
+ // too. The boundary is derived from the starting Treasury and debt, the ceiling, the Arms price, the halutz training cost,
+ // and the monthly conversion at the dated rate.
[Fact]
public void TheCeilingCheckCountsTheSpendingQueuedBeforeThePurchase()
{
var s = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
- Assert.Equal(0.5, Real.UnitTypes.Single(t => t.Id == "halutz").TrainingCost);
- var queued = new Command[] { new Train("tel_aviv", "halutz", 1), new ConvertDollars(4) };
- Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, queued, 271));
- Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(Simulation.Step(Real, s, queued.Append(new BuyArms(271)).ToList()).Rejected).Reason);
- Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, queued, 270));
- Assert.Empty(Simulation.Step(Real, s, queued.Append(new BuyArms(270)).ToList()).Rejected);
- // The conversion alone: 271 Arms borrow IL 249.668m and pass.
- Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, new Command[] { new ConvertDollars(4) }, 271));
+ var m = Real.RulesAt(s.Date).Mvp!;
+ var converted = m.DollarsPerTurn!.Value;
+ var trainingCost = Real.UnitTypes.Single(t => t.Id == "halutz").TrainingCost;
+ var convertedMoney = converted * m.IlPerDollarOn(s.Date);
+ var firstRefused = FirstArmsPastDebtCeiling(Real, s, convertedMoney - trainingCost);
+ var queued = new Command[] { new Train("tel_aviv", "halutz", 1), new ConvertDollars(converted) };
+ Assert.True(Pools.BorrowsPastDebtCeiling(Real, s, queued, firstRefused));
+ Assert.Equal(Pools.RefusedDebtCeiling, Assert.Single(Simulation.Step(Real, s, queued.Append(new BuyArms(firstRefused)).ToList()).Rejected).Reason);
+ Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, queued, firstRefused - 1));
+ Assert.Empty(Simulation.Step(Real, s, queued.Append(new BuyArms(firstRefused - 1)).ToList()).Rejected);
+ Assert.False(Pools.BorrowsPastDebtCeiling(Real, s, new Command[] { new ConvertDollars(converted) }, firstRefused)); // the conversion alone lets them pass
}
// #2206: for each queue on the Defence screen, the warning says "refused" for exactly the amounts End turn refuses for the
diff --git a/sim/Statecraft.Sim.Tests/EndReportTests.cs b/sim/Statecraft.Sim.Tests/EndReportTests.cs
index 237e09d35..739cd1627 100644
--- a/sim/Statecraft.Sim.Tests/EndReportTests.cs
+++ b/sim/Statecraft.Sim.Tests/EndReportTests.cs
@@ -10,6 +10,9 @@ public class EndReportTests
{
static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());
+ static int PayingObjectiveCount(Content c) =>
+ c.Objectives.Count(o => o.PartOf == "") + c.Objectives.Where(o => o.PartOf != "").Select(o => o.PartOf).Distinct(StringComparer.Ordinal).Count();
+
/// <summary>A real GDD game on its last day, ended as the MVP ends, with the first objective completed a month early.</summary>
static GameState Ended()
{
@@ -55,7 +58,9 @@ public class EndReportTests
public void TheReferenceScoreIsWhatCompletingEveryObjectiveOnItsHistoricalDateScores()
{
var s = Ended();
- Assert.Equal(200, EndReport.For(Real, s).ReferenceScore); // 100 each: the three infrastructure parts count once, plus absorption
+ Assert.True(PayingObjectiveCount(Real) < Real.Objectives.Count); // a group's parts pay once, so counting parts would differ
+ var expected = PayingObjectiveCount(Real) * Real.RulesAt(s.Date).Mvp!.ObjectivePoints!.Value;
+ Assert.Equal(expected, EndReport.For(Real, s).ReferenceScore);
// The same number by playing it: every objective recorded on its reference date, no timing bonus on time.
var perfect = Simulation.NewGame(Real, GoldenRun.Seed, Mode.Historical);
@@ -86,7 +91,11 @@ public class EndReportTests
Assert.True(Objectives.Record(c, s, c.RulesAt(o.ReferenceDate.AddDays(-1)).Mvp!, o.Id, o.ReferenceDate, new List<Cause>()));
s.Date = c.End;
s.GameOver = GameOverCodes.MvpEnded;
- Assert.Equal(101, s.Score);
+ var paidOn = c.Objectives.Where(o => o.PartOf == "").Select(o => o.ReferenceDate)
+ .Concat(c.Objectives.Where(o => o.PartOf != "").GroupBy(o => o.PartOf, StringComparer.Ordinal).Select(g => g.Max(o => o.ReferenceDate)));
+ var points = paidOn.Select(d => c.RulesAt(d.AddDays(-1)).Mvp!.ObjectivePoints!.Value).ToList();
+ Assert.True(points.Distinct().Count() >= 2); // the paying objectives fall in more than one era, so one era's points for all would differ
+ Assert.Equal(points.Sum(), s.Score);
Assert.Equal(s.Score, EndReport.For(c, s).ReferenceScore);
}
@@ -95,12 +104,13 @@ public class EndReportTests
public void AGroupIdEqualToAStandaloneObjectiveIdStillCountsBoth()
{
var c = ContentLoader.Load(RealContentTests.ContentRoot());
+ Assert.Contains(c.Objectives, o => o.PartOf == "" && o.Id == "absorb_immigrants"); // the standalone id the group takes
foreach (var o in c.Objectives.Where(o => o.PartOf != "")) o.PartOf = "absorb_immigrants";
var s = Simulation.NewGame(c, GoldenRun.Seed, Mode.Historical);
foreach (var o in c.Objectives)
Assert.True(Objectives.Record(c, s, c.RulesAt(s.Date).Mvp!, o.Id, o.ReferenceDate, new List<Cause>()));
s.GameOver = GameOverCodes.MvpEnded;
- Assert.Equal(200, s.Score);
+ Assert.Equal(PayingObjectiveCount(c) * c.RulesAt(s.Date).Mvp!.ObjectivePoints!.Value, s.Score);
Assert.Equal(s.Score, EndReport.For(c, s).ReferenceScore);
}
@@ -183,9 +193,10 @@ public class EndReportTests
var s = Ended();
Assert.Equal(0, EndReport.For(Real, s).PrisonersReturned);
s.PrisonersReturned["lebanon"] = 4; s.PrisonersReturned["egypt"] = 2;
- // What the Defence screen shows for these six units (DefencePresenter: units times rules.yaml's 1,000 people a unit).
- Assert.Equal(1000, Real.RulesAt(s.Date).Mvp!.PeoplePerUnit);
- Assert.Equal(6000, EndReport.For(Real, s).PrisonersReturned);
+ // What the Defence screen shows for these six units (DefencePresenter: units times rules.yaml's people per unit).
+ var peoplePerUnit = Real.RulesAt(s.Date).Mvp!.PeoplePerUnit;
+ Assert.True(peoplePerUnit > 1); // so units and people differ
+ Assert.Equal((4 + 2) * peoplePerUnit, EndReport.For(Real, s).PrisonersReturned);
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/EventRetimingTests.cs b/sim/Statecraft.Sim.Tests/EventRetimingTests.cs
index 5fdc1d05e..614f9b6ca 100644
--- a/sim/Statecraft.Sim.Tests/EventRetimingTests.cs
+++ b/sim/Statecraft.Sim.Tests/EventRetimingTests.cs
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using Statecraft.Sim;
/// <summary>The event windows re-timed for monthly turns at the cutover (docs/superpowers/specs/2026-10-14-event-timing-monthly.md,
@@ -25,7 +27,7 @@ public class EventRetimingTests
/// (a card raised at the new game comes on 15 May 1948), or null.</summary>
static DateTime? CardDate(string id) => Run.FirstOrDefault(s => s.FiredEvents.Contains(id))?.Date;
- /// <summary>#567's historical monthly run, now including objective 3's three cards (#791): all 39 ordinary events
+ /// <summary>#567's historical monthly run, now including objective 3's three cards (#791): all the ordinary events
/// except the six conditional cards below fire. Consequence cards belong only to alternate roads.</summary>
[Fact]
public void EveryEventFiresInTheHistoricalMonthlyRun()
@@ -39,8 +41,13 @@ public class EventRetimingTests
// remain unfinished (R-OBJ-005), so neither of their completion cards is expected. Deport's cards (R-EVT-007)
// follow only a Deport, which the reference player never orders (R-CTRL-009).
var missing = record.Select(e => e.Id).Where(id => CardDate(id) == null).ToList();
- Assert.True(missing.SequenceEqual(new[] { "absorb_immigrants", "burma_road_complete", "deport_acre", "deport_nazareth", "hula_drainage", "railway_complete" }), "never fired: " + string.Join(", ", missing));
- Assert.Equal(39, record.Count);
+ var expectedMissing = new[] { "absorb_immigrants", "burma_road_complete", "deport_acre", "deport_nazareth", "hula_drainage", "railway_complete" };
+ Assert.True(missing.SequenceEqual(expectedMissing), "never fired: " + string.Join(", ", missing));
+ // Every event file is in the record but the consequence cards, read from the raw files: a card the loader drops or
+ // misreads as a consequence would leave the run unchecked.
+ var files = Directory.GetFiles(Path.Combine(RealContentTests.ContentRoot(), "events"), "*.yaml");
+ var consequences = files.Count(f => Regex.IsMatch(File.ReadAllText(f), @"^kind:\s*consequence\s*$", RegexOptions.Multiline));
+ Assert.Equal(files.Length - consequences, record.Count);
}
/// <summary>The card date of every event, from #567's tables (the "Proposed" column in the war period, "Monthly" after
diff --git a/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs b/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs
index 6e991812a..9c75dfef0 100644
--- a/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs
+++ b/sim/Statecraft.Sim.Tests/Gdd03EventRulesTests.cs
@@ -192,7 +192,8 @@ public class Gdd03EventRulesTests
public void RealCatalogueExcludesExactlyFiveWholeCardsAndKeepsOrder()
{
var old = Real(false); var modern = Real(true);
- Assert.Equal(41, old.Events.Count); Assert.Equal(36, modern.Events.Count); // Deport's two cards (#801) are not excluded
+ Assert.Equal(41, old.Events.Count); // Deport's two cards (#801) are not excluded
+ Assert.Equal(old.Events.Count - Excluded.Length, modern.Events.Count);
Assert.Equal(Excluded, old.Events.Select(e => e.Id).Except(modern.Events.Select(e => e.Id)).OrderBy(x => x, StringComparer.Ordinal));
Assert.Equal(old.Events.Where(e => !Excluded.Contains(e.Id)).Select(e => e.Id), modern.Events.Select(e => e.Id));
Assert.NotEqual(old.Hash, modern.Hash);
diff --git a/sim/Statecraft.Sim.Tests/RealContentTests.cs b/sim/Statecraft.Sim.Tests/RealContentTests.cs
index 459b77f6d..3c9aa034f 100644
--- a/sim/Statecraft.Sim.Tests/RealContentTests.cs
+++ b/sim/Statecraft.Sim.Tests/RealContentTests.cs
@@ -49,13 +49,25 @@ public class RealContentTests
}
}
- /// <summary>R-ALT-004 on the real content: every one of the 33 alternatives carries its record.</summary>
+ /// <summary>R-ALT-004 on the real content: every alternative carries its record.</summary>
[Fact]
public void EveryAlternativeInContentSaysWhoProposedIt()
{
var c = ContentLoader.Load(ContentRoot());
var alternatives = c.Events.Where(e => e.Options.Any(o => o.Historical)).SelectMany(e => e.Options.Where(o => !o.Historical)).ToList();
- Assert.Equal(33, alternatives.Count);
+ // The same count read from the raw event files: a loader that drops an alternative would leave it unchecked.
+ var rawAlternatives = 0;
+ foreach (var file in Directory.GetFiles(Path.Combine(ContentRoot(), "events"), "*.yaml"))
+ {
+ var yaml = new YamlStream();
+ using (var reader = new StringReader(File.ReadAllText(file))) yaml.Load(reader);
+ if (!((YamlMappingNode)yaml.Documents[0].RootNode).Children.TryGetValue(new YamlScalarNode("options"), out var node)) continue;
+ var historical = ((YamlSequenceNode)node).Children.Cast<YamlMappingNode>()
+ .Select(o => o.Children.TryGetValue(new YamlScalarNode("historical"), out var h) && ((YamlScalarNode)h).Value == "true").ToList();
+ if (historical.Contains(true)) rawAlternatives += historical.Count(h => !h);
+ }
+ Assert.NotEqual(0, rawAlternatives);
+ Assert.Equal(rawAlternatives, alternatives.Count);
Assert.All(alternatives, o => Assert.NotNull(o.Alternative));
}
@@ -301,10 +313,13 @@ public class RealContentTests
Assert.Equal("naftali", Offices.Holder(C, "agriculture_minister", new DateTime(1952, 12, 24))?.Id);
var state = Simulation.NewGame(C, 42, Mode.Historical);
state.Date = change.AddDays(-1);
- Assert.Equal(0.9, EffectsSystem.Multiplier(C, state, "agriculture_minister") /
+ var eshkol = C.People.Single(p => p.Id == "eshkol").Competence;
+ var naftali = C.People.Single(p => p.Id == "naftali").Competence;
+ Assert.NotEqual(eshkol, naftali); // otherwise a stale holder would give the same multiplier
+ Assert.Equal(0.5 + eshkol / 20.0, EffectsSystem.Multiplier(C, state, "agriculture_minister") /
EffectsSystem.BudgetFactor(C, state, "agriculture_minister"), 10);
state.Date = change;
- Assert.Equal(0.85, EffectsSystem.Multiplier(C, state, "agriculture_minister") /
+ Assert.Equal(0.5 + naftali / 20.0, EffectsSystem.Multiplier(C, state, "agriculture_minister") /
EffectsSystem.BudgetFactor(C, state, "agriculture_minister"), 10);
Assert.Equal("kaplan", Cabinet.Holder(C, state, "minister_without_portfolio")?.Id);
Assert.DoesNotContain(Cabinet.Lineup(C, state), seat => seat.Office.Id == "deputy_prime_minister");
@@ -313,12 +328,27 @@ public class RealContentTests
}
[Fact]
- public void OpenQuestionsAreExactlyTheKnownOnes()
+ public void EveryOpenQuestionHasAResearchNote()
{
// #3: research_notes/budget-approval-1948-56.md answers budget_approval for the council and the First and Second
// Knessets. The Third Knesset's stays open: its 1956/57 law is read, its 1957-59 laws are not.
var open = C.Legislatures.SelectMany(l => l.OpenQuestions.Select(q => $"{l.Id}.{q}")).OrderBy(x => x).ToArray();
- Assert.Equal(new[] { "third_knesset.budget_approval" }, open);
+ // The loader keeps every open question legislatures.yaml lists.
+ var yaml = new YamlStream();
+ using (var reader = new StringReader(File.ReadAllText(Path.Combine(ContentRoot(), "legislatures.yaml")))) yaml.Load(reader);
+ var raw = ((YamlSequenceNode)((YamlMappingNode)yaml.Documents[0].RootNode)[new YamlScalarNode("legislatures")]).Children
+ .Cast<YamlMappingNode>()
+ .SelectMany(l => l.Children.TryGetValue(new YamlScalarNode("open_questions"), out var q)
+ ? ((YamlSequenceNode)q).Children.Select(x => $"{l[new YamlScalarNode("id")]}.{x}") : Enumerable.Empty<string>())
+ .OrderBy(x => x).ToArray();
+ Assert.Equal(raw, open);
+ var notes = new Dictionary<string, string> { ["budget_approval"] = "budget-approval-1948-56.md" };
+ Assert.All(open, item =>
+ {
+ var question = item.Substring(item.IndexOf('.') + 1);
+ Assert.True(notes.TryGetValue(question, out var note), $"{item} has no research note mapping");
+ Assert.True(File.Exists(Path.Combine(ContentRoot(), "..", "research_notes", note!)), $"{item} research note is missing: {note}");
+ });
}
[Fact]
@@ -383,7 +413,10 @@ public class RealContentTests
Assert.Equal((73, 120), PoliticsSystem.CoalitionSeats(C, new DateTime(1949, 6, 1)));
Assert.Equal(101828, C.Aliyah[0].Origins.Values.Sum());
Assert.Equal(239954, C.Aliyah[1].Origins.Values.Sum());
- Assert.Equal(13, C.Actors.Count);
+ var model = new YamlStream();
+ using (var reader = new StringReader(File.ReadAllText(Path.Combine(ContentRoot(), "model.yaml")))) model.Load(reader);
+ var actorRows = (YamlSequenceNode)((YamlMappingNode)model.Documents[0].RootNode)[new YamlScalarNode("actors")];
+ Assert.Equal(actorRows.Children.Count, C.Actors.Count);
}
[Fact]
@@ -485,7 +518,7 @@ public class RealContentTests
Assert.Equal(new DateTime(1951, 10, 8), C.Offices.Single(o => o.Id == "immigration_minister").Until);
Assert.Equal(new DateTime(1951, 10, 8), C.Offices.Single(o => o.Id == "war_victims_minister").Until);
Assert.Equal("shapira", Who("immigration_minister", 1951, 10, 7));
- Assert.Equal(0.15, C.Rules.BudgetStart["prime_minister"]); // the Immigration line keeps its id (#108)
+ Assert.Contains("prime_minister", C.Rules.BudgetStart.Keys); // the Immigration line keeps its id (#108)
var sheetrit = C.People.Single(p => p.Id == "sheetrit");
Assert.Equal("sephardim", Offices.PartyOf(C, sheetrit, new DateTime(1951, 1, 1)));
Assert.Equal("mapai", Offices.PartyOf(C, sheetrit, new DateTime(1951, 10, 8)));
diff --git a/sim/Statecraft.Sim.Tests/TranslationsTests.cs b/sim/Statecraft.Sim.Tests/TranslationsTests.cs
index 3e644efbb..2f9777660 100644
--- a/sim/Statecraft.Sim.Tests/TranslationsTests.cs
+++ b/sim/Statecraft.Sim.Tests/TranslationsTests.cs
@@ -102,7 +102,7 @@ public class TranslationsTests
var events = Directory.GetFiles(Path.Combine(root, "events"), "*.yaml").Select(f => Yaml(Path.GetRelativePath(root, f))).ToList();
Assert.Equal(events.Sum(e => Count(e, k => k == "title_he")), Inline.Value.Events.Count);
Assert.Equal(events.Sum(e => Count(e, k => k == "text_he")), Inline.Value.Events.Sum(e => 1 + e.Options.Count));
- Assert.Equal(41, Inline.Value.Events.Count);
+ Assert.Equal(events.Count, Inline.Value.Events.Count); // one title per event file
}
[Fact]
diff --git a/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs b/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs
index 7f5899190..b4a5066c0 100644
--- a/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs
+++ b/sim/Statecraft.Sim.Tests/TreasuryFloorTests.cs
@@ -9,7 +9,8 @@ public class TreasuryFloorTests
static readonly Content Real = ContentLoader.Load(RealContentTests.ContentRoot());
// R-MONEY-003: the golden run (the reference player on the real GDD loop) never leaves a negative Treasury, though it
- // borrows from the fourth monthly turn on. What goes below 0 is the net position (Treasury minus Debt) the top bar shows.
+ // eventually borrows. What goes below 0 is the net position (Treasury minus Debt) the top bar shows. The exact turn of
+ // the first debt is not pinned here: the golden run's state hash (golden/manifest.txt) covers it.
[Fact]
public void TheReferenceRunNeverLeavesANegativeTreasury()
{
@@ -21,10 +22,8 @@ public class TreasuryFloorTests
Assert.True(s.Treasury >= 0, $"turn {s.Turn} ({s.Date:yyyy-MM-dd}): Treasury {s.Treasury}");
if (firstDebt == null && s.Debt > 0) firstDebt = s.Turn;
}
- // 15 October 1948: 0 cash and IL 5.4m debt. It was turn 4 (15 September, IL 1.5m) while HistoricalAI's call-up order
- // sent the reserves home a turn after the first truce; the GDD loop now lowers the call-up with the rung (R-WAR-002),
- // which made it turn 5. The Israeli formations' Money upkeep (R-UNIT-010, #1130) brings it back to turn 4.
- Assert.Equal(4, firstDebt);
+ Assert.NotNull(firstDebt);
+ Assert.InRange(firstDebt!.Value, 1, s.Turn); // a turn of this run
}
// R-MONEY-003: an event's cost is a payment like any other. With IL 0.4m in the Treasury, the IL 1m claim on Germany