changeset 197:aa921248ffbf

Re #350: Add requirement to allow N of unit for specific other units * Add initial unit tests for handling multiple additive unit types
author IBBoard <dev@ibboard.co.uk>
date Wed, 07 Dec 2011 21:02:13 +0000
parents 498396c77601
children 6a54d1787fbe
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 125 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sun Dec 04 20:52:24 2011 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Wed Dec 07 21:02:13 2011 +0000
     1.3 @@ -18,6 +18,7 @@
     1.4  		private UnitType unitType1;
     1.5  		private UnitType unitType2;
     1.6  		private UnitType unitType3;
     1.7 +		private UnitType unitType4;
     1.8  
     1.9  		[TestFixtureSetUp()]
    1.10  		public void SetupRace()
    1.11 @@ -29,6 +30,8 @@
    1.12  			mockRace.AddUnitType(unitType2);
    1.13  			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.14  			mockRace.AddUnitType(unitType3);
    1.15 +			unitType4 = new MockUnitType("type4", "Unit Type 4");
    1.16 +			mockRace.AddUnitType(unitType4);
    1.17  		}
    1.18  
    1.19  		[Test()]
    1.20 @@ -158,6 +161,128 @@
    1.21  		}
    1.22  
    1.23  		[Test()]
    1.24 +		public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA()
    1.25 +		{
    1.26 +			Army army = new Army(mockRace, "Test", 1000);
    1.27 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.28 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.29 +			Unit unit = CreateUnitOfType(unitType4, army);
    1.30 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable));
    1.31 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOneTypePasses()
    1.36 +		{
    1.37 +			Army army = new Army(mockRace, "Test", 1000);
    1.38 +			AddUnitOfTypeToArmy(unitType2, army);
    1.39 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.40 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.41 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.42 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.43 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.44 +		}
    1.45 +
    1.46 +		[Test()]
    1.47 +		public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses()
    1.48 +		{
    1.49 +			Army army = new Army(mockRace, "Test", 1000);
    1.50 +			AddUnitOfTypeToArmy(unitType3, army);
    1.51 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.52 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.53 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.54 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.55 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.56 +		}
    1.57 +
    1.58 +		[Test()]
    1.59 +		public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses()
    1.60 +		{
    1.61 +			Army army = new Army(mockRace, "Test", 1000);
    1.62 +			AddUnitOfTypeToArmy(unitType3, army);
    1.63 +			AddUnitOfTypeToArmy(unitType2, army);
    1.64 +			AddUnitOfTypeToArmy(unitType1, army);
    1.65 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.66 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.67 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.68 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.69 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.70 +		}
    1.71 +
    1.72 +		[Test()]
    1.73 +		public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses()
    1.74 +		{
    1.75 +			Army army = new Army(mockRace, "Test", 1000);
    1.76 +			AddUnitOfTypeToArmy(unitType3, army);
    1.77 +			AddUnitOfTypeToArmy(unitType3, army);
    1.78 +			AddUnitOfTypeToArmy(unitType1, army);
    1.79 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.80 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.81 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.82 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.83 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.84 +		}
    1.85 +
    1.86 +		[Test()]
    1.87 +		public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses()
    1.88 +		{
    1.89 +			Army army = new Army(mockRace, "Test", 1000);
    1.90 +			AddUnitOfTypeToArmy(unitType2, army);
    1.91 +			AddUnitOfTypeToArmy(unitType2, army);
    1.92 +			AddUnitOfTypeToArmy(unitType1, army);
    1.93 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
    1.94 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.95 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.96 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
    1.97 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty);
    1.98 +		}
    1.99 +
   1.100 +		[Test()]
   1.101 +		public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails()
   1.102 +		{
   1.103 +			Army army = new Army(mockRace, "Test", 1000);
   1.104 +			AddUnitOfTypeToArmy(unitType3, army);
   1.105 +			AddUnitOfTypeToArmy(unitType2, army);
   1.106 +			AddUnitOfTypeToArmy(unitType1, army);
   1.107 +			AddUnitOfTypeToArmy(unitType1, army);
   1.108 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.109 +			req.AddUnitTypeRequirement(unitType2, unitType3);
   1.110 +			Unit unit = CreateUnitOfType(unitType1, army);
   1.111 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
   1.112 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3)."));
   1.113 +		}
   1.114 +
   1.115 +		[Test()]
   1.116 +		public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails()
   1.117 +		{
   1.118 +			Army army = new Army(mockRace, "Test", 1000);
   1.119 +			AddUnitOfTypeToArmy(unitType3, army);
   1.120 +			AddUnitOfTypeToArmy(unitType3, army);
   1.121 +			AddUnitOfTypeToArmy(unitType1, army);
   1.122 +			AddUnitOfTypeToArmy(unitType1, army);
   1.123 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.124 +			req.AddUnitTypeRequirement(unitType2, unitType3);
   1.125 +			Unit unit = CreateUnitOfType(unitType1, army);
   1.126 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
   1.127 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3)."));
   1.128 +		}
   1.129 +
   1.130 +		[Test()]
   1.131 +		public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails()
   1.132 +		{
   1.133 +			Army army = new Army(mockRace, "Test", 1000);
   1.134 +			AddUnitOfTypeToArmy(unitType2, army);
   1.135 +			AddUnitOfTypeToArmy(unitType2, army);
   1.136 +			AddUnitOfTypeToArmy(unitType1, army);
   1.137 +			AddUnitOfTypeToArmy(unitType1, army);
   1.138 +			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
   1.139 +			req.AddUnitTypeRequirement(unitType2, unitType3);
   1.140 +			Unit unit = CreateUnitOfType(unitType1, army);
   1.141 +			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
   1.142 +			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3)."));
   1.143 +		}
   1.144 +
   1.145 +		[Test()]
   1.146  		public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA()
   1.147  		{
   1.148  			Army army = new Army(mockRace, "Test", 1000);