5dplomacy/MultiversalDiplomacyTests/ReplTest.cs

272 lines
6.4 KiB
C#
Raw 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]
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]
public void AssertDislodged()
{
2024-09-02 19:52:27 +00:00
Assert.Ignore();
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
---
Germany Mun - Tyr
Germany Boh s Mun - Tyr
---
""");
2024-08-28 19:14:19 +00:00
// Assertion should pass for a dislodge
repl.Execute("assert dislodged Tyr");
2024-08-28 19:14:19 +00:00
// Assertion should fail for a repelled move
repl.AssertFails("assert holds Tyr");
2024-08-28 19:14:19 +00:00
}
[Test]
public void AssertMoves()
{
2024-09-02 19:52:27 +00:00
Assert.Ignore();
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
---
Germany Mun - Tyr
---
""");
2024-08-28 19:14:19 +00:00
// Assertion should pass for a move
repl.Execute("assert moves Mun");
2024-08-28 19:14:19 +00:00
// Assertion should fail for a successful move
repl.AssertFails("assert no-move Mun");
2024-08-28 19:14:19 +00:00
}
[Test]
public void AssertRepelled()
{
2024-09-02 19:52:27 +00:00
Assert.Ignore();
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
// Assertion should pass for a repelled move
repl.Execute("assert no-move Mun");
2024-08-28 19:14:19 +00:00
// Assertion should fail for no move
repl.AssertFails("assert moves Mun");
2024-08-28 19:14:19 +00:00
}
[Test]
public void AssertSupports()
{
2024-09-02 19:52:27 +00:00
Assert.Ignore();
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
---
Germany:
Mun - Tyr
Boh s Mun - Tyr
---
""");
2024-08-28 19:14:19 +00:00
// `supports` and `cut` are opposites
repl.Execute("assert supports Boh");
repl.AssertFails("assert cut Boh");
2024-08-28 19:14:19 +00:00
}
[Test]
public void AssertCutSupport()
{
2024-09-02 19:52:27 +00:00
Assert.Ignore();
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
unit Italy A Vienna
---
Germany:
Mun - Tyr
Boh s Mun - Tyr
Italy Vienna - Boh
---
""");
2024-08-28 19:14:19 +00:00
// `supports` and `cut` are opposites
repl.Execute("assert cut Boh");
repl.AssertFails("assert supports Boh");
2024-08-28 19:14:19 +00:00
}
2024-08-27 04:18:36 +00:00
}