changeset 233:99248d05ba9c

Re #410: Create "N units per M models in parent unit" requirement * Add "add unit" test helper method that sets a unit name * Add validation tests
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Jul 2012 15:29:43 +0100
parents fdebdeb52a40
children e418ba645d06
files API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs
diffstat 2 files changed, 75 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sun Jul 29 14:17:21 2012 +0100
     1.2 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sun Jul 29 15:29:43 2012 +0100
     1.3 @@ -78,6 +78,14 @@
     1.4  			return unit;
     1.5  		}
     1.6  
     1.7 +		protected static Unit AddUnitOfTypeToArmy(UnitType unitType, Army army, string name)
     1.8 +		{
     1.9 +			Unit unit = AddUnitOfTypeToArmy(unitType, army);
    1.10 +			unit.Name = name;
    1.11 +			return unit;
    1.12 +
    1.13 +		}
    1.14 +
    1.15  		protected static Unit CreateUnitOfType(UnitType unitType, Army army)
    1.16  		{
    1.17  			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
     2.1 --- a/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs	Sun Jul 29 14:17:21 2012 +0100
     2.2 +++ b/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs	Sun Jul 29 15:29:43 2012 +0100
     2.3 @@ -76,6 +76,73 @@
     2.4  			Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6");
     2.5  		}
     2.6  
     2.7 +		[Test()]
     2.8 +		public void TestValidatingUnitTypeWithNoParentAndOneUnitTypeRequiredIsAllowed()
     2.9 +		{
    2.10 +			Army army = new Army(mockRace, "Test", 1000);
    2.11 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.12 +			req.AddUnitTypeRequirement(unitType2);
    2.13 +			AddUnitOfTypeToArmy(unitType1, army);
    2.14 +			Assert_That__NotApplicable(req, army);
    2.15 +		}
    2.16 +		
    2.17 +		[Test()]
    2.18 +		public void TestValidatingUnitTypeWithParentAndOneUnitTypeRequiredIsAllowed()
    2.19 +		{
    2.20 +			Army army = new Army(mockRace, "Test", 1000);
    2.21 +			Unit parent = AddUnitOfTypeToArmy(unitType2, army);
    2.22 +			AddUnitOfTypeToArmy(unitType1, army, parent);
    2.23 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.24 +			req.AddUnitTypeRequirement(unitType2);
    2.25 +			Assert_That__ValidationPasses(req, army);
    2.26 +		}
    2.27 +		
    2.28 +		[Test()]
    2.29 +		public void TestValidatingUnitTypeWithWrongParentAndOneUnitTypeRequiredIsNotApplicable()
    2.30 +		{
    2.31 +			Army army = new Army(mockRace, "Test", 1000);
    2.32 +			Unit parent = AddUnitOfTypeToArmy(unitType2, army);
    2.33 +			AddUnitOfTypeToArmy(unitType1, army, parent);
    2.34 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.35 +			req.AddUnitTypeRequirement(unitType3);
    2.36 +			Assert_That__NotApplicable(req, army);
    2.37 +		}
    2.38 +		
    2.39 +		[Test()]
    2.40 +		public void TestValidatingTooManyUnitTypesWithParentAndOneUnitTypeRequiredFails()
    2.41 +		{
    2.42 +			Army army = new Army(mockRace, "Test", 1000);
    2.43 +			Unit parent = AddUnitOfTypeToArmy(unitType3, army, "TheParent");
    2.44 +			AddUnitsOfTypeToArmy(2, unitType1, army, parent);
    2.45 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.46 +			req.AddUnitTypeRequirement(unitType3);
    2.47 +			Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType3.Name + ": TheParent has 2 for 1.");
    2.48 +		}
    2.49 +		
    2.50 +		[Test()]
    2.51 +		public void TestValidatingTooManyUnitTypesWithParentAndFiveUnitTypeRequiredFails()
    2.52 +		{
    2.53 +			Army army = new Army(mockRace, "Test", 1000);
    2.54 +			Unit parent = AddUnitOfTypeToArmy(unitType2, army, "TheParent");
    2.55 +			AddUnitsOfTypeToArmy(6, unitType1, army, parent);
    2.56 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.57 +			req.AddUnitTypeRequirement(unitType2);
    2.58 +			Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType2.Name + ": TheParent has 6 for 5.");
    2.59 +		}
    2.60 +		
    2.61 +		[Test()]
    2.62 +		public void TestValidatingTooManyUnitsAtThreshold()
    2.63 +		{
    2.64 +			Army army = new Army(mockRace, "Test", 1000);
    2.65 +			Unit parent = AddUnitOfTypeToArmy(unitType2, army, "TheParent");
    2.66 +			AddUnitsOfTypeToArmy(5, unitType1, army, parent);
    2.67 +			UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1);
    2.68 +			req.AddUnitTypeRequirement(unitType2);
    2.69 +			Assert_That__ValidationPasses(req, army);
    2.70 +			AddUnitOfTypeToArmy(unitType1, army, parent);
    2.71 +			Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType2.Name + ": TheParent has 6 for 5.");
    2.72 +		}
    2.73 +
    2.74  		protected override UnitRequiresNParentModelsForMUnitsRequirement CreateRequirement(UnitType requirementOn)
    2.75  		{
    2.76  			return new UnitRequiresNParentModelsForMUnitsRequirement(requirementOn);