annotate API/Util/UnitEquipmentUtilTest.cs @ 19:9b23e72ba3cf

Re #198: Add equipment slots * Fix unit tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 27 Oct 2009 20:00:54 +0000
parents e8e7554fb7f3
children 40a2fd337907
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (UnitEquipmentItemUtilTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
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.
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using System;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using NUnit.Framework;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.Limits;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.WarFoundry.API.Objects;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using IBBoard.WarFoundry.API.Objects.Mock;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Util
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 [TestFixture()]
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class UnitEquipmentUtilTest
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 [Test()]
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public void TestGetMaxEquipmentCountForFixedLimitItemOnDefaultSlot()
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
19 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3);
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 UnitType unitType = equip.EquipmentForUnit;
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
21 Unit unit = GetUnit (unitType);
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 }
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
24
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 [Test()]
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlot()
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 {
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
30 equip.MaxLimit = new NumericSizeConstrainedLimit(3);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
31 equip.SlotName = "slot";
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 UnitType unitType = equip.EquipmentForUnit;
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2));
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
34 Unit unit = GetUnit(unitType);
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 }
19
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
37
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
38 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
39 public void TestGetMaxEquipmentCountForFixedLimitItemOnPercentageLimitedSlot()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
40 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
41 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
42 equip.MaxLimit = new NumericSizeConstrainedLimit(7);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
43 equip.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
44 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
45 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, false));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
46 Unit unit = GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
47 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
48 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
49
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
50 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
51 public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
52 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
53 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
54 equip.MaxLimit = new NumericSizeConstrainedLimit(3);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
55 equip.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
56 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
57 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
58 Unit unit =GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
59 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
60 equip2.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
61 unit.SetEquipmentAmount(equip2, 5);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
62 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
63 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
64
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
65 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
66 public void TestGetMaxEquipmentCountForPercentageLimitItemOnDefaultSlot()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
67 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
68 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
69 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
70 Unit unit = GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
71 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
72 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
73
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
74 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
75 public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlot()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
76 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
77 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
78 equip.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
79 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
80 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
81 Unit unit = GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
82 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
83 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
84
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
85 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
86 public void TestGetMaxEquipmentCountForPercentageLimitItemOnPercentageLimitedSlot()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
87 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
88 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
89 equip.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
90 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
91 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(25, false));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
92 Unit unit = GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
93 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
94 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
95
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
96 [Test()]
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
97 public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment()
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
98 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
99 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
100 equip.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
101 UnitType unitType = equip.EquipmentForUnit;
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
102 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
103 Unit unit = GetUnit(unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
104 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
105 equip2.SlotName = "slot";
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
106 unit.SetEquipmentAmount(equip2, 5);
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
107 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
108 }
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
109
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
110 private static Unit GetUnit (UnitType unitType)
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
111 {
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
112 return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory));
9b23e72ba3cf Re #198: Add equipment slots
IBBoard <dev@ibboard.co.uk>
parents: 18
diff changeset
113 }
18
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 }
e8e7554fb7f3 Re #198: Add slots with count
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
115 }