changeset 201:43b571aa4124

Re #350: Add requirement to allow N of unit for specific other units * Add tests on factory for different combinations of additive and non-additive requirements
author IBBoard <dev@ibboard.co.uk>
date Fri, 23 Dec 2011 14:52:22 +0000
parents 6a0a0e228e3c
children 49e50238c380
files API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs
diffstat 1 files changed, 174 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Tue Dec 20 21:01:46 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Fri Dec 23 14:52:22 2011 +0000
     1.3 @@ -17,8 +17,10 @@
     1.4  		private static Race race;
     1.5  		private static string typeID1 = "unit1";
     1.6  		private static string typeID2 = "unit2";
     1.7 +		private static string typeID3 = "unit3";
     1.8  		private static UnitType unitType1;
     1.9  		private static UnitType unitType2;
    1.10 +		private static UnitType unitType3;
    1.11  		private static MockRaceFactory raceFactory = new MockRaceFactory();
    1.12  
    1.13  		[TestFixtureSetUp()]
    1.14 @@ -29,6 +31,8 @@
    1.15  			race.AddUnitType(unitType1);
    1.16  			unitType2 = new UnitType(typeID2, "Unit 2", race);
    1.17  			race.AddUnitType(unitType2);
    1.18 +			unitType3 = new UnitType(typeID3, "Unit 3", race);
    1.19 +			race.AddUnitType(unitType3);
    1.20  		}
    1.21  
    1.22  		[Test()]
    1.23 @@ -62,6 +66,19 @@
    1.24  		}
    1.25  
    1.26  		[Test()]
    1.27 +		public void TestCreatesCorrectRequirementForThreeIDs()
    1.28 +		{
    1.29 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.30 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.31 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.32 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.33 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.34 +			expectedReq.AddUnitTypeRequirement(unitType3);
    1.35 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + "|" + typeID3, raceFactory);
    1.36 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.37 +		}
    1.38 +
    1.39 +		[Test()]
    1.40  		public void TestCreatesCorrectRequirementWithNumber()
    1.41  		{
    1.42  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.43 @@ -167,6 +184,17 @@
    1.44  		}
    1.45  
    1.46  		[Test()]
    1.47 +		public void TestCreatesCorrectTripleAdditiveRequirement()
    1.48 +		{
    1.49 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.50 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.51 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.52 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2, unitType3);
    1.53 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ";" + typeID3, raceFactory);
    1.54 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.55 +		}
    1.56 +
    1.57 +		[Test()]
    1.58  		public void TestCreatesCorrectAdditiveRequirementForTwoIDs()
    1.59  		{
    1.60  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.61 @@ -189,7 +217,7 @@
    1.62  			Assert.That(req, Is.EqualTo(expectedReq));
    1.63  		}
    1.64  
    1.65 -		/*[Test()]
    1.66 +		[Test()]
    1.67  		public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers()
    1.68  		{
    1.69  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.70 @@ -198,7 +226,7 @@
    1.71  			expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2);
    1.72  			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory);
    1.73  			Assert.That(req, Is.EqualTo(expectedReq));
    1.74 -		}*/
    1.75 +		}
    1.76  
    1.77  		[Test()]
    1.78  		public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers()
    1.79 @@ -237,6 +265,150 @@
    1.80  		}
    1.81  
    1.82  		[Test()]
    1.83 +		public void TestCreatesCorrectRequirementForOneIDAndOneAdditive()
    1.84 +		{
    1.85 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.86 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.87 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.88 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
    1.89 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.90 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory);
    1.91 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.92 +		}
    1.93 +
    1.94 +		[Test()]
    1.95 +		public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveInOtherOrder()
    1.96 +		{
    1.97 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.98 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.99 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.100 +			expectedReq.AddUnitTypeRequirement(unitType2);
   1.101 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.102 +			IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2, raceFactory);
   1.103 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.104 +		}
   1.105 +
   1.106 +		[Test()]
   1.107 +		public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditive()
   1.108 +		{
   1.109 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.110 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.111 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.112 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.113 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.114 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3", raceFactory);
   1.115 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.116 +		}
   1.117 +
   1.118 +		[Test()]
   1.119 +		public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveInOtherOrder()
   1.120 +		{
   1.121 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.122 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.123 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.124 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.125 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.126 +			IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2, raceFactory);
   1.127 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.128 +		}
   1.129 +
   1.130 +		[Test()]
   1.131 +		public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumber()
   1.132 +		{
   1.133 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.134 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.135 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.136 +			expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2);
   1.137 +			expectedReq.AddUnitTypeRequirement(unitType2);
   1.138 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2, raceFactory);
   1.139 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.140 +		}
   1.141 +
   1.142 +		[Test()]
   1.143 +		public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumberInOtherOrder()
   1.144 +		{
   1.145 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.146 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.147 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.148 +			expectedReq.AddUnitTypeRequirement(unitType2);
   1.149 +			expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2);
   1.150 +			IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2 + ":3", raceFactory);
   1.151 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.152 +		}
   1.153 +
   1.154 +		[Test()]
   1.155 +		public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditive()
   1.156 +		{
   1.157 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.158 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.159 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.160 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.161 +			expectedReq.AddUnitTypeRequirement(3, 2, unitType2);
   1.162 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3;2", raceFactory);
   1.163 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.164 +		}
   1.165 +
   1.166 +		[Test()]
   1.167 +		public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveInOtherOrder()
   1.168 +		{
   1.169 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.170 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.171 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.172 +			expectedReq.AddUnitTypeRequirement(3, 2, unitType2);
   1.173 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.174 +			IRequirement req = factory.CreateRequirement(unitType, typeID2  + ":3;2|" + typeID1 + ";" + typeID2, raceFactory);
   1.175 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.176 +		}
   1.177 +
   1.178 +		[Test()]
   1.179 +		public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowed()
   1.180 +		{
   1.181 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.182 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.183 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.184 +			expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2);
   1.185 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.186 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;2|" + typeID2 + ":3", raceFactory);
   1.187 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.188 +		}
   1.189 +
   1.190 +		[Test()]
   1.191 +		public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowedInOtherOrder()
   1.192 +		{
   1.193 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.194 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.195 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.196 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.197 +			expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2);
   1.198 +			IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2 + ":3;2", raceFactory);
   1.199 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.200 +		}
   1.201 +
   1.202 +		[Test()]
   1.203 +		public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumber()
   1.204 +		{
   1.205 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.206 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.207 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.208 +			expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2);
   1.209 +			expectedReq.AddUnitTypeRequirement(unitType2, 3, 2);
   1.210 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2 + ":3;2", raceFactory);
   1.211 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.212 +		}
   1.213 +
   1.214 +		[Test()]
   1.215 +		public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumberInOtherOrder()
   1.216 +		{
   1.217 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.218 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.219 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.220 +			expectedReq.AddUnitTypeRequirement(unitType2, 3, 2);
   1.221 +			expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2);
   1.222 +			IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2 + ":3", raceFactory);
   1.223 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.224 +		}
   1.225 +
   1.226 +		[Test()]
   1.227  		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")]
   1.228  		public void TestExceptionsForAdditiveRequirementWithInvalidID()
   1.229  		{