Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
comparison API/Util/UnitEquipmentUtilTest.cs @ 26:e6bf9b5e1b94
Re #198: Add equipment slots
* Alter constructors of mock percentage unit equipment items for more flexibility
* Consolidate tests
* Add full set of tests for getting max percentage
* Add extra tests to handle different limits
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 28 Oct 2009 20:43:33 +0000 |
parents | d48e73488838 |
children | 0676f6a1ee9d |
comparison
equal
deleted
inserted
replaced
25:d48e73488838 | 26:e6bf9b5e1b94 |
---|---|
11 namespace IBBoard.WarFoundry.API.Util | 11 namespace IBBoard.WarFoundry.API.Util |
12 { | 12 { |
13 [TestFixture()] | 13 [TestFixture()] |
14 public class UnitEquipmentUtilTest | 14 public class UnitEquipmentUtilTest |
15 { | 15 { |
16 private const string SLOT_NAME = "slot"; | |
17 | |
16 [Test()] | 18 [Test()] |
17 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlot() | 19 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlot() |
18 { | 20 { |
21 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(4); | |
22 UnitType unitType = equip.EquipmentForUnit; | |
23 Unit unit = GetUnit (unitType); | |
24 Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
25 Assert.AreEqual(4, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
26 Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
27 } | |
28 | |
29 [Test()] | |
30 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlotWithDifferentMinLimit() | |
31 { | |
32 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1,4); | |
33 UnitType unitType = equip.EquipmentForUnit; | |
34 Unit unit = GetUnit (unitType); | |
35 Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
36 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
37 Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
38 } | |
39 | |
40 [Test()] | |
41 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlot() | |
42 { | |
19 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); | 43 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); |
20 UnitType unitType = equip.EquipmentForUnit; | 44 equip.SlotName = SLOT_NAME; |
21 Unit unit = GetUnit (unitType); | 45 UnitType unitType = equip.EquipmentForUnit; |
22 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | 46 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); |
23 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | 47 Unit unit = GetUnit(unitType); |
24 } | 48 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
25 | 49 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
26 [Test()] | 50 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
27 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlotWithDifferentMinLimit() | 51 } |
28 { | 52 |
29 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1,3); | 53 [Test()] |
30 UnitType unitType = equip.EquipmentForUnit; | 54 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithDifferentMinLimit() |
31 Unit unit = GetUnit (unitType); | 55 { |
32 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | 56 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); |
33 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | 57 equip.SlotName = SLOT_NAME; |
34 } | 58 UnitType unitType = equip.EquipmentForUnit; |
35 | 59 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); |
36 [Test()] | 60 Unit unit = GetUnit(unitType); |
37 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlot() | 61 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
62 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
63 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
64 } | |
65 | |
66 [Test()] | |
67 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithMaxBelowSlotLimit() | |
68 { | |
69 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); | |
70 equip.SlotName = SLOT_NAME; | |
71 UnitType unitType = equip.EquipmentForUnit; | |
72 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); | |
73 Unit unit = GetUnit(unitType); | |
74 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
75 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
76 Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
77 } | |
78 | |
79 [Test()] | |
80 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithMaxBelowSlotLimitWithDifferentMinLimit() | |
81 { | |
82 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); | |
83 equip.SlotName = SLOT_NAME; | |
84 UnitType unitType = equip.EquipmentForUnit; | |
85 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); | |
86 Unit unit = GetUnit(unitType); | |
87 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
88 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
89 Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
90 } | |
91 | |
92 [Test()] | |
93 public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlot() | |
94 { | |
95 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(10); | |
96 equip.SlotName = SLOT_NAME; | |
97 UnitType unitType = equip.EquipmentForUnit; | |
98 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, false)); | |
99 Unit unit = GetUnit(unitType); | |
100 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
101 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
102 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
103 } | |
104 | |
105 [Test()] | |
106 public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlotWithDifferentMinLimit() | |
107 { | |
108 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5, 10); | |
109 equip.SlotName = SLOT_NAME; | |
110 UnitType unitType = equip.EquipmentForUnit; | |
111 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, false)); | |
112 Unit unit = GetUnit(unitType); | |
113 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
114 Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
115 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
116 } | |
117 | |
118 [Test()] | |
119 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() | |
120 { | |
121 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); | |
122 equip.SlotName = SLOT_NAME; | |
123 UnitType unitType = equip.EquipmentForUnit; | |
124 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(6)); | |
125 Unit unit =GetUnit(unitType); | |
126 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
127 equip2.SlotName = SLOT_NAME; | |
128 unit.SetEquipmentAmount(equip2, 5); | |
129 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
130 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
131 Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
132 } | |
133 | |
134 [Test()] | |
135 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipmentDifferentMinLimit() | |
136 { | |
137 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); | |
138 equip.SlotName = SLOT_NAME; | |
139 UnitType unitType = equip.EquipmentForUnit; | |
140 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(7)); | |
141 Unit unit =GetUnit(unitType); | |
142 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
143 equip2.SlotName = SLOT_NAME; | |
144 unit.SetEquipmentAmount(equip2, 5); | |
145 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
146 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
147 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
148 } | |
149 | |
150 [Test()] | |
151 public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlot() | |
152 { | |
153 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
154 UnitType unitType = equip.EquipmentForUnit; | |
155 Unit unit = GetUnit(unitType); | |
156 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
157 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
158 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
159 } | |
160 | |
161 [Test()] | |
162 public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlotWithDifferentMinLimit() | |
163 { | |
164 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(25, 50); | |
165 UnitType unitType = equip.EquipmentForUnit; | |
166 Unit unit = GetUnit(unitType); | |
167 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
168 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
169 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
170 } | |
171 | |
172 [Test()] | |
173 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlot() | |
174 { | |
175 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
176 equip.SlotName = SLOT_NAME; | |
177 UnitType unitType = equip.EquipmentForUnit; | |
178 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); | |
179 Unit unit = GetUnit(unitType); | |
180 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
181 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
182 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
183 } | |
184 | |
185 [Test()] | |
186 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithDifferentMinLimit() | |
187 { | |
188 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
189 equip.SlotName = SLOT_NAME; | |
190 UnitType unitType = equip.EquipmentForUnit; | |
191 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); | |
192 Unit unit = GetUnit(unitType); | |
193 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
194 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
195 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
196 } | |
197 | |
198 [Test()] | |
199 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlot() | |
200 { | |
201 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
202 equip.SlotName = SLOT_NAME; | |
203 UnitType unitType = equip.EquipmentForUnit; | |
204 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(25, false)); | |
205 Unit unit = GetUnit(unitType); | |
206 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
207 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
208 Assert.AreEqual(25, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
209 } | |
210 | |
211 [Test()] | |
212 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithDifferentMinLimit() | |
213 { | |
214 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
215 equip.SlotName = SLOT_NAME; | |
216 UnitType unitType = equip.EquipmentForUnit; | |
217 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(25, false)); | |
218 Unit unit = GetUnit(unitType); | |
219 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
220 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
221 Assert.AreEqual(25, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
222 } | |
223 | |
224 [Test()] | |
225 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithMaxBelowSlotLimit() | |
226 { | |
227 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
228 equip.SlotName = SLOT_NAME; | |
229 UnitType unitType = equip.EquipmentForUnit; | |
230 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(75, false)); | |
231 Unit unit = GetUnit(unitType); | |
232 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
233 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
234 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
235 } | |
236 | |
237 [Test()] | |
238 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithMaxBelowSlotLimitWithDifferentMinLimit() | |
239 { | |
240 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(25, 50); | |
241 equip.SlotName = SLOT_NAME; | |
242 UnitType unitType = equip.EquipmentForUnit; | |
243 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(75, false)); | |
244 Unit unit = GetUnit(unitType); | |
245 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
246 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
247 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
248 } | |
249 | |
250 [Test()] | |
251 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() | |
252 { | |
253 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
254 equip.SlotName = SLOT_NAME; | |
255 UnitType unitType = equip.EquipmentForUnit; | |
256 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(7)); | |
257 Unit unit = GetUnit(unitType); | |
258 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
259 equip2.SlotName = SLOT_NAME; | |
260 unit.SetEquipmentAmount(equip2, 5); | |
261 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
262 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
263 Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
264 } | |
265 | |
266 [Test()] | |
267 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipment() | |
268 { | |
269 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
270 equip.SlotName = SLOT_NAME; | |
271 UnitType unitType = equip.EquipmentForUnit; | |
272 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); | |
273 Unit unit = GetUnit(unitType); | |
274 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
275 equip2.SlotName = SLOT_NAME; | |
276 unit.SetEquipmentAmount(equip2, 5); | |
277 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
278 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
279 Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
280 } | |
281 | |
282 [Test()] | |
283 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipmentWithDifferentMinimum() | |
284 { | |
285 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
286 equip.SlotName = SLOT_NAME; | |
287 UnitType unitType = equip.EquipmentForUnit; | |
288 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); | |
289 Unit unit = GetUnit(unitType); | |
290 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
291 equip2.SlotName = SLOT_NAME; | |
292 unit.SetEquipmentAmount(equip2, 5); | |
293 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
294 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
295 Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
296 } | |
297 | |
298 [Test()] | |
299 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndUnlimitedSlot() | |
300 { | |
301 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
302 equip.SlotName = SLOT_NAME; | |
303 UnitType unitType = equip.EquipmentForUnit; | |
304 unitType.AddEquipmentSlot(SLOT_NAME, new UnlimitedLimit()); | |
305 Unit unit = GetUnit(unitType); | |
306 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
307 } | |
308 | |
309 [Test()] | |
310 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndRatioSlot() | |
311 { | |
312 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
313 equip.SlotName = SLOT_NAME; | |
314 UnitType unitType = equip.EquipmentForUnit; | |
315 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); | |
316 Unit unit = GetUnit(unitType); | |
317 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
318 } | |
319 | |
320 [Test()] | |
321 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndAbsoluteSlot() | |
322 { | |
323 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
324 equip.SlotName = SLOT_NAME; | |
325 UnitType unitType = equip.EquipmentForUnit; | |
326 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); | |
327 Unit unit = GetUnit(unitType); | |
328 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
329 } | |
330 | |
331 [Test()] | |
332 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndAbsoluteSlot() | |
38 { | 333 { |
39 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | 334 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
40 equip.MaxLimit = new NumericSizeConstrainedLimit(3); | 335 equip.SlotName = SLOT_NAME; |
41 equip.SlotName = "slot"; | 336 UnitType unitType = equip.EquipmentForUnit; |
42 UnitType unitType = equip.EquipmentForUnit; | 337 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); |
43 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); | 338 Unit unit = GetUnit(unitType); |
44 Unit unit = GetUnit(unitType); | 339 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); |
45 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | 340 } |
46 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | 341 |
47 } | 342 [Test()] |
48 | 343 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndUnlimitedSlot() |
49 [Test()] | |
50 public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlot() | |
51 { | 344 { |
52 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | 345 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
53 equip.MaxLimit = new NumericSizeConstrainedLimit(7); | 346 equip.SlotName = SLOT_NAME; |
54 equip.SlotName = "slot"; | 347 UnitType unitType = equip.EquipmentForUnit; |
55 UnitType unitType = equip.EquipmentForUnit; | 348 unitType.AddEquipmentSlot(SLOT_NAME, new UnlimitedLimit()); |
56 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, false)); | 349 Unit unit = GetUnit(unitType); |
57 Unit unit = GetUnit(unitType); | 350 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); |
58 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | 351 } |
59 Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | 352 |
60 } | 353 [Test()] |
61 | 354 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndRatioSlot() |
62 [Test()] | |
63 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() | |
64 { | 355 { |
65 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | 356 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
66 equip.MaxLimit = new NumericSizeConstrainedLimit(3); | 357 equip.SlotName = SLOT_NAME; |
67 equip.SlotName = "slot"; | 358 UnitType unitType = equip.EquipmentForUnit; |
68 UnitType unitType = equip.EquipmentForUnit; | 359 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); |
69 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6)); | |
70 Unit unit =GetUnit(unitType); | |
71 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
72 equip2.SlotName = "slot"; | |
73 unit.SetEquipmentAmount(equip2, 5); | |
74 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
75 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
76 } | |
77 | |
78 [Test()] | |
79 public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlot() | |
80 { | |
81 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
82 UnitType unitType = equip.EquipmentForUnit; | |
83 Unit unit = GetUnit(unitType); | |
84 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
85 Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
86 } | |
87 | |
88 [Test()] | |
89 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlot() | |
90 { | |
91 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
92 equip.SlotName = "slot"; | |
93 UnitType unitType = equip.EquipmentForUnit; | |
94 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); | |
95 Unit unit = GetUnit(unitType); | |
96 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
97 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
98 } | |
99 | |
100 [Test()] | |
101 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlot() | |
102 { | |
103 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
104 equip.SlotName = "slot"; | |
105 UnitType unitType = equip.EquipmentForUnit; | |
106 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(25, false)); | |
107 Unit unit = GetUnit(unitType); | |
108 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
109 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
110 } | |
111 | |
112 [Test()] | |
113 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() | |
114 { | |
115 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
116 equip.SlotName = "slot"; | |
117 UnitType unitType = equip.EquipmentForUnit; | |
118 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6)); | |
119 Unit unit = GetUnit(unitType); | |
120 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
121 equip2.SlotName = "slot"; | |
122 unit.SetEquipmentAmount(equip2, 5); | |
123 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
124 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
125 } | |
126 | |
127 [Test()] | |
128 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndUnlimitedSlot() | |
129 { | |
130 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
131 equip.SlotName = "slot"; | |
132 UnitType unitType = equip.EquipmentForUnit; | |
133 unitType.AddEquipmentSlot("slot", new UnlimitedLimit()); | |
134 Unit unit = GetUnit(unitType); | |
135 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
136 } | |
137 | |
138 [Test()] | |
139 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndRatioSlot() | |
140 { | |
141 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
142 equip.SlotName = "slot"; | |
143 UnitType unitType = equip.EquipmentForUnit; | |
144 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, true)); | |
145 Unit unit = GetUnit(unitType); | |
146 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
147 } | |
148 | |
149 [Test()] | |
150 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndAbsoluteSlot() | |
151 { | |
152 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
153 equip.SlotName = "slot"; | |
154 UnitType unitType = equip.EquipmentForUnit; | |
155 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(5)); | |
156 Unit unit = GetUnit(unitType); | 360 Unit unit = GetUnit(unitType); |
157 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | 361 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); |
158 } | 362 } |
159 | 363 |
160 [Test()] | |
161 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndAbsoluteSlot() | |
162 { | |
163 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | |
164 equip.SlotName = "slot"; | |
165 UnitType unitType = equip.EquipmentForUnit; | |
166 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(5)); | |
167 Unit unit = GetUnit(unitType); | |
168 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
169 } | |
170 | |
171 [Test()] | |
172 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndUnlimitedSlot() | |
173 { | |
174 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | |
175 equip.SlotName = "slot"; | |
176 UnitType unitType = equip.EquipmentForUnit; | |
177 unitType.AddEquipmentSlot("slot", new UnlimitedLimit()); | |
178 Unit unit = GetUnit(unitType); | |
179 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
180 } | |
181 | |
182 [Test()] | |
183 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndRatioSlot() | |
184 { | |
185 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); | |
186 equip.SlotName = "slot"; | |
187 UnitType unitType = equip.EquipmentForUnit; | |
188 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, true)); | |
189 Unit unit = GetUnit(unitType); | |
190 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
191 } | |
192 | |
193 [Test()] | |
194 public void TestGetMaxPercentageForPercentageLimitedEquipmentOnUnlimitedSlot() | |
195 { | |
196 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(75); | |
197 UnitType unitType = equip.EquipmentForUnit; | |
198 Unit unit = GetUnit(unitType); | |
199 Assert.AreEqual(75, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
200 } | |
201 | |
202 [Test()] | |
203 public void TestGetMaxPercentageForNumericLimitedEquipmentOnUnlimitedSlot() | |
204 { | |
205 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); | |
206 UnitType unitType = equip.EquipmentForUnit; | |
207 Unit unit = GetUnit(unitType); | |
208 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
209 } | |
210 | |
211 private Unit GetUnit (UnitType unitType) | 364 private Unit GetUnit (UnitType unitType) |
212 { | 365 { |
213 return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory)); | 366 return new Unit ("unit", "Test Unit", 15, unitType, new MockArmyCategory (unitType.MainCategory)); |
214 } | 367 } |
215 } | 368 } |
216 } | 369 } |