Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Util/UnitEquipmentUtilTest.cs @ 172:c026c02583ca
* Remove MockArmy.GetMockArmy as it only causes problems in unit tests
* Remove MockArmyCategory as MockArmy change would make it do nothing special
* Close streams as well as files to fix Windows unit test errors
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Sep 2011 11:46:20 +0100 |
parents | 9bf542b76de2 |
children | bd38c32fb1a9 |
rev | line source |
---|---|
18 | 1 // This file (UnitEquipmentItemUtilTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard |
2 // | |
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 | |
5 using System; | |
6 using NUnit.Framework; | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
7 using IBBoard.CustomMath; |
18 | 8 using IBBoard.Limits; |
9 using IBBoard.WarFoundry.API.Objects; | |
10 using IBBoard.WarFoundry.API.Objects.Mock; | |
11 | |
12 namespace IBBoard.WarFoundry.API.Util | |
13 { | |
14 [TestFixture()] | |
15 public class UnitEquipmentUtilTest | |
16 { | |
26 | 17 private const string SLOT_NAME = "slot"; |
18 | |
18 | 19 [Test()] |
24 | 20 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlot() |
18 | 21 { |
26 | 22 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(4); |
18 | 23 UnitType unitType = equip.EquipmentForUnit; |
19 | 24 Unit unit = GetUnit (unitType); |
26 | 25 Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
26 Assert.AreEqual(4, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
27 Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
28 Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
18 | 29 } |
30 | |
31 [Test()] | |
24 | 32 public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlotWithDifferentMinLimit() |
33 { | |
26 | 34 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1,4); |
24 | 35 UnitType unitType = equip.EquipmentForUnit; |
36 Unit unit = GetUnit (unitType); | |
26 | 37 Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
24 | 38 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
39 Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
40 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
24 | 41 } |
42 | |
43 [Test()] | |
44 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlot() | |
18 | 45 { |
26 | 46 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); |
47 equip.SlotName = SLOT_NAME; | |
18 | 48 UnitType unitType = equip.EquipmentForUnit; |
26 | 49 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); |
19 | 50 Unit unit = GetUnit(unitType); |
18 | 51 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
24 | 52 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
53 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
54 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 55 } |
56 | |
57 [Test()] | |
58 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithDifferentMinLimit() | |
59 { | |
60 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); | |
61 equip.SlotName = SLOT_NAME; | |
62 UnitType unitType = equip.EquipmentForUnit; | |
63 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); | |
64 Unit unit = GetUnit(unitType); | |
65 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
66 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
67 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
68 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 69 } |
70 | |
71 [Test()] | |
72 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithMaxBelowSlotLimit() | |
73 { | |
74 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); | |
75 equip.SlotName = SLOT_NAME; | |
76 UnitType unitType = equip.EquipmentForUnit; | |
77 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); | |
78 Unit unit = GetUnit(unitType); | |
79 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
80 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
81 Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
82 Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
18 | 83 } |
19 | 84 |
85 [Test()] | |
26 | 86 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithMaxBelowSlotLimitWithDifferentMinLimit() |
87 { | |
88 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); | |
89 equip.SlotName = SLOT_NAME; | |
90 UnitType unitType = equip.EquipmentForUnit; | |
91 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); | |
92 Unit unit = GetUnit(unitType); | |
93 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
94 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
95 Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
96 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 97 } |
98 | |
99 [Test()] | |
24 | 100 public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlot() |
19 | 101 { |
26 | 102 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(10); |
103 equip.SlotName = SLOT_NAME; | |
19 | 104 UnitType unitType = equip.EquipmentForUnit; |
26 | 105 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, false)); |
19 | 106 Unit unit = GetUnit(unitType); |
26 | 107 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
108 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
109 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
110 Assert.AreEqual(50, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 111 } |
112 | |
113 [Test()] | |
114 public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlotWithDifferentMinLimit() | |
115 { | |
116 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5, 10); | |
117 equip.SlotName = SLOT_NAME; | |
118 UnitType unitType = equip.EquipmentForUnit; | |
119 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, false)); | |
120 Unit unit = GetUnit(unitType); | |
121 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
24 | 122 Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
26 | 123 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
124 Assert.AreEqual(IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
19 | 125 } |
126 | |
127 [Test()] | |
24 | 128 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() |
19 | 129 { |
26 | 130 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); |
131 equip.SlotName = SLOT_NAME; | |
19 | 132 UnitType unitType = equip.EquipmentForUnit; |
26 | 133 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(6)); |
19 | 134 Unit unit =GetUnit(unitType); |
135 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
26 | 136 equip2.SlotName = SLOT_NAME; |
19 | 137 unit.SetEquipmentAmount(equip2, 5); |
138 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
24 | 139 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
140 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
141 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
142 } |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
143 |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
144 [Test()] |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
145 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType() |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
146 { |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
147 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
148 equip.SlotName = SLOT_NAME; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
149 UnitType unitType = equip.EquipmentForUnit; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
150 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(3)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
151 Unit unit =GetUnit(unitType); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
152 unit.SetEquipmentAmount(equip, 2); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
153 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
154 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
155 Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
156 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 157 } |
158 | |
159 [Test()] | |
160 public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipmentDifferentMinLimit() | |
161 { | |
162 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); | |
163 equip.SlotName = SLOT_NAME; | |
164 UnitType unitType = equip.EquipmentForUnit; | |
165 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(7)); | |
166 Unit unit =GetUnit(unitType); | |
167 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
168 equip2.SlotName = SLOT_NAME; | |
169 unit.SetEquipmentAmount(equip2, 5); | |
170 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
171 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
172 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
173 Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
19 | 174 } |
175 | |
176 [Test()] | |
24 | 177 public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlot() |
19 | 178 { |
26 | 179 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); |
19 | 180 UnitType unitType = equip.EquipmentForUnit; |
181 Unit unit = GetUnit(unitType); | |
26 | 182 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
183 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
184 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
185 Assert.AreEqual(50, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 186 } |
187 | |
188 [Test()] | |
189 public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlotWithDifferentMinLimit() | |
190 { | |
191 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(25, 50); | |
192 UnitType unitType = equip.EquipmentForUnit; | |
193 Unit unit = GetUnit(unitType); | |
194 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
195 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
196 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
197 Assert.AreEqual(25, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
19 | 198 } |
199 | |
200 [Test()] | |
24 | 201 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlot() |
19 | 202 { |
26 | 203 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); |
204 equip.SlotName = SLOT_NAME; | |
19 | 205 UnitType unitType = equip.EquipmentForUnit; |
26 | 206 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); |
19 | 207 Unit unit = GetUnit(unitType); |
208 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
24 | 209 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
210 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
30 | 211 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 212 } |
213 | |
214 [Test()] | |
215 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithDifferentMinLimit() | |
216 { | |
217 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
218 equip.SlotName = SLOT_NAME; | |
219 UnitType unitType = equip.EquipmentForUnit; | |
220 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(2)); | |
221 Unit unit = GetUnit(unitType); | |
222 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
223 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
224 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
225 Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
19 | 226 } |
227 | |
228 [Test()] | |
24 | 229 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlot() |
19 | 230 { |
26 | 231 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); |
232 equip.SlotName = SLOT_NAME; | |
233 UnitType unitType = equip.EquipmentForUnit; | |
234 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(25, false)); | |
235 Unit unit = GetUnit(unitType); | |
236 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
237 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
238 Assert.AreEqual(25, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
239 Assert.AreEqual(25, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 240 } |
241 | |
242 [Test()] | |
243 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithDifferentMinLimit() | |
244 { | |
245 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
246 equip.SlotName = SLOT_NAME; | |
19 | 247 UnitType unitType = equip.EquipmentForUnit; |
26 | 248 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(25, false)); |
249 Unit unit = GetUnit(unitType); | |
250 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
251 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
252 Assert.AreEqual(25, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
253 Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 254 } |
255 | |
256 [Test()] | |
257 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithMaxBelowSlotLimit() | |
258 { | |
259 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
260 equip.SlotName = SLOT_NAME; | |
261 UnitType unitType = equip.EquipmentForUnit; | |
262 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(75, false)); | |
19 | 263 Unit unit = GetUnit(unitType); |
26 | 264 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
265 Assert.AreEqual(7, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
266 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
267 Assert.AreEqual(50, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 268 } |
269 | |
270 [Test()] | |
271 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithMaxBelowSlotLimitWithDifferentMinLimit() | |
272 { | |
273 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(25, 50); | |
274 equip.SlotName = SLOT_NAME; | |
275 UnitType unitType = equip.EquipmentForUnit; | |
276 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(75, false)); | |
277 Unit unit = GetUnit(unitType); | |
278 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
279 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
280 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); | |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
281 Assert.AreEqual(25, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
19 | 282 } |
283 | |
284 [Test()] | |
24 | 285 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() |
19 | 286 { |
26 | 287 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); |
288 equip.SlotName = SLOT_NAME; | |
19 | 289 UnitType unitType = equip.EquipmentForUnit; |
26 | 290 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(7)); |
291 Unit unit = GetUnit(unitType); | |
292 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
293 equip2.SlotName = SLOT_NAME; | |
294 unit.SetEquipmentAmount(equip2, 5); | |
295 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
296 Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
297 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
298 Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
299 } |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
300 |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
301 [Test()] |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
302 public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType() |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
303 { |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
304 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
305 equip.SlotName = SLOT_NAME; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
306 UnitType unitType = equip.EquipmentForUnit; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
307 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(10)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
308 Unit unit = GetUnit(unitType); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
309 unit.SetEquipmentAmount(equip, 5); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
310 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
311 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
312 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
313 Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 314 } |
315 | |
316 [Test()] | |
317 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipment() | |
318 { | |
319 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(50); | |
320 equip.SlotName = SLOT_NAME; | |
321 UnitType unitType = equip.EquipmentForUnit; | |
322 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); | |
19 | 323 Unit unit = GetUnit(unitType); |
324 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
26 | 325 equip2.SlotName = SLOT_NAME; |
19 | 326 unit.SetEquipmentAmount(equip2, 5); |
26 | 327 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
328 Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); | |
32
9bf542b76de2
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
329 Assert.AreEqual(50 - IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
30 | 330 Assert.AreEqual(50 - IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
29
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
331 } |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
332 |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
333 [Test()] |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
334 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipmentOfSameType() |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
335 { |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
336 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
337 equip.SlotName = SLOT_NAME; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
338 UnitType unitType = equip.EquipmentForUnit; |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
339 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
340 Unit unit = GetUnit(unitType); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
341 unit.SetEquipmentAmount(equip, 5); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
342 Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
343 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
29e81f10bb8b
Re #208: equipmentslot limit issues
IBBoard <dev@ibboard.co.uk>
parents:
27
diff
changeset
|
344 Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
345 Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
26 | 346 } |
347 | |
348 [Test()] | |
349 public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipmentWithDifferentMinimum() | |
350 { | |
351 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); | |
352 equip.SlotName = SLOT_NAME; | |
353 UnitType unitType = equip.EquipmentForUnit; | |
354 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); | |
355 Unit unit = GetUnit(unitType); | |
356 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); | |
357 equip2.SlotName = SLOT_NAME; | |
358 unit.SetEquipmentAmount(equip2, 5); | |
359 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); | |
21 | 360 Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); |
32
9bf542b76de2
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
31
diff
changeset
|
361 Assert.AreEqual(50 - IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); |
31
c6082e4018f7
Re #209: equipmentslot Value problem
IBBoard <dev@ibboard.co.uk>
parents:
30
diff
changeset
|
362 Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); |
21 | 363 } |
22 | 364 |
365 [Test()] | |
366 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndUnlimitedSlot() | |
367 { | |
23 | 368 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); |
26 | 369 equip.SlotName = SLOT_NAME; |
22 | 370 UnitType unitType = equip.EquipmentForUnit; |
26 | 371 unitType.AddEquipmentSlot(SLOT_NAME, new UnlimitedLimit()); |
22 | 372 Unit unit = GetUnit(unitType); |
373 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
374 } | |
375 | |
376 [Test()] | |
377 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndRatioSlot() | |
378 { | |
379 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
26 | 380 equip.SlotName = SLOT_NAME; |
22 | 381 UnitType unitType = equip.EquipmentForUnit; |
26 | 382 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); |
22 | 383 Unit unit = GetUnit(unitType); |
384 Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
385 } | |
386 | |
387 [Test()] | |
388 public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndAbsoluteSlot() | |
389 { | |
390 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); | |
26 | 391 equip.SlotName = SLOT_NAME; |
22 | 392 UnitType unitType = equip.EquipmentForUnit; |
26 | 393 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); |
22 | 394 Unit unit = GetUnit(unitType); |
395 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
396 } | |
23 | 397 |
398 [Test()] | |
399 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndAbsoluteSlot() | |
400 { | |
24 | 401 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
26 | 402 equip.SlotName = SLOT_NAME; |
23 | 403 UnitType unitType = equip.EquipmentForUnit; |
26 | 404 unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(5)); |
23 | 405 Unit unit = GetUnit(unitType); |
406 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
407 } | |
408 | |
409 [Test()] | |
410 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndUnlimitedSlot() | |
411 { | |
24 | 412 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
26 | 413 equip.SlotName = SLOT_NAME; |
23 | 414 UnitType unitType = equip.EquipmentForUnit; |
26 | 415 unitType.AddEquipmentSlot(SLOT_NAME, new UnlimitedLimit()); |
23 | 416 Unit unit = GetUnit(unitType); |
417 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
418 } | |
419 | |
420 [Test()] | |
421 public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndRatioSlot() | |
422 { | |
24 | 423 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); |
26 | 424 equip.SlotName = SLOT_NAME; |
23 | 425 UnitType unitType = equip.EquipmentForUnit; |
26 | 426 unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); |
23 | 427 Unit unit = GetUnit(unitType); |
428 Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); | |
429 } | |
24 | 430 |
431 private Unit GetUnit (UnitType unitType) | |
19 | 432 { |
172
c026c02583ca
* Remove MockArmy.GetMockArmy as it only causes problems in unit tests
IBBoard <dev@ibboard.co.uk>
parents:
32
diff
changeset
|
433 return new Unit ("unit", "Test Unit", 15, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); |
19 | 434 } |
18 | 435 } |
436 } |