comparison API/Objects/RaceTests.cs @ 129:95dac00e9330

Re #27: Unit requirements * Test getting all unit requirements for race
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 19:13:42 +0000
parents 779ad76c2644
children 081b48413f6d
comparison
equal deleted inserted replaced
128:7ca536ccd27a 129:95dac00e9330
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. 3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
4 using System; 4 using System;
5 using NUnit.Framework; 5 using NUnit.Framework;
6 using IBBoard.WarFoundry.API.Objects.Mock; 6 using IBBoard.WarFoundry.API.Objects.Mock;
7 using NUnit.Framework.SyntaxHelpers; 7 using NUnit.Framework.SyntaxHelpers;
8 using IBBoard.WarFoundry.API.Objects.Requirement;
9 using System.Collections.Generic;
8 10
9 namespace IBBoard.WarFoundry.API.Objects 11 namespace IBBoard.WarFoundry.API.Objects
10 { 12 {
11 [TestFixture()] 13 [TestFixture()]
12 public class RaceTests 14 public class RaceTests
14 [Test()] 16 [Test()]
15 public void TestRaceWithNoUnitTypesHasNoRequirements() 17 public void TestRaceWithNoUnitTypesHasNoRequirements()
16 { 18 {
17 Assert.That(new MockRace().GetRequirements(), Has.Count(0)); 19 Assert.That(new MockRace().GetRequirements(), Has.Count(0));
18 } 20 }
21
22 [Test()]
23 public void TestRaceWithOneUnitTypeHasNoRequirements()
24 {
25 MockRace race = new MockRace();
26 race.AddUnitType(new MockUnitType());
27 Assert.That(race.GetRequirements(), Has.Count(0));
28 }
29
30 [Test()]
31 public void TestRaceWithOneUnitTypeWithOneRequirementHasOneRequirement()
32 {
33 MockRace race = new MockRace();
34 MockUnitType unitType = new MockUnitType();
35 UnitRequiresAtLeastNUnitsRequirement unitRequirement = new UnitRequiresAtLeastNUnitsRequirement(unitType);
36 unitType.AddRequirement(unitRequirement);
37 race.AddUnitType(unitType);
38 ICollection<IRequirement> raceRequirements = race.GetRequirements();
39 Assert.That(raceRequirements, Has.Count(1));
40 Assert.That(raceRequirements, Has.All.EqualTo(unitRequirement));
41 }
42
43 [Test()]
44 public void TestRaceWithTwoUnitTypesWithMultipleRequirementsHasMultipleRequirements()
45 {
46 MockRace race = new MockRace();
47 MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
48 UnitRequiresAtLeastNUnitsRequirement unitRequirement1 = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
49 unitType1.AddRequirement(unitRequirement1);
50 UnitRequiresNoMoreThanNOfUnitTypeRequirement unitRequirement2 = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
51 unitType1.AddRequirement(unitRequirement2);
52 race.AddUnitType(unitType1);
53 MockUnitType unitType2 = new MockUnitType("type2", "Type 2");
54 UnitRequiresAtLeastNUnitsRequirement unitRequirement3 = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
55 unitType2.AddRequirement(unitRequirement3);
56 race.AddUnitType(unitType2);
57 ICollection<IRequirement> raceRequirements = race.GetRequirements();
58 Assert.That(raceRequirements, Has.Count(3));
59 Assert.That(raceRequirements, Has.Member(unitRequirement1));
60 Assert.That(raceRequirements, Has.Member(unitRequirement2));
61 Assert.That(raceRequirements, Has.Member(unitRequirement3));
62 }
19 } 63 }
20 } 64 }
21 65