Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs @ 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 | c323770e61c2 |
comparison
equal
deleted
inserted
replaced
200:6a0a0e228e3c | 201:43b571aa4124 |
---|---|
15 public class UnitUnitRequiresNUnitsForMUnitsRequirementFactoryTest | 15 public class UnitUnitRequiresNUnitsForMUnitsRequirementFactoryTest |
16 { | 16 { |
17 private static Race race; | 17 private static Race race; |
18 private static string typeID1 = "unit1"; | 18 private static string typeID1 = "unit1"; |
19 private static string typeID2 = "unit2"; | 19 private static string typeID2 = "unit2"; |
20 private static string typeID3 = "unit3"; | |
20 private static UnitType unitType1; | 21 private static UnitType unitType1; |
21 private static UnitType unitType2; | 22 private static UnitType unitType2; |
23 private static UnitType unitType3; | |
22 private static MockRaceFactory raceFactory = new MockRaceFactory(); | 24 private static MockRaceFactory raceFactory = new MockRaceFactory(); |
23 | 25 |
24 [TestFixtureSetUp()] | 26 [TestFixtureSetUp()] |
25 public void Setup() | 27 public void Setup() |
26 { | 28 { |
27 race = new MockRace(); | 29 race = new MockRace(); |
28 unitType1 = new UnitType(typeID1, "Unit 1", race); | 30 unitType1 = new UnitType(typeID1, "Unit 1", race); |
29 race.AddUnitType(unitType1); | 31 race.AddUnitType(unitType1); |
30 unitType2 = new UnitType(typeID2, "Unit 2", race); | 32 unitType2 = new UnitType(typeID2, "Unit 2", race); |
31 race.AddUnitType(unitType2); | 33 race.AddUnitType(unitType2); |
34 unitType3 = new UnitType(typeID3, "Unit 3", race); | |
35 race.AddUnitType(unitType3); | |
32 } | 36 } |
33 | 37 |
34 [Test()] | 38 [Test()] |
35 public void TestCreatesRequirement() | 39 public void TestCreatesRequirement() |
36 { | 40 { |
60 IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); | 64 IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory); |
61 Assert.That(req, Is.EqualTo(expectedReq)); | 65 Assert.That(req, Is.EqualTo(expectedReq)); |
62 } | 66 } |
63 | 67 |
64 [Test()] | 68 [Test()] |
69 public void TestCreatesCorrectRequirementForThreeIDs() | |
70 { | |
71 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
72 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
73 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
74 expectedReq.AddUnitTypeRequirement(unitType1); | |
75 expectedReq.AddUnitTypeRequirement(unitType2); | |
76 expectedReq.AddUnitTypeRequirement(unitType3); | |
77 IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + "|" + typeID3, raceFactory); | |
78 Assert.That(req, Is.EqualTo(expectedReq)); | |
79 } | |
80 | |
81 [Test()] | |
65 public void TestCreatesCorrectRequirementWithNumber() | 82 public void TestCreatesCorrectRequirementWithNumber() |
66 { | 83 { |
67 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 84 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
68 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 85 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
69 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | 86 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); |
165 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory); | 182 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory); |
166 Assert.That(req, Is.EqualTo(expectedReq)); | 183 Assert.That(req, Is.EqualTo(expectedReq)); |
167 } | 184 } |
168 | 185 |
169 [Test()] | 186 [Test()] |
187 public void TestCreatesCorrectTripleAdditiveRequirement() | |
188 { | |
189 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
190 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
191 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
192 expectedReq.AddUnitTypeRequirement(unitType1, unitType2, unitType3); | |
193 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ";" + typeID3, raceFactory); | |
194 Assert.That(req, Is.EqualTo(expectedReq)); | |
195 } | |
196 | |
197 [Test()] | |
170 public void TestCreatesCorrectAdditiveRequirementForTwoIDs() | 198 public void TestCreatesCorrectAdditiveRequirementForTwoIDs() |
171 { | 199 { |
172 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 200 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
173 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 201 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
174 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | 202 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); |
187 expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); | 215 expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); |
188 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory); | 216 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory); |
189 Assert.That(req, Is.EqualTo(expectedReq)); | 217 Assert.That(req, Is.EqualTo(expectedReq)); |
190 } | 218 } |
191 | 219 |
192 /*[Test()] | 220 [Test()] |
193 public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers() | 221 public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers() |
194 { | 222 { |
195 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 223 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
196 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 224 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |
197 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | 225 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); |
198 expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2); | 226 expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2); |
199 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory); | 227 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory); |
200 Assert.That(req, Is.EqualTo(expectedReq)); | 228 Assert.That(req, Is.EqualTo(expectedReq)); |
201 }*/ | 229 } |
202 | 230 |
203 [Test()] | 231 [Test()] |
204 public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers() | 232 public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers() |
205 { | 233 { |
206 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 234 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
235 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory); | 263 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory); |
236 Assert.That(req, Is.EqualTo(expectedReq)); | 264 Assert.That(req, Is.EqualTo(expectedReq)); |
237 } | 265 } |
238 | 266 |
239 [Test()] | 267 [Test()] |
268 public void TestCreatesCorrectRequirementForOneIDAndOneAdditive() | |
269 { | |
270 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
271 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
272 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
273 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
274 expectedReq.AddUnitTypeRequirement(unitType2); | |
275 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory); | |
276 Assert.That(req, Is.EqualTo(expectedReq)); | |
277 } | |
278 | |
279 [Test()] | |
280 public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveInOtherOrder() | |
281 { | |
282 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
283 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
284 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
285 expectedReq.AddUnitTypeRequirement(unitType2); | |
286 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
287 IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2, raceFactory); | |
288 Assert.That(req, Is.EqualTo(expectedReq)); | |
289 } | |
290 | |
291 [Test()] | |
292 public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditive() | |
293 { | |
294 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
295 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
296 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
297 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
298 expectedReq.AddUnitTypeRequirement(unitType2, 3); | |
299 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3", raceFactory); | |
300 Assert.That(req, Is.EqualTo(expectedReq)); | |
301 } | |
302 | |
303 [Test()] | |
304 public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveInOtherOrder() | |
305 { | |
306 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
307 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
308 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
309 expectedReq.AddUnitTypeRequirement(unitType2, 3); | |
310 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
311 IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2, raceFactory); | |
312 Assert.That(req, Is.EqualTo(expectedReq)); | |
313 } | |
314 | |
315 [Test()] | |
316 public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumber() | |
317 { | |
318 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
319 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
320 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
321 expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); | |
322 expectedReq.AddUnitTypeRequirement(unitType2); | |
323 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2, raceFactory); | |
324 Assert.That(req, Is.EqualTo(expectedReq)); | |
325 } | |
326 | |
327 [Test()] | |
328 public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumberInOtherOrder() | |
329 { | |
330 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
331 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
332 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
333 expectedReq.AddUnitTypeRequirement(unitType2); | |
334 expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); | |
335 IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2 + ":3", raceFactory); | |
336 Assert.That(req, Is.EqualTo(expectedReq)); | |
337 } | |
338 | |
339 [Test()] | |
340 public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditive() | |
341 { | |
342 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
343 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
344 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
345 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
346 expectedReq.AddUnitTypeRequirement(3, 2, unitType2); | |
347 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3;2", raceFactory); | |
348 Assert.That(req, Is.EqualTo(expectedReq)); | |
349 } | |
350 | |
351 [Test()] | |
352 public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveInOtherOrder() | |
353 { | |
354 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
355 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
356 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
357 expectedReq.AddUnitTypeRequirement(3, 2, unitType2); | |
358 expectedReq.AddUnitTypeRequirement(unitType1, unitType2); | |
359 IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2, raceFactory); | |
360 Assert.That(req, Is.EqualTo(expectedReq)); | |
361 } | |
362 | |
363 [Test()] | |
364 public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowed() | |
365 { | |
366 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
367 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
368 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
369 expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); | |
370 expectedReq.AddUnitTypeRequirement(unitType2, 3); | |
371 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;2|" + typeID2 + ":3", raceFactory); | |
372 Assert.That(req, Is.EqualTo(expectedReq)); | |
373 } | |
374 | |
375 [Test()] | |
376 public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowedInOtherOrder() | |
377 { | |
378 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
379 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
380 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
381 expectedReq.AddUnitTypeRequirement(unitType2, 3); | |
382 expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); | |
383 IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2 + ":3;2", raceFactory); | |
384 Assert.That(req, Is.EqualTo(expectedReq)); | |
385 } | |
386 | |
387 [Test()] | |
388 public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumber() | |
389 { | |
390 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
391 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
392 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
393 expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); | |
394 expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); | |
395 IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2 + ":3;2", raceFactory); | |
396 Assert.That(req, Is.EqualTo(expectedReq)); | |
397 } | |
398 | |
399 [Test()] | |
400 public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumberInOtherOrder() | |
401 { | |
402 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | |
403 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | |
404 RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); | |
405 expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); | |
406 expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); | |
407 IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2 + ":3", raceFactory); | |
408 Assert.That(req, Is.EqualTo(expectedReq)); | |
409 } | |
410 | |
411 [Test()] | |
240 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] | 412 [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] |
241 public void TestExceptionsForAdditiveRequirementWithInvalidID() | 413 public void TestExceptionsForAdditiveRequirementWithInvalidID() |
242 { | 414 { |
243 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); | 415 UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); |
244 UnitType unitType = new UnitType("testUnit", "Test Unit", race); | 416 UnitType unitType = new UnitType("testUnit", "Test Unit", race); |