comparison API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs @ 106:4dad874f4862

Re #27: Define unit requirements * Add unit tests for multiple unit types being required
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Mar 2011 19:19:04 +0000
parents 9163bd04a3db
children
comparison
equal deleted inserted replaced
105:9163bd04a3db 106:4dad874f4862
12 public class UnitRequiresAtLeastNUnitsRequirementTest 12 public class UnitRequiresAtLeastNUnitsRequirementTest
13 { 13 {
14 private MockRace mockRace; 14 private MockRace mockRace;
15 private UnitType unitType1; 15 private UnitType unitType1;
16 private UnitType unitType2; 16 private UnitType unitType2;
17 private UnitType unitType3;
17 18
18 [TestFixtureSetUp()] 19 [TestFixtureSetUp()]
19 public void SetupRace() 20 public void SetupRace()
20 { 21 {
21 mockRace = MockRace.GetMockRace(); 22 mockRace = MockRace.GetMockRace();
22 unitType1 = new MockUnitType("type1", "Unit Type 1"); 23 unitType1 = new MockUnitType("type1", "Unit Type 1");
23 mockRace.AddUnitType(unitType1); 24 mockRace.AddUnitType(unitType1);
24 unitType2 = new MockUnitType("type2", "Unit Type 2"); 25 unitType2 = new MockUnitType("type2", "Unit Type 2");
25 mockRace.AddUnitType(unitType2); 26 mockRace.AddUnitType(unitType2);
27 unitType3 = new MockUnitType("type3", "Unit Type 3");
28 mockRace.AddUnitType(unitType3);
26 } 29 }
27 30
28 [Test()] 31 [Test()]
29 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() 32 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
30 { 33 {
59 AddUnitOfTypeToArmy(unitType2, army); 62 AddUnitOfTypeToArmy(unitType2, army);
60 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2); 63 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
61 Assert.That(req.AllowsAdding(unitType1, army), Is.True); 64 Assert.That(req.AllowsAdding(unitType1, army), Is.True);
62 } 65 }
63 66
67 [Test()]
68 public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
69 {
70 Army army = new Army(mockRace, "Test", 1000);
71 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
72 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
73 }
74
75 [Test()]
76 public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
77 {
78 Army army = new Army(mockRace, "Test", 1000);
79 AddUnitOfTypeToArmy(unitType2, army);
80 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
81 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
82 }
83
84 [Test()]
85 public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
86 {
87 Army army = new Army(mockRace, "Test", 1000);
88 AddUnitOfTypeToArmy(unitType2, army);
89 AddUnitOfTypeToArmy(unitType3, army);
90 UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
91 Assert.That(req.AllowsAdding(unitType1, army), Is.True);
92 }
93
64 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) 94 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
65 { 95 {
66 army.AddUnit(CreateUnitOfType(unitType, army)); 96 army.AddUnit(CreateUnitOfType(unitType, army));
67 } 97 }
68 98