changeset 199:925c37fa4feb

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests for validating army, based on adding unit tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 20 Dec 2011 20:34:48 +0000
parents 6a54d1787fbe
children 6a0a0e228e3c
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 109 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Thu Dec 15 21:00:37 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Tue Dec 20 20:34:48 2011 +0000
     1.3 @@ -524,6 +524,115 @@
     1.4  			Assert.That(req.GetValidationMessage(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 TestValidatingArmyWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA()
     1.9 +		{
    1.10 +			Army army = new Army(mockRace, "Test", 1000);
    1.11 +			AddUnitOfTypeToArmy(unitType4, army);
    1.12 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.13 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.14 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
    1.15 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.16 +		}
    1.17 +
    1.18 +		[Test()]
    1.19 +		public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses()
    1.20 +		{
    1.21 +			Army army = new Army(mockRace, "Test", 1000);
    1.22 +			AddUnitOfTypeToArmy(unitType2, army);
    1.23 +			AddUnitsOfTypeToArmy(3, unitType1, army);
    1.24 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.25 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.26 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.27 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.28 +		}
    1.29 +
    1.30 +		[Test()]
    1.31 +		public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses()
    1.32 +		{
    1.33 +			Army army = new Army(mockRace, "Test", 1000);
    1.34 +			AddUnitOfTypeToArmy(unitType3, army);
    1.35 +			AddUnitsOfTypeToArmy(3, unitType1, army);
    1.36 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.37 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.38 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.39 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.40 +		}
    1.41 +
    1.42 +		[Test()]
    1.43 +		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses()
    1.44 +		{
    1.45 +			Army army = new Army(mockRace, "Test", 1000);
    1.46 +			AddUnitOfTypeToArmy(unitType3, army);
    1.47 +			AddUnitOfTypeToArmy(unitType2, army);
    1.48 +			AddUnitsOfTypeToArmy(6, unitType1, army);
    1.49 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.50 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.51 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.52 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.53 +		}
    1.54 +
    1.55 +		[Test()]
    1.56 +		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses()
    1.57 +		{
    1.58 +			Army army = new Army(mockRace, "Test", 1000);
    1.59 +			AddUnitsOfTypeToArmy(2, unitType3, army);
    1.60 +			AddUnitsOfTypeToArmy(6, unitType1, army);
    1.61 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.62 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.63 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.64 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.65 +		}
    1.66 +
    1.67 +		[Test()]
    1.68 +		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses()
    1.69 +		{
    1.70 +			Army army = new Army(mockRace, "Test", 1000);
    1.71 +			AddUnitsOfTypeToArmy(2, unitType2, army);
    1.72 +			AddUnitsOfTypeToArmy(6, unitType1, army);
    1.73 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.74 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.75 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
    1.76 +			Assert.That(req.GetValidationMessage(army), Is.Empty);
    1.77 +		}
    1.78 +
    1.79 +		[Test()]
    1.80 +		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails()
    1.81 +		{
    1.82 +			Army army = new Army(mockRace, "Test", 1000);
    1.83 +			AddUnitOfTypeToArmy(unitType3, army);
    1.84 +			AddUnitOfTypeToArmy(unitType2, army);
    1.85 +			AddUnitsOfTypeToArmy(7, unitType1, army);
    1.86 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.87 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.88 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
    1.89 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
    1.90 +		}
    1.91 +
    1.92 +		[Test()]
    1.93 +		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails()
    1.94 +		{
    1.95 +			Army army = new Army(mockRace, "Test", 1000);
    1.96 +			AddUnitsOfTypeToArmy(2, unitType3, army);
    1.97 +			AddUnitsOfTypeToArmy(7, unitType1, army);
    1.98 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.99 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
   1.100 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
   1.101 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
   1.102 +		}
   1.103 +
   1.104 +		[Test()]
   1.105 +		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails()
   1.106 +		{
   1.107 +			Army army = new Army(mockRace, "Test", 1000);
   1.108 +			AddUnitsOfTypeToArmy(2, unitType2, army);
   1.109 +			AddUnitsOfTypeToArmy(7, unitType1, army);
   1.110 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.111 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
   1.112 +			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
   1.113 +			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
   1.114 +		}
   1.115 +
   1.116  		private static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army)
   1.117  		{
   1.118  			for (int i = 0; i < count; i++)