changeset 219:f951595143a9

Re #394: Make requirements (or factory) more closely match Rollcall methods * Add unit tests that match text * "N for M" factory already handled "2,X|Y" (format: "X;Y:2" - "X|Y" is equivalent to Rollcall's "1,X,1,Y")
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Mar 2012 16:46:06 +0000
parents d60d93b787dc
children 0fa634c6391b
files API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs
diffstat 2 files changed, 98 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Tue Mar 06 20:32:19 2012 +0000
     1.2 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sat Mar 24 16:46:06 2012 +0000
     1.3 @@ -58,6 +58,14 @@
     1.4  			Assert.That(req.GetValidationMessage(army), Is.EqualTo(message));
     1.5  		}
     1.6  
     1.7 +		protected static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army)
     1.8 +		{
     1.9 +			for (int i = 0; i < count; i++)
    1.10 +			{
    1.11 +				AddUnitOfTypeToArmy(unitType, army);
    1.12 +			}
    1.13 +		}
    1.14 +
    1.15  		protected static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.16  		{
    1.17  			army.AddUnit(CreateUnitOfType(unitType, army));
     2.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Tue Mar 06 20:32:19 2012 +0000
     2.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Mar 24 16:46:06 2012 +0000
     2.3 @@ -151,6 +151,96 @@
     2.4  		}
     2.5  
     2.6  		[Test]
     2.7 +		public void TestRequirementWithOR()
     2.8 +		{
     2.9 +			Army army = new Army(mockRace, "Test", 1000);
    2.10 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.11 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    2.12 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).");
    2.13 +			AddUnitOfTypeToArmy(unitType2, army);
    2.14 +			Assert_That__PassesAdding(req, unitType1, army);
    2.15 +		}
    2.16 +
    2.17 +		[Test]
    2.18 +		public void TestRequirementWithORWithOtherUnit()
    2.19 +		{
    2.20 +			Army army = new Army(mockRace, "Test", 1000);
    2.21 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.22 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    2.23 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).");
    2.24 +			AddUnitOfTypeToArmy(unitType2, army);
    2.25 +			Assert_That__PassesAdding(req, unitType1, army);
    2.26 +		}
    2.27 +
    2.28 +		[Test]
    2.29 +		public void TestRequirementWithORWithLimit()
    2.30 +		{
    2.31 +			Army army = new Army(mockRace, "Test", 1000);
    2.32 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.33 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
    2.34 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).");
    2.35 +			AddUnitOfTypeToArmy(unitType2, army);
    2.36 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1).");
    2.37 +			AddUnitOfTypeToArmy(unitType2, army);
    2.38 +			Assert_That__PassesAdding(req, unitType1, army);
    2.39 +		}
    2.40 +
    2.41 +		[Test]
    2.42 +		public void TestRequirementWithORWithLimitWithOtherUnit()
    2.43 +		{
    2.44 +			Army army = new Army(mockRace, "Test", 1000);
    2.45 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.46 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
    2.47 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).");
    2.48 +			AddUnitOfTypeToArmy(unitType3, army);
    2.49 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1).");
    2.50 +			AddUnitOfTypeToArmy(unitType3, army);
    2.51 +			Assert_That__PassesAdding(req, unitType1, army);
    2.52 +		}
    2.53 +
    2.54 +		[Test]
    2.55 +		public void TestRequirementWithORWithLimitWithBothUnits()
    2.56 +		{
    2.57 +			Army army = new Army(mockRace, "Test", 1000);
    2.58 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.59 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
    2.60 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1).");
    2.61 +			AddUnitOfTypeToArmy(unitType2, army);
    2.62 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1).");
    2.63 +			AddUnitOfTypeToArmy(unitType3, army);
    2.64 +			Assert_That__PassesAdding(req, unitType1, army);
    2.65 +		}
    2.66 +
    2.67 +		[Test]
    2.68 +		public void TestRequirementWithORBasedOnRollcall()
    2.69 +		{
    2.70 +			Army army = new Army(mockRace, "Test", 1000);
    2.71 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.72 +			req.AddUnitTypeRequirement(2, unitType2, unitType3);
    2.73 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    2.74 +			AddUnitsOfTypeToArmy(2, unitType3, army);
    2.75 +			AddUnitsOfTypeToArmy(9, unitType1, army);
    2.76 +			Assert_That__PassesAdding(req, unitType1, army);
    2.77 +			AddUnitOfTypeToArmy(unitType1, army);
    2.78 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 5 for 11).");
    2.79 +		}
    2.80 +
    2.81 +		[Test]
    2.82 +		public void TestRequirementWithoutORBasedOnRollcall()
    2.83 +		{
    2.84 +			Army army = new Army(mockRace, "Test", 1000);
    2.85 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    2.86 +			req.AddUnitTypeRequirement(2, unitType2);
    2.87 +			req.AddUnitTypeRequirement(2, unitType3);
    2.88 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    2.89 +			AddUnitsOfTypeToArmy(2, unitType3, army);
    2.90 +			AddUnitsOfTypeToArmy(3, unitType1, army);
    2.91 +			Assert_That__PassesAdding(req, unitType1, army);
    2.92 +			AddUnitOfTypeToArmy(unitType1, army);
    2.93 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 2 for 5).");
    2.94 +		}
    2.95 +
    2.96 +		[Test]
    2.97  		public void TestValidationNotApplicableWithNoLimitedUnit()
    2.98  		{
    2.99  			Army army = new Army(mockRace, "Test", 1000);