changeset 220:0fa634c6391b

Re #394: Make requirements (or factory) more closely match Rollcall methods * Add matching unit tests for validation
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Mar 2012 19:32:47 +0000
parents f951595143a9
children c40cb2048fc3
files API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs
diffstat 1 files changed, 102 insertions(+), 7 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Mar 24 16:46:06 2012 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sat Mar 24 19:32:47 2012 +0000
     1.3 @@ -151,7 +151,7 @@
     1.4  		}
     1.5  
     1.6  		[Test]
     1.7 -		public void TestRequirementWithOR()
     1.8 +		public void TestAddingRequirementWithOR()
     1.9  		{
    1.10  			Army army = new Army(mockRace, "Test", 1000);
    1.11  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.12 @@ -162,7 +162,7 @@
    1.13  		}
    1.14  
    1.15  		[Test]
    1.16 -		public void TestRequirementWithORWithOtherUnit()
    1.17 +		public void TestAddingRequirementWithORWithOtherUnit()
    1.18  		{
    1.19  			Army army = new Army(mockRace, "Test", 1000);
    1.20  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.21 @@ -173,7 +173,7 @@
    1.22  		}
    1.23  
    1.24  		[Test]
    1.25 -		public void TestRequirementWithORWithLimit()
    1.26 +		public void TestAddingRequirementWithORWithLimit()
    1.27  		{
    1.28  			Army army = new Army(mockRace, "Test", 1000);
    1.29  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.30 @@ -186,7 +186,7 @@
    1.31  		}
    1.32  
    1.33  		[Test]
    1.34 -		public void TestRequirementWithORWithLimitWithOtherUnit()
    1.35 +		public void TestAddingRequirementWithORWithLimitWithOtherUnit()
    1.36  		{
    1.37  			Army army = new Army(mockRace, "Test", 1000);
    1.38  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.39 @@ -199,7 +199,7 @@
    1.40  		}
    1.41  
    1.42  		[Test]
    1.43 -		public void TestRequirementWithORWithLimitWithBothUnits()
    1.44 +		public void TestAddingRequirementWithORWithLimitWithBothUnits()
    1.45  		{
    1.46  			Army army = new Army(mockRace, "Test", 1000);
    1.47  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.48 @@ -212,7 +212,7 @@
    1.49  		}
    1.50  
    1.51  		[Test]
    1.52 -		public void TestRequirementWithORBasedOnRollcall()
    1.53 +		public void TestAddingRequirementWithORBasedOnRollcall()
    1.54  		{
    1.55  			Army army = new Army(mockRace, "Test", 1000);
    1.56  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.57 @@ -226,7 +226,7 @@
    1.58  		}
    1.59  
    1.60  		[Test]
    1.61 -		public void TestRequirementWithoutORBasedOnRollcall()
    1.62 +		public void TestAddingRequirementWithoutORBasedOnRollcall()
    1.63  		{
    1.64  			Army army = new Army(mockRace, "Test", 1000);
    1.65  			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.66 @@ -383,6 +383,101 @@
    1.67  			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).");
    1.68  		}
    1.69  
    1.70 +		[Test]
    1.71 +		public void TestRequirementWithOR()
    1.72 +		{
    1.73 +			Army army = new Army(mockRace, "Test", 1000);
    1.74 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.75 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.76 +			AddUnitOfTypeToArmy(unitType1, army);
    1.77 +			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).");
    1.78 +			AddUnitOfTypeToArmy(unitType2, army);
    1.79 +			Assert_That__ValidationPasses(req, army);
    1.80 +		}
    1.81 +
    1.82 +		[Test]
    1.83 +		public void TestRequirementWithORWithOtherUnit()
    1.84 +		{
    1.85 +			Army army = new Army(mockRace, "Test", 1000);
    1.86 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.87 +			req.AddUnitTypeRequirement(unitType2, unitType3);
    1.88 +			AddUnitOfTypeToArmy(unitType1, army);
    1.89 +			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).");
    1.90 +			AddUnitOfTypeToArmy(unitType2, army);
    1.91 +			Assert_That__ValidationPasses(req, army);
    1.92 +		}
    1.93 +
    1.94 +		[Test]
    1.95 +		public void TestRequirementWithORWithLimit()
    1.96 +		{
    1.97 +			Army army = new Army(mockRace, "Test", 1000);
    1.98 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
    1.99 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
   1.100 +			AddUnitOfTypeToArmy(unitType1, army);
   1.101 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).");
   1.102 +			AddUnitOfTypeToArmy(unitType2, army);
   1.103 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1).");
   1.104 +			AddUnitOfTypeToArmy(unitType2, army);
   1.105 +			Assert_That__ValidationPasses(req, army);
   1.106 +		}
   1.107 +
   1.108 +		[Test]
   1.109 +		public void TestRequirementWithORWithLimitWithOtherUnit()
   1.110 +		{
   1.111 +			Army army = new Army(mockRace, "Test", 1000);
   1.112 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
   1.113 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
   1.114 +			AddUnitOfTypeToArmy(unitType1, army);
   1.115 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).");
   1.116 +			AddUnitOfTypeToArmy(unitType3, army);
   1.117 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1).");
   1.118 +			AddUnitOfTypeToArmy(unitType3, army);
   1.119 +			Assert_That__ValidationPasses(req, army);
   1.120 +		}
   1.121 +
   1.122 +		[Test]
   1.123 +		public void TestRequirementWithORWithLimitWithBothUnits()
   1.124 +		{
   1.125 +			Army army = new Army(mockRace, "Test", 1000);
   1.126 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
   1.127 +			req.AddUnitTypeRequirement(2, 1, unitType2, unitType3);
   1.128 +			AddUnitOfTypeToArmy(unitType1, army);
   1.129 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1).");
   1.130 +			AddUnitOfTypeToArmy(unitType2, army);
   1.131 +			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1).");
   1.132 +			AddUnitOfTypeToArmy(unitType3, army);
   1.133 +			Assert_That__ValidationPasses(req, army);
   1.134 +		}
   1.135 +
   1.136 +		[Test]
   1.137 +		public void TestRequirementWithORBasedOnRollcall()
   1.138 +		{
   1.139 +			Army army = new Army(mockRace, "Test", 1000);
   1.140 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
   1.141 +			req.AddUnitTypeRequirement(2, unitType2, unitType3);
   1.142 +			AddUnitsOfTypeToArmy(3, unitType2, army);
   1.143 +			AddUnitsOfTypeToArmy(2, unitType3, army);
   1.144 +			AddUnitsOfTypeToArmy(10, unitType1, army);
   1.145 +			Assert_That__ValidationPasses(req, army);
   1.146 +			AddUnitOfTypeToArmy(unitType1, army);
   1.147 +			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 5 for 11).");
   1.148 +		}
   1.149 +
   1.150 +		[Test]
   1.151 +		public void TestRequirementWithoutORBasedOnRollcall()
   1.152 +		{
   1.153 +			Army army = new Army(mockRace, "Test", 1000);
   1.154 +			UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
   1.155 +			req.AddUnitTypeRequirement(2, unitType2);
   1.156 +			req.AddUnitTypeRequirement(2, unitType3);
   1.157 +			AddUnitsOfTypeToArmy(3, unitType2, army);
   1.158 +			AddUnitsOfTypeToArmy(2, unitType3, army);
   1.159 +			AddUnitsOfTypeToArmy(4, unitType1, army);
   1.160 +			Assert_That__ValidationPasses(req, army);
   1.161 +			AddUnitOfTypeToArmy(unitType1, army);
   1.162 +			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 2 for 5).");
   1.163 +		}
   1.164 +
   1.165  		protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn)
   1.166  		{
   1.167  			return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn);