changeset 192:f25cb069f700

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests for having requirements on more than one unit type
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Dec 2011 16:41:54 +0000
parents 2b19d6f18f3a
children cf1c0a91eaa9
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 16:13:38 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 16:41:54 2011 +0000
     1.3 @@ -63,6 +63,19 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestAddingOneUnitWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails()
     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);
    1.13 +			req.AddUnitTypeRequirement(unitType3);
    1.14 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.15 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.16 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 0 for 1)."));
    1.17 +		}
    1.18 +
    1.19 +		[Test()]
    1.20  		public void TestAddingTwoUnitsWithOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.21  		{
    1.22  			Army army = new Army(mockRace, "Test", 1000);
    1.23 @@ -88,6 +101,21 @@
    1.24  		}
    1.25  
    1.26  		[Test()]
    1.27 +		public void TestAddingTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails()
    1.28 +		{
    1.29 +			Army army = new Army(mockRace, "Test", 1000);
    1.30 +			AddUnitOfTypeToArmy(unitType2, army);
    1.31 +			AddUnitOfTypeToArmy(unitType3, army);
    1.32 +			AddUnitOfTypeToArmy(unitType1, army);
    1.33 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.34 +			req.AddUnitTypeRequirement(unitType2, 1, 2);
    1.35 +			req.AddUnitTypeRequirement(unitType3, 1, 1);
    1.36 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.37 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.38 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2)."));
    1.39 +		}
    1.40 +
    1.41 +		[Test()]
    1.42  		public void TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.43  		{
    1.44  			Army army = new Army(mockRace, "Test", 1000);
    1.45 @@ -132,6 +160,19 @@
    1.46  		}
    1.47  
    1.48  		[Test()]
    1.49 +		public void TestValidatingArmyWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails()
    1.50 +		{
    1.51 +			Army army = new Army(mockRace, "Test", 1000);
    1.52 +			AddUnitOfTypeToArmy(unitType2, army);
    1.53 +			AddUnitOfTypeToArmy(unitType1, army);
    1.54 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.55 +			req.AddUnitTypeRequirement(unitType2);
    1.56 +			req.AddUnitTypeRequirement(unitType3);
    1.57 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.58 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 0 for 1)."));
    1.59 +		}
    1.60 +
    1.61 +		[Test()]
    1.62  		public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.63  		{
    1.64  			Army army = new Army(mockRace, "Test", 1000);
    1.65 @@ -157,6 +198,21 @@
    1.66  		}
    1.67  
    1.68  		[Test()]
    1.69 +		public void TestValidatingArmyWithTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails()
    1.70 +		{
    1.71 +			Army army = new Army(mockRace, "Test", 1000);
    1.72 +			AddUnitOfTypeToArmy(unitType2, army);
    1.73 +			AddUnitOfTypeToArmy(unitType3, army);
    1.74 +			AddUnitOfTypeToArmy(unitType1, army);
    1.75 +			AddUnitOfTypeToArmy(unitType1, army);
    1.76 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.77 +			req.AddUnitTypeRequirement(unitType2, 1, 2);
    1.78 +			req.AddUnitTypeRequirement(unitType3, 1, 1);
    1.79 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.80 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2)."));
    1.81 +		}
    1.82 +
    1.83 +		[Test()]
    1.84  		public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.85  		{
    1.86  			Army army = new Army(mockRace, "Test", 1000);