changeset 190:702a0957f9e4

Re #350: Add requirement to allow N of unit for specific other units * Add army validation tests
author IBBoard <dev@ibboard.co.uk>
date Wed, 30 Nov 2011 21:05:54 +0000
parents eea440e5891b
children 2b19d6f18f3a
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 69 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Wed Nov 30 20:45:12 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Wed Nov 30 21:05:54 2011 +0000
     1.3 @@ -101,6 +101,75 @@
     1.4  			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3)."));
     1.5  		}
     1.6  
     1.7 +		[Test()]
     1.8 +		public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA()
     1.9 +		{
    1.10 +			Army army = new Army(mockRace, "Test", 1000);
    1.11 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    1.12 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
    1.13 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.14 +		}
    1.15 +
    1.16 +		[Test()]
    1.17 +		public void TestValidatingArmyWithOneUnitTypeRequiredAndOneUnitOfTypePasses()
    1.18 +		{
    1.19 +			Army army = new Army(mockRace, "Test", 1000);
    1.20 +			AddUnitOfTypeToArmy(unitType2, army);
    1.21 +			AddUnitOfTypeToArmy(unitType1, army);
    1.22 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    1.23 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.24 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.25 +		}
    1.26 +
    1.27 +		[Test()]
    1.28 +		public void TestValidatingArmyWithOneUnitTypeRequiredAndNoUnitOfTypeFails()
    1.29 +		{
    1.30 +			Army army = new Army(mockRace, "Test", 1000);
    1.31 +			AddUnitOfTypeToArmy(unitType1, army);
    1.32 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    1.33 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.34 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 0 for 1)."));
    1.35 +		}
    1.36 +
    1.37 +		[Test()]
    1.38 +		public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.39 +		{
    1.40 +			Army army = new Army(mockRace, "Test", 1000);
    1.41 +			AddUnitOfTypeToArmy(unitType2, army);
    1.42 +			AddUnitOfTypeToArmy(unitType1, army);
    1.43 +			AddUnitOfTypeToArmy(unitType1, army);
    1.44 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2);
    1.45 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.46 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 1 for 2)."));
    1.47 +		}
    1.48 +
    1.49 +		[Test()]
    1.50 +		public void TestValidatingArmyWithTwoUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses()
    1.51 +		{
    1.52 +			Army army = new Army(mockRace, "Test", 1000);
    1.53 +			AddUnitOfTypeToArmy(unitType2, army);
    1.54 +			AddUnitOfTypeToArmy(unitType1, army);
    1.55 +			AddUnitOfTypeToArmy(unitType1, army);
    1.56 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.57 +			req.AddUnitTypeRequirement(unitType2, 1, 2);
    1.58 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.59 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.60 +		}
    1.61 +
    1.62 +		[Test()]
    1.63 +		public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
    1.64 +		{
    1.65 +			Army army = new Army(mockRace, "Test", 1000);
    1.66 +			AddUnitOfTypeToArmy(unitType2, army);
    1.67 +			AddUnitOfTypeToArmy(unitType1, army);
    1.68 +			AddUnitOfTypeToArmy(unitType1, army);
    1.69 +			AddUnitOfTypeToArmy(unitType1, army);
    1.70 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.71 +			req.AddUnitTypeRequirement(unitType2, 1, 2);
    1.72 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.73 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3)."));
    1.74 +		}
    1.75 +
    1.76  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    1.77  		{
    1.78  			army.AddUnit(CreateUnitOfType(unitType, army));