2024-08-27 04:18:36 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
using MultiversalDiplomacy.Model;
|
2024-08-28 00:46:32 +00:00
|
|
|
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(
|
2024-09-03 03:20:59 +00:00
|
|
|
(msg) => {/* discard */},
|
2024-08-28 21:10:41 +00:00
|
|
|
World.WithStandardMap(),
|
2024-09-03 03:20:59 +00:00
|
|
|
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
|
|
|
|
2024-09-03 03:20:59 +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-09-03 03:20:59 +00:00
|
|
|
""");
|
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);
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.Execute("---");
|
2024-08-27 04:18:36 +00:00
|
|
|
|
|
|
|
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
|
|
|
}
|
2024-08-28 00:46:32 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void SubmitOrders()
|
|
|
|
{
|
2024-08-28 15:09:57 +00:00
|
|
|
var repl = StandardRepl();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.ExecuteAll("""
|
2024-08-28 00:46:32 +00:00
|
|
|
unit Germany A Mun
|
|
|
|
unit Austria A Tyr
|
|
|
|
unit England F Lon
|
2024-08-28 15:09:57 +00:00
|
|
|
---
|
2024-08-28 00:46:32 +00:00
|
|
|
Germany A Mun hold
|
|
|
|
Austria: Army Tyrolia - Vienna
|
|
|
|
England:
|
|
|
|
Lon h
|
2024-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 00:46:32 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.Execute("---");
|
2024-08-28 00:46:32 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
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-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 15:09:57 +00:00
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.AssertFails("assert false");
|
2024-08-28 15:01:27 +00:00
|
|
|
}
|
2024-08-28 19:14:19 +00:00
|
|
|
|
|
|
|
[Test]
|
2024-09-03 03:20:59 +00:00
|
|
|
public void AssertOrderValidity()
|
2024-08-28 19:14:19 +00:00
|
|
|
{
|
|
|
|
var repl = StandardRepl();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
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-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
2024-09-03 03:20:59 +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
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.ExecuteAll("""
|
2024-08-28 19:14:19 +00:00
|
|
|
---
|
|
|
|
Germany A Mun - Tyr
|
|
|
|
---
|
2024-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
2024-09-03 03:20:59 +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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.ExecuteAll("""
|
2024-08-28 19:14:19 +00:00
|
|
|
unit England F London
|
|
|
|
---
|
|
|
|
---
|
2024-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
2024-09-03 04:25:37 +00:00
|
|
|
// Expected past
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.Execute("assert has-past a1>a0");
|
2024-09-03 04:25:37 +00:00
|
|
|
// Incorrect past
|
2024-09-03 03:20:59 +00:00
|
|
|
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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.ExecuteAll("""
|
2024-08-28 19:14:19 +00:00
|
|
|
unit Germany A Mun
|
|
|
|
unit Austria A Tyr
|
|
|
|
---
|
|
|
|
Germany Mun - Tyr
|
|
|
|
---
|
2024-09-03 03:20:59 +00:00
|
|
|
""");
|
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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
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-09-03 03:20:59 +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
|
|
|
|
2024-09-03 03:20:59 +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-09-03 03:20:59 +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:22:07 +00:00
|
|
|
public void AssertDislodged()
|
2024-08-28 19:14:19 +00:00
|
|
|
{
|
2024-09-02 19:52:27 +00:00
|
|
|
Assert.Ignore();
|
2024-08-28 19:14:19 +00:00
|
|
|
var repl = StandardRepl();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
repl.ExecuteAll("""
|
2024-08-28 19:14:19 +00:00
|
|
|
unit Germany A Mun
|
2024-09-05 05:22:07 +00:00
|
|
|
unit Germany A Boh
|
2024-08-28 19:14:19 +00:00
|
|
|
unit Austria A Tyr
|
|
|
|
---
|
|
|
|
Germany Mun - Tyr
|
2024-09-05 05:22:07 +00:00
|
|
|
Germany Boh s Mun - Tyr
|
2024-08-28 19:14:19 +00:00
|
|
|
---
|
2024-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
2024-09-05 05:22:07 +00:00
|
|
|
// Assertion should pass for a dislodge
|
|
|
|
repl.Execute("assert dislodged Tyr");
|
|
|
|
// Assertion should fail for a repelled move
|
|
|
|
repl.AssertFails("assert holds Tyr");
|
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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
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-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
|
|
|
// `supports` and `cut` are opposites
|
2024-09-03 03:20:59 +00:00
|
|
|
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();
|
|
|
|
|
2024-09-03 03:20:59 +00:00
|
|
|
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-09-03 03:20:59 +00:00
|
|
|
""");
|
2024-08-28 19:14:19 +00:00
|
|
|
|
|
|
|
// `supports` and `cut` are opposites
|
2024-09-03 03:20:59 +00:00
|
|
|
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
|
|
|
}
|