Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs @ 197:aa921248ffbf
Re #350: Add requirement to allow N of unit for specific other units
* Add initial unit tests for handling multiple additive unit types
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 07 Dec 2011 21:02:13 +0000 |
parents | 8e95ccb8e9d5 |
children | 6a54d1787fbe |
comparison
equal
deleted
inserted
replaced
196:498396c77601 | 197:aa921248ffbf |
---|---|
16 { | 16 { |
17 private MockRace mockRace; | 17 private MockRace mockRace; |
18 private UnitType unitType1; | 18 private UnitType unitType1; |
19 private UnitType unitType2; | 19 private UnitType unitType2; |
20 private UnitType unitType3; | 20 private UnitType unitType3; |
21 private UnitType unitType4; | |
21 | 22 |
22 [TestFixtureSetUp()] | 23 [TestFixtureSetUp()] |
23 public void SetupRace() | 24 public void SetupRace() |
24 { | 25 { |
25 mockRace = MockRace.GetMockRace(); | 26 mockRace = MockRace.GetMockRace(); |
27 mockRace.AddUnitType(unitType1); | 28 mockRace.AddUnitType(unitType1); |
28 unitType2 = new MockUnitType("type2", "Unit Type 2"); | 29 unitType2 = new MockUnitType("type2", "Unit Type 2"); |
29 mockRace.AddUnitType(unitType2); | 30 mockRace.AddUnitType(unitType2); |
30 unitType3 = new MockUnitType("type3", "Unit Type 3"); | 31 unitType3 = new MockUnitType("type3", "Unit Type 3"); |
31 mockRace.AddUnitType(unitType3); | 32 mockRace.AddUnitType(unitType3); |
33 unitType4 = new MockUnitType("type4", "Unit Type 4"); | |
34 mockRace.AddUnitType(unitType4); | |
32 } | 35 } |
33 | 36 |
34 [Test()] | 37 [Test()] |
35 public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequiredIsNA() | 38 public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequiredIsNA() |
36 { | 39 { |
153 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | 156 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); |
154 req.AddUnitTypeRequirement(unitType2, 1, 2); | 157 req.AddUnitTypeRequirement(unitType2, 1, 2); |
155 Unit unit = CreateUnitOfType(unitType1, army); | 158 Unit unit = CreateUnitOfType(unitType1, army); |
156 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | 159 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); |
157 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (would have 1 for 3).")); | 160 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (would have 1 for 3).")); |
161 } | |
162 | |
163 [Test()] | |
164 public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA() | |
165 { | |
166 Army army = new Army(mockRace, "Test", 1000); | |
167 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
168 req.AddUnitTypeRequirement(unitType2, unitType3); | |
169 Unit unit = CreateUnitOfType(unitType4, army); | |
170 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); | |
171 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
172 } | |
173 | |
174 [Test()] | |
175 public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() | |
176 { | |
177 Army army = new Army(mockRace, "Test", 1000); | |
178 AddUnitOfTypeToArmy(unitType2, army); | |
179 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
180 req.AddUnitTypeRequirement(unitType2, unitType3); | |
181 Unit unit = CreateUnitOfType(unitType1, army); | |
182 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
183 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
184 } | |
185 | |
186 [Test()] | |
187 public void TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() | |
188 { | |
189 Army army = new Army(mockRace, "Test", 1000); | |
190 AddUnitOfTypeToArmy(unitType3, army); | |
191 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
192 req.AddUnitTypeRequirement(unitType2, unitType3); | |
193 Unit unit = CreateUnitOfType(unitType1, army); | |
194 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
195 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
196 } | |
197 | |
198 [Test()] | |
199 public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() | |
200 { | |
201 Army army = new Army(mockRace, "Test", 1000); | |
202 AddUnitOfTypeToArmy(unitType3, army); | |
203 AddUnitOfTypeToArmy(unitType2, army); | |
204 AddUnitOfTypeToArmy(unitType1, army); | |
205 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
206 req.AddUnitTypeRequirement(unitType2, unitType3); | |
207 Unit unit = CreateUnitOfType(unitType1, army); | |
208 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
209 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
210 } | |
211 | |
212 [Test()] | |
213 public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() | |
214 { | |
215 Army army = new Army(mockRace, "Test", 1000); | |
216 AddUnitOfTypeToArmy(unitType3, army); | |
217 AddUnitOfTypeToArmy(unitType3, army); | |
218 AddUnitOfTypeToArmy(unitType1, army); | |
219 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
220 req.AddUnitTypeRequirement(unitType2, unitType3); | |
221 Unit unit = CreateUnitOfType(unitType1, army); | |
222 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
223 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
224 } | |
225 | |
226 [Test()] | |
227 public void TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() | |
228 { | |
229 Army army = new Army(mockRace, "Test", 1000); | |
230 AddUnitOfTypeToArmy(unitType2, army); | |
231 AddUnitOfTypeToArmy(unitType2, army); | |
232 AddUnitOfTypeToArmy(unitType1, army); | |
233 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
234 req.AddUnitTypeRequirement(unitType2, unitType3); | |
235 Unit unit = CreateUnitOfType(unitType1, army); | |
236 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); | |
237 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); | |
238 } | |
239 | |
240 [Test()] | |
241 public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() | |
242 { | |
243 Army army = new Army(mockRace, "Test", 1000); | |
244 AddUnitOfTypeToArmy(unitType3, army); | |
245 AddUnitOfTypeToArmy(unitType2, army); | |
246 AddUnitOfTypeToArmy(unitType1, army); | |
247 AddUnitOfTypeToArmy(unitType1, army); | |
248 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
249 req.AddUnitTypeRequirement(unitType2, unitType3); | |
250 Unit unit = CreateUnitOfType(unitType1, army); | |
251 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
252 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3).")); | |
253 } | |
254 | |
255 [Test()] | |
256 public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() | |
257 { | |
258 Army army = new Army(mockRace, "Test", 1000); | |
259 AddUnitOfTypeToArmy(unitType3, army); | |
260 AddUnitOfTypeToArmy(unitType3, army); | |
261 AddUnitOfTypeToArmy(unitType1, army); | |
262 AddUnitOfTypeToArmy(unitType1, army); | |
263 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
264 req.AddUnitTypeRequirement(unitType2, unitType3); | |
265 Unit unit = CreateUnitOfType(unitType1, army); | |
266 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
267 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3).")); | |
268 } | |
269 | |
270 [Test()] | |
271 public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() | |
272 { | |
273 Army army = new Army(mockRace, "Test", 1000); | |
274 AddUnitOfTypeToArmy(unitType2, army); | |
275 AddUnitOfTypeToArmy(unitType2, army); | |
276 AddUnitOfTypeToArmy(unitType1, army); | |
277 AddUnitOfTypeToArmy(unitType1, army); | |
278 RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); | |
279 req.AddUnitTypeRequirement(unitType2, unitType3); | |
280 Unit unit = CreateUnitOfType(unitType1, army); | |
281 Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); | |
282 Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 2 for 3).")); | |
158 } | 283 } |
159 | 284 |
160 [Test()] | 285 [Test()] |
161 public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() | 286 public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() |
162 { | 287 { |