changeset 198:6a54d1787fbe

Re #350: Add requirement to allow N of unit for specific other units * Add big stack of test methods to test additive requirements with allowed values other than one * Add helper method to reduce repetition (used in new code, but not yet in old code)
author IBBoard <dev@ibboard.co.uk>
date Thu, 15 Dec 2011 21:00:37 +0000
parents aa921248ffbf
children 925c37fa4feb
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 125 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Wed Dec 07 21:02:13 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Thu Dec 15 21:00:37 2011 +0000
     1.3 @@ -283,6 +283,123 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestAddingUnrelatedUnitWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA()
     1.8 +		{
     1.9 +			Army army = new Army(mockRace, "Test", 1000);
    1.10 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.11 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.12 +			Unit unit = CreateUnitOfType(unitType4, army);
    1.13 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    1.14 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.15 +		}
    1.16 +
    1.17 +		[Test()]
    1.18 +		public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses()
    1.19 +		{
    1.20 +			Army army = new Army(mockRace, "Test", 1000);
    1.21 +			AddUnitOfTypeToArmy(unitType2, army);
    1.22 +			AddUnitsOfTypeToArmy(2, unitType1, army);
    1.23 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.24 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.25 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.26 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.27 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.28 +		}
    1.29 +
    1.30 +		[Test()]
    1.31 +		public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses()
    1.32 +		{
    1.33 +			Army army = new Army(mockRace, "Test", 1000);
    1.34 +			AddUnitOfTypeToArmy(unitType3, army);
    1.35 +			AddUnitsOfTypeToArmy(2, unitType1, army);
    1.36 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.37 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.38 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.39 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.40 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.41 +		}
    1.42 +
    1.43 +		[Test()]
    1.44 +		public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses()
    1.45 +		{
    1.46 +			Army army = new Army(mockRace, "Test", 1000);
    1.47 +			AddUnitOfTypeToArmy(unitType3, army);
    1.48 +			AddUnitOfTypeToArmy(unitType2, army);
    1.49 +			AddUnitsOfTypeToArmy(5, unitType1, army);
    1.50 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.51 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.52 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.53 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.54 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.55 +		}
    1.56 +
    1.57 +		[Test()]
    1.58 +		public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses()
    1.59 +		{
    1.60 +			Army army = new Army(mockRace, "Test", 1000);
    1.61 +			AddUnitsOfTypeToArmy(2, unitType3, army);
    1.62 +			AddUnitsOfTypeToArmy(5, unitType1, army);
    1.63 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.64 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.65 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.66 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.67 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.68 +		}
    1.69 +
    1.70 +		[Test()]
    1.71 +		public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses()
    1.72 +		{
    1.73 +			Army army = new Army(mockRace, "Test", 1000);
    1.74 +			AddUnitsOfTypeToArmy(2, unitType2, army);
    1.75 +			AddUnitsOfTypeToArmy(5, unitType1, army);
    1.76 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.77 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.78 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.79 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.80 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.81 +		}
    1.82 +
    1.83 +		[Test()]
    1.84 +		public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails()
    1.85 +		{
    1.86 +			Army army = new Army(mockRace, "Test", 1000);
    1.87 +			AddUnitOfTypeToArmy(unitType3, army);
    1.88 +			AddUnitOfTypeToArmy(unitType2, army);
    1.89 +			AddUnitsOfTypeToArmy(6, unitType1, army);
    1.90 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.91 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
    1.92 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.93 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
    1.94 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7)."));
    1.95 +		}
    1.96 +
    1.97 +		[Test()]
    1.98 +		public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails()
    1.99 +		{
   1.100 +			Army army = new Army(mockRace, "Test", 1000);
   1.101 +			AddUnitsOfTypeToArmy(2, unitType3, army);
   1.102 +			AddUnitsOfTypeToArmy(6, unitType1, army);
   1.103 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.104 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
   1.105 +			Unit unit = CreateUnitOfType(unitType1, army);
   1.106 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
   1.107 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7)."));
   1.108 +		}
   1.109 +
   1.110 +		[Test()]
   1.111 +		public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails()
   1.112 +		{
   1.113 +			Army army = new Army(mockRace, "Test", 1000);
   1.114 +			AddUnitsOfTypeToArmy(2, unitType2, army);
   1.115 +			AddUnitsOfTypeToArmy(6, unitType1, army);
   1.116 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.117 +			req.AddUnitTypeRequirement(3, unitType2, unitType3);
   1.118 +			Unit unit = CreateUnitOfType(unitType1, army);
   1.119 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
   1.120 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7)."));
   1.121 +		}
   1.122 +
   1.123 +		[Test()]
   1.124  		public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA()
   1.125  		{
   1.126  			Army army = new Army(mockRace, "Test", 1000);
   1.127 @@ -407,6 +524,14 @@
   1.128  			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3)."));
   1.129  		}
   1.130  
   1.131 +		private static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army)
   1.132 +		{
   1.133 +			for (int i = 0; i < count; i++)
   1.134 +			{
   1.135 +				AddUnitOfTypeToArmy(unitType, army);
   1.136 +			}
   1.137 +		}
   1.138 +
   1.139  		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   1.140  		{
   1.141  			army.AddUnit(CreateUnitOfType(unitType, army));