Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs @ 200:6a0a0e228e3c
Re #350: Add requirement to allow N of unit for specific other units
* Add unit tests for additive requirements
Still need tests to make sure mixing additive with non-additive is handled correctly
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 20 Dec 2011 21:01:46 +0000 |
parents | f1f4df654a91 |
children | 43b571aa4124 |
comparison
equal
deleted
inserted
replaced
199:925c37fa4feb | 200:6a0a0e228e3c |
---|---|
127 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 127 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
128 factory.CreateRequirement(unitType, "fibble", raceFactory); | 128 factory.CreateRequirement(unitType, "fibble", raceFactory); |
129 } | 129 } |
130 | 130 |
131 [Test()] | 131 [Test()] |
132 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] | 132 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] |
133 public void TestExceptionsForInvalidNumber() | 133 public void TestExceptionsForInvalidNumber() |
134 { | 134 { |
135 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 135 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
136 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 136 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
137 factory.CreateRequirement(unitType, typeID1+":a", raceFactory); | 137 factory.CreateRequirement(unitType, typeID1+":a", raceFactory); |
138 } | 138 } |
139 | 139 |
140 [Test()] | 140 [Test()] |
141 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] | 141 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] |
142 public void TestExceptionsForInvalidAllowedNumber() | 142 public void TestExceptionsForInvalidAllowedNumber() |
143 { | 143 { |
144 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 144 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
145 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 145 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
146 factory.CreateRequirement(unitType, typeID1 + ":3;a", raceFactory); | 146 factory.CreateRequirement(unitType, typeID1 + ":3;a", raceFactory); |
147 } | 147 } |
148 | 148 |
149 [Test()] | 149 [Test()] |
150 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] | 150 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] |
151 public void TestExceptionsForInvalidMinimumNumber() | 151 public void TestExceptionsForInvalidMinimumNumber() |
152 { | 152 { |
153 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 153 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
154 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 154 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
155 factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory); | 155 factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory); |
156 } | |
157 | |
158 [Test()] | |
159 public void TestCreatesCorrectAdditiveRequirement() | |
160 { | |
161 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
162 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
163 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
164 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
165 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory); | |
166 Assert.That(req, Is.EqualTo(expectedReq)); | |
167 } | |
168 | |
169 [Test()] | |
170 public void TestCreatesCorrectAdditiveRequirementForTwoIDs() | |
171 { | |
172 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
173 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
174 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
175 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
176 expectedReq.AddUnitTypeRequirement(unitType2); | |
177 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory); | |
178 Assert.That(req, Is.EqualTo(expectedReq)); | |
179 } | |
180 | |
181 [Test()] | |
182 public void TestCreatesCorrectAdditiveRequirementWithNumber() | |
183 { | |
184 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
185 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
186 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
187 expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); | |
188 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory); | |
189 Assert.That(req, Is.EqualTo(expectedReq)); | |
190 } | |
191 | |
192 /*[Test()] | |
193 public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers() | |
194 { | |
195 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
196 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
197 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
198 expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2); | |
199 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory); | |
200 Assert.That(req, Is.EqualTo(expectedReq)); | |
201 }*/ | |
202 | |
203 [Test()] | |
204 public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers() | |
205 { | |
206 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
207 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
208 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
209 expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); | |
210 expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); | |
211 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1 + ":3", raceFactory); | |
212 Assert.That(req, Is.EqualTo(expectedReq)); | |
213 } | |
214 | |
215 [Test()] | |
216 public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOneNumber() | |
217 { | |
218 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
219 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
220 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
221 expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); | |
222 expectedReq.AddUnitTypeRequirement(unitType2, unitType1); | |
223 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1, raceFactory); | |
224 Assert.That(req, Is.EqualTo(expectedReq)); | |
225 } | |
226 | |
227 [Test()] | |
228 public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOtherNumber() | |
229 { | |
230 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
231 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
232 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
233 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
234 expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); | |
235 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory); | |
236 Assert.That(req, Is.EqualTo(expectedReq)); | |
237 } | |
238 | |
239 [Test()] | |
240 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] | |
241 public void TestExceptionsForAdditiveRequirementWithInvalidID() | |
242 { | |
243 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
244 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
245 factory.CreateRequirement(unitType, "fibble;" + typeID1, raceFactory); | |
246 } | |
247 | |
248 [Test()] | |
249 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] | |
250 public void TestExceptionsForAdditiveRequirementWithOtherInvalidID() | |
251 { | |
252 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
253 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
254 factory.CreateRequirement(unitType, typeID1 + ";fibble", raceFactory); | |
255 } | |
256 | |
257 [Test()] | |
258 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] | |
259 public void TestExceptionsForAdditiveRequirementWithInvalidNumber() | |
260 { | |
261 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
262 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
263 factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a", raceFactory); | |
264 } | |
265 | |
266 [Test()] | |
267 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] | |
268 public void TestExceptionsForAdditiveRequirementWithInvalidAllowedNumber() | |
269 { | |
270 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
271 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
272 factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;a", raceFactory); | |
273 } | |
274 | |
275 [Test()] | |
276 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] | |
277 public void TestExceptionsForAdditiveRequirementWithInvalidMinimumNumber() | |
278 { | |
279 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
280 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
281 factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a;3", raceFactory); | |
156 } | 282 } |
157 } | 283 } |
158 } | 284 } |
159 | 285 |