Add some basic unit tests for the movement adjudicator

This commit is contained in:
Jaculabilis 2022-03-27 15:10:34 -07:00
parent 6b1b9dce10
commit b026adbfbc
3 changed files with 88 additions and 2 deletions

View File

@ -65,7 +65,9 @@ public class MovementDecisions
// Find competing moves.
List<MoveOrder> competing = orders
.OfType<MoveOrder>()
.Where(other => other.Location.Province == move.Location.Province)
.Where(other
=> other != move
&& other.Location.Province == move.Location.Province)
.ToList();
// Create the move-related decisions.

View File

@ -1,6 +1,6 @@
using MultiversalDiplomacy.Adjudicate;
using MultiversalDiplomacy.Adjudicate.Decision;
using MultiversalDiplomacy.Model;
using MultiversalDiplomacy.Orders;
using NUnit.Framework;
@ -72,4 +72,84 @@ public class MovementAdjudicatorTest
Assert.That(order.Validation, Is.Valid, "Unexpected validation result");
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
}
[Test]
public void Adjudication_Hold()
{
TestCaseBuilder setup = new TestCaseBuilder(World.WithStandardMap().WithInitialSeason());
setup["Germany"]
.Army("Mun").Holds().GetReference(out var order);
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
var adjMun = order.Adjudications;
Assert.That(adjMun.All(adj => adj.Resolved), Is.True);
Assert.That(adjMun.OfType<IsDislodged>().Count(), Is.EqualTo(1));
IsDislodged isDislodged = adjMun.OfType<IsDislodged>().Single();
Assert.That(isDislodged.Order, Is.EqualTo(order.Order));
Assert.That(isDislodged.Outcome, Is.False);
Assert.That(isDislodged.Incoming, Is.Empty);
}
[Test]
public void Adjudication_Move()
{
TestCaseBuilder setup = new TestCaseBuilder(World.WithStandardMap().WithInitialSeason());
setup["Germany"]
.Army("Mun").MovesTo("Tyr").GetReference(out var order);
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
var adjMun = order.Adjudications;
Assert.That(adjMun.All(adj => adj.Resolved), Is.True);
Assert.That(adjMun.OfType<IsDislodged>().Count(), Is.EqualTo(1));
Assert.That(adjMun.OfType<DoesMove>().Count(), Is.EqualTo(1));
IsDislodged dislodged = adjMun.OfType<IsDislodged>().Single();
Assert.That(dislodged.Order, Is.EqualTo(order.Order));
Assert.That(dislodged.Outcome, Is.False);
DoesMove moves = adjMun.OfType<DoesMove>().Single();
Assert.That(moves.Order, Is.EqualTo(order.Order));
Assert.That(moves.Outcome, Is.True);
Assert.That(moves.Competing, Is.Empty);
Assert.That(moves.OpposingMove, Is.Null);
}
[Test]
public void Adjudication_Support()
{
TestCaseBuilder setup = new TestCaseBuilder(World.WithStandardMap().WithInitialSeason());
setup["Germany"]
.Army("Mun").MovesTo("Tyr").GetReference(out var move)
.Army("Boh").Supports.Army("Mun").MoveTo("Tyr").GetReference(out var support);
setup.ValidateOrders(MovementPhaseAdjudicator.Instance);
setup.AdjudicateOrders(MovementPhaseAdjudicator.Instance);
var adjBoh = support.Adjudications;
Assert.That(adjBoh.All(adj => adj.Resolved), Is.True);
Assert.That(adjBoh.OfType<IsDislodged>().Count(), Is.EqualTo(1));
Assert.That(adjBoh.OfType<GivesSupport>().Count(), Is.EqualTo(1));
IsDislodged dislodgeBoh = adjBoh.OfType<IsDislodged>().Single();
Assert.That(dislodgeBoh.Order, Is.EqualTo(support.Order));
Assert.That(dislodgeBoh.Outcome, Is.False);
GivesSupport supportBoh = adjBoh.OfType<GivesSupport>().Single();
Assert.That(supportBoh.Order, Is.EqualTo(support.Order));
Assert.That(supportBoh.Outcome, Is.True);
var adjMun = move.Adjudications;
Assert.That(adjMun.All(adj => adj.Resolved), Is.True);
Assert.That(adjMun.OfType<AttackStrength>().Count(), Is.EqualTo(1));
AttackStrength attackMun = adjMun.OfType<AttackStrength>().Single();
Assert.That(attackMun.Order, Is.EqualTo(move.Order));
Assert.That(attackMun.MinValue, Is.EqualTo(2));
Assert.That(attackMun.MaxValue, Is.EqualTo(2));
}
}

View File

@ -75,6 +75,10 @@ public class OrderReference<OrderType> where OrderType : Order
{
IsDislodged dislodged => dislodged.Order == this.Order,
DoesMove moves => moves.Order == this.Order,
GivesSupport supports => supports.Order == this.Order,
AttackStrength attack => attack.Order == this.Order,
DefendStrength defend => defend.Order == this.Order,
PreventStrength prevent => prevent.Order == this.Order,
_ => false,
}).ToList();
return adjudications;