Mercurial > repos > IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/RequiresNoMoreThanNOfUnitTypeRequirementTest.cs @ 139:3e4864e206ea
Re #140: Equality methods
* Add equality testing to RequiresNoMoreThanN requirement
* Add extra different races for testing more of equality method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Apr 2011 19:47:36 +0000 |
parents | dd0ef8526a4e |
children | 2ae80631ec9c |
comparison
equal
deleted
inserted
replaced
138:11faab6c712a | 139:3e4864e206ea |
---|---|
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 System.Reflection; | |
9 using IBBoard.NUnit; | |
10 using IBBoard.WarFoundry.API.Factories; | |
8 | 11 |
9 namespace IBBoard.WarFoundry.API.Objects.Requirement | 12 namespace IBBoard.WarFoundry.API.Objects.Requirement |
10 { | 13 { |
11 [TestFixture()] | 14 [TestFixture()] |
12 public class RequiresNoMoreThanNOfUnitTypeRequirementTest | 15 public class RequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractEqualityTest<RequiresNoMoreThanNOfUnitTypeRequirement> |
13 { | 16 { |
17 //FIXME We shouldn't duplicate these tests, but it is broken at the moment | |
18 [Test] | |
19 public void TestEquality() | |
20 { | |
21 Assert.AreEqual(GetObject(), GetSameObject()); | |
22 Assert.AreEqual(GetSameObject(), GetObject()); | |
23 } | |
24 | |
25 [Test] | |
26 public void TestInequality() | |
27 { | |
28 Assert.AreNotEqual(GetObject(), GetDifferentObject()); | |
29 Assert.AreNotEqual(GetSameObject(), GetDifferentObject()); | |
30 Assert.AreNotEqual(GetDifferentObject(), GetObject()); | |
31 Assert.AreNotEqual(GetDifferentObject(), GetSameObject()); | |
32 } | |
33 | |
34 [Test] | |
35 public void TestReflexiveEquality() | |
36 { | |
37 Assert.AreEqual(GetObject(), GetObject()); | |
38 Assert.AreEqual(GetSameObject(), GetSameObject()); | |
39 Assert.AreEqual(GetDifferentObject(), GetDifferentObject()); | |
40 } | |
41 | |
42 [Test] | |
43 public void TestOtherInequality() | |
44 { | |
45 MethodInfo[] methodInfo = GetType().GetMethods(); | |
46 RequiresNoMoreThanNOfUnitTypeRequirement obj = GetObject(); | |
47 | |
48 foreach (MethodInfo method in methodInfo) | |
49 { | |
50 if (method.Name.StartsWith("GetOtherDifferent")) | |
51 { | |
52 RequiresAtLeastNUnitsRequirement otherObj = (RequiresAtLeastNUnitsRequirement)method.Invoke(this, new object[0]); | |
53 Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name); | |
54 Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name); | |
55 } | |
56 } | |
57 } | |
58 | |
59 | |
60 | |
61 | |
14 private MockRace mockRace; | 62 private MockRace mockRace; |
15 private UnitType unitType1; | 63 private UnitType unitType1; |
16 private UnitType unitType2; | 64 private UnitType unitType2; |
17 private UnitType unitType3; | 65 private UnitType unitType3; |
18 | 66 |
114 | 162 |
115 private static Unit CreateUnitOfType(UnitType unitType, Army army) | 163 private static Unit CreateUnitOfType(UnitType unitType, Army army) |
116 { | 164 { |
117 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); | 165 return new Unit(unitType, army.GetCategory(unitType.MainCategory)); |
118 } | 166 } |
167 | |
168 public override RequiresNoMoreThanNOfUnitTypeRequirement GetObject () | |
169 { | |
170 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); | |
171 req.AddUnitTypeRequirement(unitType1, 2); | |
172 return req; | |
173 } | |
174 | |
175 public override RequiresNoMoreThanNOfUnitTypeRequirement GetSameObject () | |
176 { | |
177 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); | |
178 req.AddUnitTypeRequirement(unitType1, 2); | |
179 return req; | |
180 } | |
181 | |
182 public override RequiresNoMoreThanNOfUnitTypeRequirement GetDifferentObject () | |
183 { | |
184 RequiresNoMoreThanNOfUnitTypeRequirement req = new RequiresNoMoreThanNOfUnitTypeRequirement(); | |
185 DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); | |
186 GameSystem gameSystem = new GameSystem("system", "system", factory); | |
187 Race race = new Race("race", "race", gameSystem, factory); | |
188 req.AddUnitTypeRequirement(new UnitType("id2", "Type 2", race), 2); | |
189 return req; | |
190 } | |
119 } | 191 } |
120 } | 192 } |
121 | 193 |