changeset 202:49e50238c380

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests to make sure we handle required values other than 1 (e.g. "need 2 for every 3") properly
author IBBoard <dev@ibboard.co.uk>
date Fri, 23 Dec 2011 15:33:53 +0000
parents 43b571aa4124
children 2b27447ae74e
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 74 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Fri Dec 23 14:52:22 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Fri Dec 23 15:33:53 2011 +0000
     1.3 @@ -161,6 +161,44 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestAddingOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails()
     1.8 +		{
     1.9 +			Army army = new Army(mockRace, "Test", 1000);
    1.10 +			AddUnitOfTypeToArmy(unitType2, army);
    1.11 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.12 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.13 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.14 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.15 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 1 for 1)."));
    1.16 +		}
    1.17 +
    1.18 +		[Test()]
    1.19 +		public void TestAddingSecondUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails()
    1.20 +		{
    1.21 +			Army army = new Army(mockRace, "Test", 1000);
    1.22 +			AddUnitOfTypeToArmy(unitType2, army);
    1.23 +			AddUnitOfTypeToArmy(unitType1, army);
    1.24 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.25 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.26 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.27 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.28 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 1 for 2)."));
    1.29 +		}
    1.30 +
    1.31 +		[Test()]
    1.32 +		public void TestAddingFourthUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails()
    1.33 +		{
    1.34 +			Army army = new Army(mockRace, "Test", 1000);
    1.35 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.36 +			AddUnitsOfTypeToArmy(3, unitType1, army);
    1.37 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.38 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.39 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.40 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.41 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 3 for 4)."));
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45  		public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA()
    1.46  		{
    1.47  			Army army = new Army(mockRace, "Test", 1000);
    1.48 @@ -511,6 +549,42 @@
    1.49  		}
    1.50  
    1.51  		[Test()]
    1.52 +		public void TestValidatingArmyWithOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails()
    1.53 +		{
    1.54 +			Army army = new Army(mockRace, "Test", 1000);
    1.55 +			AddUnitOfTypeToArmy(unitType2, army);
    1.56 +			AddUnitOfTypeToArmy(unitType1, army);
    1.57 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.58 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.59 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.60 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 1 for 1)."));
    1.61 +		}
    1.62 +
    1.63 +		[Test()]
    1.64 +		public void TestValidatingArmyWithTwoUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails()
    1.65 +		{
    1.66 +			Army army = new Army(mockRace, "Test", 1000);
    1.67 +			AddUnitOfTypeToArmy(unitType2, army);
    1.68 +			AddUnitsOfTypeToArmy(2, unitType1, army);
    1.69 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.70 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.71 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.72 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 1 for 2)."));
    1.73 +		}
    1.74 +
    1.75 +		[Test()]
    1.76 +		public void TestValidatingArmyWithFourUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails()
    1.77 +		{
    1.78 +			Army army = new Army(mockRace, "Test", 1000);
    1.79 +			AddUnitsOfTypeToArmy(3, unitType2, army);
    1.80 +			AddUnitsOfTypeToArmy(4, unitType1, army);
    1.81 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.82 +			req.AddUnitTypeRequirement(unitType2, 2, 3);
    1.83 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.84 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 3 for 4)."));
    1.85 +		}
    1.86 +
    1.87 +		[Test()]
    1.88  		public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.89  		{
    1.90  			Army army = new Army(mockRace, "Test", 1000);