using NUnit.Framework; using MultiversalDiplomacy.Model; using MultiversalDiplomacy.Orders; using MultiversalDiplomacy.Script; namespace MultiversalDiplomacyTests; public class ReplTest { private static ReplDriver StandardRepl() => new( new SetupScriptHandler( (msg) => {/* discard */}, World.WithStandardMap(), Adjudicator.MovementPhase)); [Test] public void SetupHandler() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Munich unit Austria Army Tyrolia unit England F Lon """); Assert.That(repl.Handler, Is.TypeOf()); SetupScriptHandler handler = (SetupScriptHandler)repl.Handler!; Assert.That(handler.World.Units.Count, Is.EqualTo(3)); Assert.That(handler.World.GetUnitAt("Mun"), Is.Not.Null); Assert.That(handler.World.GetUnitAt("Tyr"), Is.Not.Null); Assert.That(handler.World.GetUnitAt("Lon"), Is.Not.Null); repl.Execute("---"); Assert.That(repl.Handler, Is.TypeOf()); } [Test] public void SubmitOrders() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun unit Austria A Tyr unit England F Lon --- Germany A Mun hold Austria: Army Tyrolia - Vienna England: Lon h """); Assert.That(repl.Handler, Is.TypeOf()); GameScriptHandler handler = (GameScriptHandler)repl.Handler!; Assert.That(handler.Orders.Count, Is.EqualTo(3)); Assert.That(handler.Orders.Single(o => o.Power == "Germany"), Is.TypeOf()); Assert.That(handler.Orders.Single(o => o.Power == "Austria"), Is.TypeOf()); Assert.That(handler.Orders.Single(o => o.Power == "England"), Is.TypeOf()); Assert.That(handler.World.Timelines.Pasts.Count, Is.EqualTo(1)); World before = handler.World; repl.Execute("---"); Assert.That(repl.Handler, Is.TypeOf()); var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!; Assert.That(newHandler.World, Is.Not.EqualTo(before)); Assert.That(newHandler.World.Timelines.Pasts.Count, Is.EqualTo(2)); } [Test] public void AssertBasic() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Munich --- --- assert true """); repl.AssertFails("assert false"); } [Test] public void AssertOrderValidity() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun --- Germany A Mun - Stp --- """); // Order should be invalid repl.Execute("assert order-invalid Mun"); repl.AssertFails("assert order-valid Mun"); repl.ExecuteAll(""" --- Germany A Mun - Tyr --- """); // Order should be valid repl.Execute("assert order-valid Mun"); repl.AssertFails("assert order-invalid Mun"); } [Test] public void AssertSeasonPast() { var repl = StandardRepl(); repl.ExecuteAll(""" unit England F London --- --- """); // Expected past repl.Execute("assert has-past a1>a0"); // Incorrect past repl.AssertFails("assert has-past a0>a1"); repl.AssertFails("assert has-past a1>a1"); // Missing season repl.AssertFails("assert has-past a2>a1"); } [Test] public void AssertHoldOrder() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun --- """); repl.AssertFails("Germany A Mun - The Sun"); repl.Execute("---"); // Order is invalid repl.Execute("assert hold-order Mun"); // order-invalid requires the order be parsable, which this isn't repl.AssertFails("assert order-invalid Mun"); } [Test] public void AssertMovement() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun unit Austria A Tyr --- Germany Mun - Tyr --- """); // Movement fails repl.Execute("assert no-move Mun"); repl.AssertFails("assert moves Mun"); repl.ExecuteAll(""" --- Germany Mun - Boh --- """); // Movement succeeds repl.Execute("assert moves Mun"); repl.AssertFails("assert no-move Mun"); } [Test] public void AssertSupportHold() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun unit Germany A Boh unit Austria A Tyr --- Germany Mun s Boh --- """); // Support is given repl.Execute("assert support-given Mun"); repl.AssertFails("assert support-cut Mun"); repl.ExecuteAll(""" --- Germany Mun s Boh Austria Tyr - Mun --- """); // Support is cut repl.Execute("assert support-cut Mun"); repl.AssertFails("assert support-given Mun"); } [Test] public void AssertSupportMove() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Berlin unit Germany A Bohemia unit Austria A Tyrolia --- Germany: Berlin - Silesia Bohemia s Berlin - Silesia --- """); // Support is given repl.Execute("assert support-given Boh"); repl.AssertFails("assert support-cut Boh"); repl.ExecuteAll(""" --- Germany: Silesia - Munich Bohemia s Silesia - Munich Austria Tyrolia - Bohemia --- """); // Support is cut repl.AssertFails("assert support-given Boh"); repl.Execute("assert support-cut Boh"); } [Test] public void AssertDislodged() { var repl = StandardRepl(); repl.ExecuteAll(""" unit Germany A Mun unit Germany A Boh unit Austria A Tyr --- Germany Mun - Tyr --- """); // Move repelled repl.Execute("assert not-dislodged Tyr"); repl.AssertFails("assert dislodged Tyr"); repl.ExecuteAll(""" --- Germany Mun - Tyr Germany Boh s Mun - Tyr --- """); // Move succeeds repl.Execute("assert dislodged Tyr"); repl.AssertFails("assert not-dislodged Tyr"); } }