changeset 114:4fcac7e162fe

Re #27: Unit requirements * Add unit tests for when the unit with the prerequisite doesn't exist (requirement needn't hold)
author IBBoard <dev@ibboard.co.uk>
date Sun, 03 Apr 2011 19:03:13 +0000
parents 87cff356079d
children bcca07bee8ea
files API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Apr 03 13:31:29 2011 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Apr 03 19:03:13 2011 +0000
     1.3 @@ -112,6 +112,16 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet()
     1.8 +		{
     1.9 +			Army army = new Army(mockRace, "Test", 1000);
    1.10 +			AddUnitOfTypeToArmy(unitType2, army);
    1.11 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.12 +			req.AddUnitTypeRequirement(unitType2, 2);
    1.13 +			Assert.That(req.AllowsAdding(unitType3, army), Is.True);
    1.14 +		}
    1.15 +
    1.16 +		[Test()]
    1.17  		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
    1.18  		{
    1.19  			Army army = new Army(mockRace, "Test", 1000);
    1.20 @@ -136,6 +146,7 @@
    1.21  		public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired()
    1.22  		{
    1.23  			Army army = new Army(mockRace, "Test", 1000);
    1.24 +			AddUnitOfTypeToArmy(unitType1, army);
    1.25  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.26  			req.AddUnitTypeRequirement(unitType2);
    1.27  			Assert.That(req.ValidatesArmy(army), Is.False);
    1.28 @@ -146,10 +157,22 @@
    1.29  		{
    1.30  			Army army = new Army(mockRace, "Test", 1000);
    1.31  			AddUnitOfTypeToArmy(unitType2, army);
    1.32 +			AddUnitOfTypeToArmy(unitType1, army);
    1.33  			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.34  			req.AddUnitTypeRequirement(unitType2);
    1.35  			Assert.That(req.ValidatesArmy(army), Is.True);
    1.36  		}
    1.37 +
    1.38 +		[Test()]
    1.39 +		public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet()
    1.40 +		{
    1.41 +			Army army = new Army(mockRace, "Test", 1000);
    1.42 +			AddUnitOfTypeToArmy(unitType2, army);
    1.43 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.44 +			req.AddUnitTypeRequirement(unitType2, 2);
    1.45 +			Assert.That(req.ValidatesArmy(army), Is.True);
    1.46 +		}
    1.47 +
    1.48  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.49  		{
    1.50  			army.AddUnit(CreateUnitOfType(unitType, army));