changeset 222:12ac487af0ba

Re #395: Requirements can incorrectly allow based on common divisor * Add tests to check for using common divisor (e.g. allowing 1 per 2 when we said allow 2 per 4)
author IBBoard <dev@ibboard.co.uk>
date Sat, 31 Mar 2012 15:24:41 +0100
parents c40cb2048fc3
children fd51527f6d64
files API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs
diffstat 1 files changed, 84 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Mar 24 20:34:42 2012 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Mar 31 15:24:41 2012 +0100
     1.3 @@ -478,6 +478,90 @@
     1.4  			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 2 for 5).");
     1.5  		}
     1.6  
     1.7 +		[Test]
     1.8 +		public void TestBug395RequirementShouldNotFindCommonDivisorAdding()
     1.9 +		{
    1.10 +			Army army = new Army(mockRace, "Test", 1000);
    1.11 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.12 +			req.AddUnitTypeRequirement(4, 2, unitType2);
    1.13 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.14 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 3 for 1).");
    1.15 +			AddUnitOfTypeToArmy(unitType2, army);
    1.16 +			Assert_That__PassesAdding(req, unitType1, army);
    1.17 +			AddUnitOfTypeToArmy(unitType1, army);
    1.18 +			Assert_That__PassesAdding(req, unitType1, army);
    1.19 +			AddUnitOfTypeToArmy(unitType1, army);
    1.20 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 4 for 3).");
    1.21 +			AddUnitOfTypeToArmy(unitType2, army);
    1.22 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 5 for 3).");
    1.23 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.24 +			Assert_That__PassesAdding(req, unitType1, army);
    1.25 +		}
    1.26 +
    1.27 +		[Test]
    1.28 +		public void TestBug395RequirementShouldNotFindCommonDivisorValidating()
    1.29 +		{
    1.30 +			Army army = new Army(mockRace, "Test", 1000);
    1.31 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.32 +			req.AddUnitTypeRequirement(4, 2, unitType2);
    1.33 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.34 +			AddUnitOfTypeToArmy(unitType1, army);
    1.35 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 3 for 1).");
    1.36 +			AddUnitOfTypeToArmy(unitType2, army);
    1.37 +			Assert_That__ValidationPasses(req, army);
    1.38 +			AddUnitOfTypeToArmy(unitType1, army);
    1.39 +			Assert_That__ValidationPasses(req, army);
    1.40 +			AddUnitOfTypeToArmy(unitType1, army);
    1.41 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 4 for 3).");
    1.42 +			AddUnitOfTypeToArmy(unitType2, army);
    1.43 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 5 for 3).");
    1.44 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.45 +			Assert_That__ValidationPasses(req, army);
    1.46 +		}
    1.47 +
    1.48 +		[Test]
    1.49 +		public void TestBug395RequirementShouldNotFindCommonDivisorAddingMultiUnits()
    1.50 +		{
    1.51 +			Army army = new Army(mockRace, "Test", 1000);
    1.52 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.53 +			req.AddUnitTypeRequirement(4, 2, unitType2, unitType3);
    1.54 +			AddUnitOfTypeToArmy(unitType3, army);
    1.55 +			AddUnitsOfTypeToArmy(2, unitType2, army);
    1.56 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 3 for 1).");
    1.57 +			AddUnitOfTypeToArmy(unitType2, army);
    1.58 +			Assert_That__PassesAdding(req, unitType1, army);
    1.59 +			AddUnitOfTypeToArmy(unitType1, army);
    1.60 +			Assert_That__PassesAdding(req, unitType1, army);
    1.61 +			AddUnitOfTypeToArmy(unitType1, army);
    1.62 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 4 for 3).");
    1.63 +			AddUnitOfTypeToArmy(unitType2, army);
    1.64 +			Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 5 for 3).");
    1.65 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.66 +			Assert_That__PassesAdding(req, unitType1, army);
    1.67 +		}
    1.68 +
    1.69 +		[Test]
    1.70 +		public void TestBug395RequirementShouldNotFindCommonDivisorValidatingMultiUnits()
    1.71 +		{
    1.72 +			Army army = new Army(mockRace, "Test", 1000);
    1.73 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.74 +			req.AddUnitTypeRequirement(4, 2, unitType2, unitType3);
    1.75 +			AddUnitOfTypeToArmy(unitType3, army);
    1.76 +			AddUnitsOfTypeToArmy(2, unitType2, army);
    1.77 +			AddUnitOfTypeToArmy(unitType1, army);
    1.78 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 3 for 1).");
    1.79 +			AddUnitOfTypeToArmy(unitType2, army);
    1.80 +			Assert_That__ValidationPasses(req, army);
    1.81 +			AddUnitOfTypeToArmy(unitType1, army);
    1.82 +			Assert_That__ValidationPasses(req, army);
    1.83 +			AddUnitOfTypeToArmy(unitType1, army);
    1.84 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 4 for 3).");
    1.85 +			AddUnitOfTypeToArmy(unitType2, army);
    1.86 +			Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 5 for 3).");
    1.87 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.88 +			Assert_That__ValidationPasses(req, army);
    1.89 +		}
    1.90 +
    1.91  		protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn)
    1.92  		{
    1.93  			return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn);