2022-03-23 04:27:06 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate;
|
2022-03-27 22:10:34 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate.Decision;
|
2022-03-23 04:27:06 +00:00
|
|
|
using MultiversalDiplomacy.Model;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacyTests;
|
|
|
|
|
|
|
|
public class MovementAdjudicatorTest
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void Validation_ValidHold()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-23 04:27:06 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-23 04:27:06 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
Assert.That(order, Is.Valid, "Unexpected validation result");
|
2022-03-23 05:11:14 +00:00
|
|
|
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
|
2022-03-23 04:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Validation_ValidMove()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-23 04:27:06 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-23 04:27:06 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
Assert.That(order, Is.Valid, "Unexpected validation result");
|
2022-03-23 05:11:14 +00:00
|
|
|
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
|
2022-03-23 04:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Validation_ValidConvoy()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-23 04:27:06 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Fleet("Nth").Convoys.Army("Hol").To("Lon").GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-23 04:27:06 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
Assert.That(order, Is.Valid, "Unexpected validation result");
|
2022-03-23 05:11:14 +00:00
|
|
|
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
|
2022-03-23 04:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Validation_ValidSupportHold()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-23 04:27:06 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Supports.Army("Kie").Hold().GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-23 04:27:06 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
Assert.That(order, Is.Valid, "Unexpected validation result");
|
2022-03-23 05:11:14 +00:00
|
|
|
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
|
2022-03-23 04:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Validation_ValidSupportMove()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-23 04:27:06 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Supports.Army("Kie").MoveTo("Ber").GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-23 04:27:06 +00:00
|
|
|
|
2022-03-29 05:34:57 +00:00
|
|
|
Assert.That(order, Is.Valid, "Unexpected validation result");
|
2022-03-23 05:11:14 +00:00
|
|
|
Assert.That(order.Replacement, Is.Null, "Unexpected order replacement");
|
2022-03-23 04:27:06 +00:00
|
|
|
}
|
2022-03-27 22:10:34 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Adjudication_Hold()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-27 22:10:34 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-27 22:10:34 +00:00
|
|
|
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()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-27 22:10:34 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var order);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
|
|
|
setup.AdjudicateOrders();
|
2022-03-27 22:10:34 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-27 22:10:34 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var move)
|
|
|
|
.Army("Boh").Supports.Army("Mun").MoveTo("Tyr").GetReference(out var support);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
|
|
|
setup.AdjudicateOrders();
|
2022-03-27 22:10:34 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2022-03-30 00:16:00 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Update_SingleHold()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-30 00:16:00 +00:00
|
|
|
setup["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var mun);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun, Is.Valid);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun, Is.NotDislodged);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
World updated = setup.UpdateWorld();
|
2022-03-30 00:16:00 +00:00
|
|
|
|
|
|
|
// Confirm the future was created
|
|
|
|
Assert.That(updated.Seasons.Count, Is.EqualTo(2));
|
|
|
|
Season future = updated.Seasons.Single(s => s != updated.RootSeason);
|
|
|
|
Assert.That(future.Past, Is.EqualTo(updated.RootSeason));
|
|
|
|
Assert.That(future.Futures, Is.Empty);
|
|
|
|
Assert.That(future.Timeline, Is.EqualTo(updated.RootSeason.Timeline));
|
|
|
|
Assert.That(future.Turn, Is.EqualTo(Season.FIRST_TURN + 1));
|
|
|
|
|
|
|
|
// Confirm the unit was created
|
|
|
|
Assert.That(updated.Units.Count, Is.EqualTo(2));
|
|
|
|
Unit second = updated.Units.Single(u => u.Past != null);
|
|
|
|
Assert.That(second.Location, Is.EqualTo(mun.Order.Unit.Location));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Update_DoubleHold()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-03-30 00:16:00 +00:00
|
|
|
.GetReference(out Season s1)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var mun1);
|
|
|
|
|
|
|
|
Assert.That(mun1.Order.Unit.Season, Is.EqualTo(s1));
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun1, Is.Valid);
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun1, Is.NotDislodged);
|
2022-03-30 15:04:44 +00:00
|
|
|
World updated = setup.UpdateWorld();
|
2022-03-30 00:16:00 +00:00
|
|
|
|
|
|
|
// Confirm the future was created
|
2024-08-12 16:28:56 +00:00
|
|
|
Season s2 = updated.GetSeason("a", 1);
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(s2.Past, Is.EqualTo(s1));
|
|
|
|
Assert.That(s2.Futures, Is.Empty);
|
|
|
|
Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline));
|
|
|
|
Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1));
|
|
|
|
|
|
|
|
// Confirm the unit was created in the future
|
|
|
|
Unit u2 = updated.GetUnitAt("Mun", s2.Coord);
|
|
|
|
Assert.That(updated.Units.Count, Is.EqualTo(2));
|
|
|
|
Assert.That(u2, Is.Not.EqualTo(mun1.Order.Unit));
|
|
|
|
Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit));
|
|
|
|
Assert.That(u2.Season, Is.EqualTo(s2));
|
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 1)]
|
2022-03-30 00:16:00 +00:00
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").Holds().GetReference(out var mun2);
|
|
|
|
|
|
|
|
// Validate the second set of orders
|
2022-03-30 15:04:44 +00:00
|
|
|
var validations = setup.ValidateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(validations.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(mun2, Is.Valid);
|
|
|
|
|
|
|
|
// Adjudicate the second set of orders
|
2022-03-30 15:04:44 +00:00
|
|
|
var adjudications = setup.AdjudicateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun2, Is.NotDislodged);
|
|
|
|
|
|
|
|
// Update the world again
|
2022-03-30 15:04:44 +00:00
|
|
|
updated = setup.UpdateWorld();
|
2024-08-12 16:28:56 +00:00
|
|
|
Season s3 = updated.GetSeason(s2.Timeline, s2.Turn + 1);
|
2022-03-30 00:16:00 +00:00
|
|
|
Unit u3 = updated.GetUnitAt("Mun", s3.Coord);
|
|
|
|
Assert.That(u3.Past, Is.EqualTo(mun2.Order.Unit));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Update_DoubleMove()
|
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-03-30 00:16:00 +00:00
|
|
|
.GetReference(out Season s1)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var mun1);
|
|
|
|
|
|
|
|
Assert.That(mun1.Order.Unit.Season, Is.EqualTo(s1));
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun1, Is.Valid);
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(mun1, Is.Victorious);
|
2022-03-30 15:04:44 +00:00
|
|
|
World updated = setup.UpdateWorld();
|
2022-03-30 00:16:00 +00:00
|
|
|
|
|
|
|
// Confirm the future was created
|
2024-08-12 16:28:56 +00:00
|
|
|
Season s2 = updated.GetSeason(s1.Timeline, s1.Turn + 1);
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(s2.Past, Is.EqualTo(s1));
|
|
|
|
Assert.That(s2.Futures, Is.Empty);
|
|
|
|
Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline));
|
|
|
|
Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1));
|
|
|
|
|
|
|
|
// Confirm the unit was created in the future
|
|
|
|
Unit u2 = updated.GetUnitAt("Tyr", s2.Coord);
|
|
|
|
Assert.That(updated.Units.Count, Is.EqualTo(2));
|
|
|
|
Assert.That(u2, Is.Not.EqualTo(mun1.Order.Unit));
|
|
|
|
Assert.That(u2.Past, Is.EqualTo(mun1.Order.Unit));
|
|
|
|
Assert.That(u2.Season, Is.EqualTo(s2));
|
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 1)]
|
2022-03-30 00:16:00 +00:00
|
|
|
["Germany"]
|
|
|
|
.Army("Tyr").MovesTo("Mun").GetReference(out var tyr2);
|
|
|
|
|
|
|
|
// Validate the second set of orders
|
2022-03-30 15:04:44 +00:00
|
|
|
var validations = setup.ValidateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(validations.Count, Is.EqualTo(1));
|
|
|
|
Assert.That(tyr2, Is.Valid);
|
|
|
|
|
|
|
|
// Adjudicate the second set of orders
|
2022-03-30 15:04:44 +00:00
|
|
|
var adjudications = setup.AdjudicateOrders();
|
2022-03-30 00:16:00 +00:00
|
|
|
Assert.That(tyr2, Is.Victorious);
|
|
|
|
|
|
|
|
// Update the world again
|
2022-03-30 15:04:44 +00:00
|
|
|
updated = setup.UpdateWorld();
|
2024-08-12 16:28:56 +00:00
|
|
|
Season s3 = updated.GetSeason(s2.Timeline, s2.Turn + 1);
|
2022-03-30 00:16:00 +00:00
|
|
|
Unit u3 = updated.GetUnitAt("Mun", s3.Coord);
|
|
|
|
Assert.That(u3.Past, Is.EqualTo(u2));
|
|
|
|
}
|
2022-03-23 05:11:14 +00:00
|
|
|
}
|