Add unit tests for move location disambiguation
Some of the coastal tests fail because the coast accessibility check isn't implemented yet
This commit is contained in:
parent
80f340c0b2
commit
26f7cee070
|
@ -5,7 +5,7 @@ using MultiversalDiplomacy.Orders;
|
||||||
|
|
||||||
namespace MultiversalDiplomacyTests;
|
namespace MultiversalDiplomacyTests;
|
||||||
|
|
||||||
public class RegexTest
|
public class OrderParserTest
|
||||||
{
|
{
|
||||||
private static TestCaseData Test(string order, params string[] expected)
|
private static TestCaseData Test(string order, params string[] expected)
|
||||||
=> new TestCaseData(order, expected).SetName($"{{m}}(\"{order}\")");
|
=> new TestCaseData(order, expected).SetName($"{{m}}(\"{order}\")");
|
||||||
|
@ -216,4 +216,88 @@ public class RegexTest
|
||||||
Assert.That(move.Location, Is.EqualTo("Tyrolia/l"));
|
Assert.That(move.Location, Is.EqualTo("Tyrolia/l"));
|
||||||
Assert.That(move.Season.Key, Is.EqualTo("a0"));
|
Assert.That(move.Season.Key, Is.EqualTo("a0"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OrderDisambiguation()
|
||||||
|
{
|
||||||
|
World world = World.WithStandardMap().AddUnits("Germany A Mun");
|
||||||
|
OrderParser.TryParseOrder(world, "Germany", "Mun h", out Order? parsed);
|
||||||
|
Assert.That(parsed?.ToString(), Is.EqualTo("G A a-Munich/l@0 holds"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UnitTypeDisambiguatesCoastalLocation()
|
||||||
|
{
|
||||||
|
World world = World.WithStandardMap().AddUnits("England F Nth", "Germany A Ruhr");
|
||||||
|
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "England", "North Sea - Holland", out Order? fleetOrder),
|
||||||
|
"Failed to parse fleet order");
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "Germany", "Ruhr - Holland", out Order? armyOrder),
|
||||||
|
"Failed to parse army order");
|
||||||
|
|
||||||
|
Assert.That(fleetOrder, Is.TypeOf<MoveOrder>(), "Unexpected fleet order");
|
||||||
|
Assert.That(armyOrder, Is.TypeOf<MoveOrder>(), "Unexpected army order");
|
||||||
|
Location fleetDest = world.Map.GetLocation(((MoveOrder)fleetOrder!).Location);
|
||||||
|
Location armyDest = world.Map.GetLocation(((MoveOrder)armyOrder!).Location);
|
||||||
|
|
||||||
|
Assert.That(fleetDest.ProvinceName, Is.EqualTo(armyDest.ProvinceName));
|
||||||
|
Assert.That(fleetDest.Type, Is.EqualTo(LocationType.Water), "Unexpected fleet movement location");
|
||||||
|
Assert.That(armyDest.Type, Is.EqualTo(LocationType.Land), "Unexpected army movement location");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UnitTypeOverrulesNonsenseLocation()
|
||||||
|
{
|
||||||
|
World world = World.WithStandardMap().AddUnits("England F Nth", "Germany A Ruhr");
|
||||||
|
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "England", "F North Sea - Holland/l", out Order? fleetOrder),
|
||||||
|
"Failed to parse fleet order");
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "Germany", "A Ruhr - Holland/w", out Order? armyOrder),
|
||||||
|
"Failed to parse army order");
|
||||||
|
|
||||||
|
Assert.That(fleetOrder, Is.TypeOf<MoveOrder>(), "Unexpected fleet order");
|
||||||
|
Assert.That(armyOrder, Is.TypeOf<MoveOrder>(), "Unexpected army order");
|
||||||
|
Location fleetDest = world.Map.GetLocation(((MoveOrder)fleetOrder!).Location);
|
||||||
|
Location armyDest = world.Map.GetLocation(((MoveOrder)armyOrder!).Location);
|
||||||
|
|
||||||
|
Assert.That(fleetDest.ProvinceName, Is.EqualTo(armyDest.ProvinceName));
|
||||||
|
Assert.That(fleetDest.Type, Is.EqualTo(LocationType.Water), "Unexpected fleet movement location");
|
||||||
|
Assert.That(armyDest.Type, Is.EqualTo(LocationType.Land), "Unexpected army movement location");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DisambiguateSingleAccessibleCoast()
|
||||||
|
{
|
||||||
|
World world = World.WithStandardMap().AddUnits("France F Gascony", "France F Marseilles");
|
||||||
|
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "France", "Gascony - Spain", out Order? northOrder),
|
||||||
|
"Failed to parse north coast order");
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "France", "Marseilles - Spain", out Order? southOrder),
|
||||||
|
"Failed to parse south coast order");
|
||||||
|
|
||||||
|
Assert.That(northOrder, Is.TypeOf<MoveOrder>(), "Unexpected north coast order");
|
||||||
|
Assert.That(southOrder, Is.TypeOf<MoveOrder>(), "Unexpected south coast order");
|
||||||
|
Location north = world.Map.GetLocation(((MoveOrder)northOrder!).Location);
|
||||||
|
Location south = world.Map.GetLocation(((MoveOrder)southOrder!).Location);
|
||||||
|
|
||||||
|
Assert.That(north.Name, Is.EqualTo("north coast"), "Unexpected disambiguation");
|
||||||
|
Assert.That(south.Name, Is.EqualTo("south coast"), "Unexpected disambiguation");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DisambiguateMultipleAccessibleCoasts()
|
||||||
|
{
|
||||||
|
World world = World.WithStandardMap().AddUnits("France F Portugal");
|
||||||
|
|
||||||
|
Assert.That(
|
||||||
|
OrderParser.TryParseOrder(world, "France", "Portugal - Spain", out Order? northOrder),
|
||||||
|
Is.False,
|
||||||
|
"Should not parse ambiguous coastal move");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue