comparison API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs @ 209:fc9a90d29ae0

Re #379: Fix validation of requirements to check for unit * Fix some of the copy-and-paste errors in the tests - some tests still fail
author IBBoard <dev@ibboard.co.uk>
date Wed, 22 Feb 2012 21:00:01 +0000
parents c323770e61c2
children 649759343da5
comparison
equal deleted inserted replaced
208:c323770e61c2 209:fc9a90d29ae0
91 91
92 [Test()] 92 [Test()]
93 public void TestAddingUnitTriggersFailure() 93 public void TestAddingUnitTriggersFailure()
94 { 94 {
95 Army army = new Army(mockRace, "Test", 1000); 95 Army army = new Army(mockRace, "Test", 1000);
96 AddUnitOfTypeToArmy(unitType2, army); 96 AddUnitOfTypeToArmy(unitType1, army);
97 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 97 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
98 req.AddUnitTypeRequirement(unitType2, 1); 98 req.AddUnitTypeRequirement(unitType2, 1);
99 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); 99 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
100 AddUnitOfTypeToArmy(unitType2, army); 100 AddUnitOfTypeToArmy(unitType2, army);
101 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); 101 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
102 } 102 }
103 103
104 [Test()] 104 [Test()]
105 public void TestAddingUnitTypeDefaultsToNoMoreThanZero() 105 public void TestAddingUnitTypeDefaultsToOne()
106 { 106 {
107 Army army = new Army(mockRace, "Test", 1000); 107 Army army = new Army(mockRace, "Test", 1000);
108 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 108 AddUnitOfTypeToArmy(unitType1, army);
109 req.AddUnitTypeRequirement(unitType2); 109 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
110 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); 110 req.AddUnitTypeRequirement(unitType2);
111 AddUnitOfTypeToArmy(unitType2, army); 111 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
112 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); 112 AddUnitOfTypeToArmy(unitType2, army);
113 Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
113 } 114 }
114 115
115 [Test] 116 [Test]
116 public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded() 117 public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded()
117 { 118 {
139 { 140 {
140 Army army = new Army(mockRace, "Test", 1000); 141 Army army = new Army(mockRace, "Test", 1000);
141 AddUnitOfTypeToArmy(unitType1, army); 142 AddUnitOfTypeToArmy(unitType1, army);
142 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 143 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
143 req.AddUnitTypeRequirement(unitType2); 144 req.AddUnitTypeRequirement(unitType2);
144 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); 145 Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
145 } 146 }
146 147
147 [Test] 148 [Test]
148 public void TestValidationMessageIsBlankForPass() 149 public void TestValidationMessageIsBlankForPass()
149 { 150 {
159 Army army = new Army(mockRace, "Test", 1000); 160 Army army = new Army(mockRace, "Test", 1000);
160 AddUnitOfTypeToArmy(unitType1, army); 161 AddUnitOfTypeToArmy(unitType1, army);
161 AddUnitOfTypeToArmy(unitType2, army); 162 AddUnitOfTypeToArmy(unitType2, army);
162 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 163 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
163 req.AddUnitTypeRequirement(unitType2); 164 req.AddUnitTypeRequirement(unitType2);
164 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); 165 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 0 × " + unitType2.Name + " for every " + unitType1.Name + " (have 1)."));
165 } 166 }
166 167
167 [Test] 168 [Test]
168 public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit() 169 public void TestValidationMessageIsCorrectForFailWithTwoOfOneUnitLimit()
169 { 170 {
172 AddUnitOfTypeToArmy(unitType2, army); 173 AddUnitOfTypeToArmy(unitType2, army);
173 AddUnitOfTypeToArmy(unitType2, army); 174 AddUnitOfTypeToArmy(unitType2, army);
174 AddUnitOfTypeToArmy(unitType2, army); 175 AddUnitOfTypeToArmy(unitType2, army);
175 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 176 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
176 req.AddUnitTypeRequirement(unitType2, 2); 177 req.AddUnitTypeRequirement(unitType2, 2);
177 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (have 3).")); 178 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every " + unitType1.Name + " (have 3)."));
178 } 179 }
179 180
180 [Test] 181 [Test]
181 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited() 182 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibited()
182 { 183 {
184 AddUnitOfTypeToArmy(unitType1, army); 185 AddUnitOfTypeToArmy(unitType1, army);
185 AddUnitOfTypeToArmy(unitType2, army); 186 AddUnitOfTypeToArmy(unitType2, army);
186 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 187 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
187 req.AddUnitTypeRequirement(unitType2); 188 req.AddUnitTypeRequirement(unitType2);
188 req.AddUnitTypeRequirement(unitType3); 189 req.AddUnitTypeRequirement(unitType3);
189 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1).")); 190 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."));
190 } 191 }
191 192
192 [Test] 193 [Test]
193 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() 194 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
194 { 195 {
196 AddUnitOfTypeToArmy(unitType1, army); 197 AddUnitOfTypeToArmy(unitType1, army);
197 AddUnitOfTypeToArmy(unitType3, army); 198 AddUnitOfTypeToArmy(unitType3, army);
198 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 199 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
199 req.AddUnitTypeRequirement(unitType2); 200 req.AddUnitTypeRequirement(unitType2);
200 req.AddUnitTypeRequirement(unitType3); 201 req.AddUnitTypeRequirement(unitType3);
201 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType3.Name + " (have 1).")); 202 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."));
202 } 203 }
203 204
204 [Test] 205 [Test]
205 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy() 206 public void TestValidationMessageIsCorrectForFailWithTwoUnitsProhibitedAndBothUnitsInArmy()
206 { 207 {
209 AddUnitOfTypeToArmy(unitType2, army); 210 AddUnitOfTypeToArmy(unitType2, army);
210 AddUnitOfTypeToArmy(unitType3, army); 211 AddUnitOfTypeToArmy(unitType3, army);
211 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 212 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
212 req.AddUnitTypeRequirement(unitType2); 213 req.AddUnitTypeRequirement(unitType2);
213 req.AddUnitTypeRequirement(unitType3); 214 req.AddUnitTypeRequirement(unitType3);
214 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1).")); 215 Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 0 × " + unitType2.Name + " for every " + unitType1.Name + " (have 1); 0 × " + unitType3.Name + " for every " + unitType1.Name + " (have 1)."));
215 } 216 }
216 217
217 [Test] 218 [Test]
218 public void TestAllowsAddMessageIsBlankForPass() 219 public void TestAllowsAddMessageIsBlankForPass()
219 { 220 {
228 { 229 {
229 Army army = new Army(mockRace, "Test", 1000); 230 Army army = new Army(mockRace, "Test", 1000);
230 AddUnitOfTypeToArmy(unitType1, army); 231 AddUnitOfTypeToArmy(unitType1, army);
231 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 232 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
232 req.AddUnitTypeRequirement(unitType2); 233 req.AddUnitTypeRequirement(unitType2);
233 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); 234 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 0 × " + unitType2.Name + " for every " + unitType1.Name + " (would have 1)."));
234 } 235 }
235 236
236 [Test] 237 [Test]
237 public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit() 238 public void TestAllowsAddMessageIsCorrectForFailWithTwoOfOneUnitLimit()
238 { 239 {
240 AddUnitOfTypeToArmy(unitType1, army); 241 AddUnitOfTypeToArmy(unitType1, army);
241 AddUnitOfTypeToArmy(unitType2, army); 242 AddUnitOfTypeToArmy(unitType2, army);
242 AddUnitOfTypeToArmy(unitType2, army); 243 AddUnitOfTypeToArmy(unitType2, army);
243 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 244 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
244 req.AddUnitTypeRequirement(unitType2, 2); 245 req.AddUnitTypeRequirement(unitType2, 2);
245 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 2 × " + unitType2.Name + " (would have 3).")); 246 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 2 × " + unitType2.Name + " for every " + unitType1.Name + " (would have 3)."));
246 } 247 }
247 248
248 [Test] 249 [Test]
249 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited() 250 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibited()
250 { 251 {
251 Army army = new Army(mockRace, "Test", 1000); 252 Army army = new Army(mockRace, "Test", 1000);
252 AddUnitOfTypeToArmy(unitType1, army); 253 AddUnitOfTypeToArmy(unitType1, army);
253 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 254 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
254 req.AddUnitTypeRequirement(unitType2); 255 req.AddUnitTypeRequirement(unitType2);
255 req.AddUnitTypeRequirement(unitType3); 256 req.AddUnitTypeRequirement(unitType3);
256 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1).")); 257 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 1 × " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."));
257 } 258 }
258 259
259 [Test] 260 [Test]
260 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy() 261 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOneUnitInArmy()
261 { 262 {
263 AddUnitOfTypeToArmy(unitType1, army); 264 AddUnitOfTypeToArmy(unitType1, army);
264 AddUnitOfTypeToArmy(unitType2, army); 265 AddUnitOfTypeToArmy(unitType2, army);
265 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 266 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
266 req.AddUnitTypeRequirement(unitType2); 267 req.AddUnitTypeRequirement(unitType2);
267 req.AddUnitTypeRequirement(unitType3); 268 req.AddUnitTypeRequirement(unitType3);
268 Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); 269 Assert.That(req.GetAllowsAddingMessage(unitType3, army), Is.EqualTo("Army must contain: 0 × " + unitType2.Name + " for every " + unitType1.Name + " (would have 1); 0 × " + unitType3.Name + " for every " + unitType1.Name + " (would have 1)."));
269 } 270 }
270 271
271 [Test] 272 [Test]
272 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy() 273 public void TestAllowsAddMessageIsCorrectForFailWithTwoUnitsProhibitedAndOtherUnitInArmy()
273 { 274 {
275 AddUnitOfTypeToArmy(unitType1, army); 276 AddUnitOfTypeToArmy(unitType1, army);
276 AddUnitOfTypeToArmy(unitType3, army); 277 AddUnitOfTypeToArmy(unitType3, army);
277 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); 278 UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1);
278 req.AddUnitTypeRequirement(unitType2); 279 req.AddUnitTypeRequirement(unitType2);
279 req.AddUnitTypeRequirement(unitType3); 280 req.AddUnitTypeRequirement(unitType3);
280 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1).")); 281 Assert.That(req.GetAllowsAddingMessage(unitType2, army), Is.EqualTo("Army must contain: 0 × " + unitType2.Name + " for every " + unitType1.Name + " (would have 1); 0 × " + unitType3.Name + " for every " + unitType1.Name + " (would have 1)."));
281 } 282 }
282 283
283 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) 284 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
284 { 285 {
285 army.AddUnit(CreateUnitOfType(unitType, army)); 286 army.AddUnit(CreateUnitOfType(unitType, army));