276 lines
6.8 KiB
C#
276 lines
6.8 KiB
C#
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,
|
|
strict: true));
|
|
|
|
[Test]
|
|
public void SetupHandler()
|
|
{
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Munich
|
|
unit Austria Army Tyrolia
|
|
unit England F Lon
|
|
"""].AssertReady();
|
|
|
|
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["""
|
|
---
|
|
"""].AssertReady();
|
|
|
|
Assert.That(repl.Handler, Is.TypeOf<GameScriptHandler>());
|
|
}
|
|
|
|
[Test]
|
|
public void SubmitOrders()
|
|
{
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
unit Austria A Tyr
|
|
unit England F Lon
|
|
---
|
|
Germany A Mun hold
|
|
Austria: Army Tyrolia - Vienna
|
|
England:
|
|
Lon h
|
|
"""].AssertReady();
|
|
|
|
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["""
|
|
---
|
|
"""].AssertReady();
|
|
|
|
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));
|
|
}
|
|
|
|
[Test]
|
|
public void AssertBasic()
|
|
{
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Munich
|
|
---
|
|
---
|
|
assert true
|
|
"""].AssertReady();
|
|
|
|
repl["assert false"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertInvalidOrder()
|
|
{
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
---
|
|
Germany A Mun - Stp
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for an invalid order
|
|
repl["assert order-invalid Mun"].AssertReady();
|
|
// Assertion should fail for an invalid order
|
|
repl["assert order-valid Mun"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertValidOrder()
|
|
{
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
---
|
|
Germany A Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a valid order
|
|
repl["assert order-valid Mun"].AssertReady();
|
|
// Assertion should fail for a valid order
|
|
repl["assert order-invalid Mun"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertSeasonPast()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit England F London
|
|
---
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a season's past
|
|
repl["assert has-past a1>a0"].AssertReady();
|
|
// Assertion should fail for an incorrect past
|
|
repl["assert has-past a0>a1"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertHolds()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
unit Austria A Tyr
|
|
---
|
|
Germany Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a repelled move
|
|
repl["assert holds Tyr"].AssertReady();
|
|
// Assertion should fail for a repelled move
|
|
repl["assert dislodged Tyr"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertDislodged()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
unit Germany A Boh
|
|
unit Austria A Tyr
|
|
---
|
|
Germany Mun - Tyr
|
|
Germany Boh s Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a dislodge
|
|
repl["assert dislodged Tyr"].AssertReady();
|
|
// Assertion should fail for a repelled move
|
|
repl["assert holds Tyr"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertMoves()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
---
|
|
Germany Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a move
|
|
repl["assert moves Mun"].AssertReady();
|
|
// Assertion should fail for a successful move
|
|
repl["assert no-move Mun"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertRepelled()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
unit Austria A Tyr
|
|
---
|
|
Germany Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// Assertion should pass for a repelled move
|
|
repl["assert no-move Mun"].AssertReady();
|
|
// Assertion should fail for no move
|
|
repl["assert moves Mun"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertSupports()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
unit Germany A Mun
|
|
unit Germany A Boh
|
|
unit Austria A Tyr
|
|
---
|
|
Germany:
|
|
Mun - Tyr
|
|
Boh s Mun - Tyr
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// `supports` and `cut` are opposites
|
|
repl["assert supports Boh"].AssertReady();
|
|
repl["assert cut Boh"].AssertClosed();
|
|
}
|
|
|
|
[Test]
|
|
public void AssertCutSupport()
|
|
{
|
|
Assert.Ignore();
|
|
var repl = StandardRepl();
|
|
|
|
repl["""
|
|
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
|
|
---
|
|
"""].AssertReady();
|
|
|
|
// `supports` and `cut` are opposites
|
|
repl["assert cut Boh"].AssertReady();
|
|
repl["assert supports Boh"].AssertClosed();
|
|
}
|
|
}
|