5dplomacy/MultiversalDiplomacyTests/ReplTest.cs

277 lines
6.6 KiB
C#
Raw Permalink Normal View History

2024-08-27 04:18:36 +00:00
using NUnit.Framework;
using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
2024-08-27 04:18:36 +00:00
using MultiversalDiplomacy.Script;
namespace MultiversalDiplomacyTests;
public class ReplTest
{
2024-08-28 15:09:57 +00:00
private static ReplDriver StandardRepl() => new(
2024-08-28 21:10:41 +00:00
new SetupScriptHandler(
(msg) => {/* discard */},
2024-08-28 21:10:41 +00:00
World.WithStandardMap(),
Adjudicator.MovementPhase));
2024-08-28 15:09:57 +00:00
2024-08-27 04:18:36 +00:00
[Test]
public void SetupHandler()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
2024-08-27 04:18:36 +00:00
repl.ExecuteAll("""
2024-08-27 04:18:36 +00:00
unit Germany A Munich
unit Austria Army Tyrolia
2024-08-28 00:45:38 +00:00
unit England F Lon
""");
2024-08-27 04:18:36 +00:00
Assert.That(repl.Handler, Is.TypeOf<SetupScriptHandler>());
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("---");
2024-08-27 04:18:36 +00:00
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
}
[Test]
public void SubmitOrders()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
repl.ExecuteAll("""
unit Germany A Mun
unit Austria A Tyr
unit England F Lon
2024-08-28 15:09:57 +00:00
---
Germany A Mun hold
Austria: Army Tyrolia - Vienna
England:
Lon h
""");
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
GameScriptHandler handler = (GameScriptHandler)repl.Handler!;
Assert.That(handler.Orders.Count, Is.EqualTo(3));
Assert.That(handler.Orders.Single(o => o.Power == "Germany"), Is.TypeOf<HoldOrder>());
Assert.That(handler.Orders.Single(o => o.Power == "Austria"), Is.TypeOf<MoveOrder>());
Assert.That(handler.Orders.Single(o => o.Power == "England"), Is.TypeOf<HoldOrder>());
Assert.That(handler.World.Timelines.Pasts.Count, Is.EqualTo(1));
World before = handler.World;
repl.Execute("---");
Assert.That(repl.Handler, Is.TypeOf<AdjudicationQueryScriptHandler>());
var newHandler = (AdjudicationQueryScriptHandler)repl.Handler!;
Assert.That(newHandler.World, Is.Not.EqualTo(before));
Assert.That(newHandler.World.Timelines.Pasts.Count, Is.EqualTo(2));
}
2024-08-28 15:01:27 +00:00
[Test]
public void AssertBasic()
{
2024-08-28 15:09:57 +00:00
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 15:01:27 +00:00
unit Germany A Munich
---
---
2024-08-28 15:09:57 +00:00
assert true
""");
2024-08-28 15:09:57 +00:00
repl.AssertFails("assert false");
2024-08-28 15:01:27 +00:00
}
2024-08-28 19:14:19 +00:00
[Test]
public void AssertOrderValidity()
2024-08-28 19:14:19 +00:00
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
unit Germany A Mun
---
2024-09-02 19:52:27 +00:00
Germany A Mun - Stp
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
// Order should be invalid
repl.Execute("assert order-invalid Mun");
repl.AssertFails("assert order-valid Mun");
2024-08-28 19:14:19 +00:00
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
---
Germany A Mun - Tyr
---
""");
2024-08-28 19:14:19 +00:00
// Order should be valid
repl.Execute("assert order-valid Mun");
repl.AssertFails("assert order-invalid Mun");
2024-08-28 19:14:19 +00:00
}
[Test]
public void AssertSeasonPast()
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
unit England F London
---
---
""");
2024-08-28 19:14:19 +00:00
2024-09-03 04:25:37 +00:00
// Expected past
repl.Execute("assert has-past a1>a0");
2024-09-03 04:25:37 +00:00
// Incorrect past
repl.AssertFails("assert has-past a0>a1");
2024-09-03 04:25:37 +00:00
repl.AssertFails("assert has-past a1>a1");
// Missing season
repl.AssertFails("assert has-past a2>a1");
2024-08-28 19:14:19 +00:00
}
[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");
}
2024-08-28 19:14:19 +00:00
[Test]
2024-09-03 04:25:37 +00:00
public void AssertMovement()
2024-08-28 19:14:19 +00:00
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
unit Germany A Mun
unit Austria A Tyr
---
Germany Mun - Tyr
---
""");
2024-08-28 19:14:19 +00:00
2024-09-03 04:25:37 +00:00
// 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");
2024-08-28 19:14:19 +00:00
}
[Test]
2024-09-05 05:22:07 +00:00
public void AssertSupportHold()
2024-08-28 19:14:19 +00:00
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
unit Germany A Mun
unit Germany A Boh
unit Austria A Tyr
---
2024-09-05 05:22:07 +00:00
Germany Mun s Boh
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
2024-09-05 05:22:07 +00:00
// Support is given
repl.Execute("assert support-given Mun");
repl.AssertFails("assert support-cut Mun");
2024-08-28 19:14:19 +00:00
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
---
2024-09-05 05:22:07 +00:00
Germany Mun s Boh
Austria Tyr - Mun
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
2024-09-05 05:22:07 +00:00
// Support is cut
repl.Execute("assert support-cut Mun");
repl.AssertFails("assert support-given Mun");
2024-08-28 19:14:19 +00:00
}
[Test]
2024-09-05 05:27:48 +00:00
public void AssertSupportMove()
2024-08-28 19:14:19 +00:00
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-09-05 05:27:48 +00:00
unit Germany A Berlin
unit Germany A Bohemia
unit Austria A Tyrolia
2024-08-28 19:14:19 +00:00
---
2024-09-05 05:27:48 +00:00
Germany:
Berlin - Silesia
Bohemia s Berlin - Silesia
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
2024-09-05 05:27:48 +00:00
// Support is given
repl.Execute("assert support-given Boh");
repl.AssertFails("assert support-cut Boh");
2024-08-28 19:14:19 +00:00
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
---
Germany:
2024-09-05 05:27:48 +00:00
Silesia - Munich
Bohemia s Silesia - Munich
Austria Tyrolia - Bohemia
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
2024-09-05 05:27:48 +00:00
// Support is cut
repl.AssertFails("assert support-given Boh");
repl.Execute("assert support-cut Boh");
2024-08-28 19:14:19 +00:00
}
[Test]
2024-09-05 05:27:48 +00:00
public void AssertDislodged()
2024-08-28 19:14:19 +00:00
{
var repl = StandardRepl();
repl.ExecuteAll("""
2024-08-28 19:14:19 +00:00
unit Germany A Mun
unit Germany A Boh
unit Austria A Tyr
---
2024-09-05 05:27:48 +00:00
Germany Mun - Tyr
---
""");
// Move repelled
repl.Execute("assert not-dislodged Tyr");
2024-09-05 05:27:48 +00:00
repl.AssertFails("assert dislodged Tyr");
2024-08-28 19:14:19 +00:00
2024-09-05 05:27:48 +00:00
repl.ExecuteAll("""
---
Germany Mun - Tyr
Germany Boh s Mun - Tyr
2024-08-28 19:14:19 +00:00
---
""");
2024-08-28 19:14:19 +00:00
2024-09-05 05:27:48 +00:00
// Move succeeds
repl.Execute("assert dislodged Tyr");
repl.AssertFails("assert not-dislodged Tyr");
2024-08-28 19:14:19 +00:00
}
2024-08-27 04:18:36 +00:00
}