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;
|
|
7 using IBBoard.Limits;
|
|
8 using IBBoard.WarFoundry.API.Objects;
|
|
9 using IBBoard.WarFoundry.API.Objects.Mock;
|
|
10
|
|
11 namespace IBBoard.WarFoundry.API.Util
|
|
12 {
|
|
13 [TestFixture()]
|
|
14 public class UnitEquipmentUtilTest
|
|
15 {
|
|
16 [Test()]
|
|
17 public void TestGetMaxEquipmentCountForFixedLimitItemOnDefaultSlot()
|
|
18 {
|
19
|
19 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3);
|
18
|
20 UnitType unitType = equip.EquipmentForUnit;
|
19
|
21 Unit unit = GetUnit (unitType);
|
18
|
22 Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
23 }
|
19
|
24
|
18
|
25
|
|
26 [Test()]
|
|
27 public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlot()
|
|
28 {
|
|
29 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
|
19
|
30 equip.MaxLimit = new NumericSizeConstrainedLimit(3);
|
|
31 equip.SlotName = "slot";
|
18
|
32 UnitType unitType = equip.EquipmentForUnit;
|
|
33 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2));
|
19
|
34 Unit unit = GetUnit(unitType);
|
18
|
35 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
36 }
|
19
|
37
|
|
38 [Test()]
|
|
39 public void TestGetMaxEquipmentCountForFixedLimitItemOnPercentageLimitedSlot()
|
|
40 {
|
|
41 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
|
|
42 equip.MaxLimit = new NumericSizeConstrainedLimit(7);
|
|
43 equip.SlotName = "slot";
|
|
44 UnitType unitType = equip.EquipmentForUnit;
|
|
45 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, false));
|
|
46 Unit unit = GetUnit(unitType);
|
|
47 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
48 }
|
|
49
|
|
50 [Test()]
|
|
51 public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment()
|
|
52 {
|
|
53 UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
|
|
54 equip.MaxLimit = new NumericSizeConstrainedLimit(3);
|
|
55 equip.SlotName = "slot";
|
|
56 UnitType unitType = equip.EquipmentForUnit;
|
|
57 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6));
|
|
58 Unit unit =GetUnit(unitType);
|
|
59 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType);
|
|
60 equip2.SlotName = "slot";
|
|
61 unit.SetEquipmentAmount(equip2, 5);
|
|
62 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
63 }
|
|
64
|
|
65 [Test()]
|
|
66 public void TestGetMaxEquipmentCountForPercentageLimitItemOnDefaultSlot()
|
|
67 {
|
|
68 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
|
|
69 UnitType unitType = equip.EquipmentForUnit;
|
|
70 Unit unit = GetUnit(unitType);
|
|
71 Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
72 }
|
|
73
|
|
74 [Test()]
|
|
75 public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlot()
|
|
76 {
|
|
77 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
|
|
78 equip.SlotName = "slot";
|
|
79 UnitType unitType = equip.EquipmentForUnit;
|
|
80 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2));
|
|
81 Unit unit = GetUnit(unitType);
|
|
82 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
83 }
|
|
84
|
|
85 [Test()]
|
|
86 public void TestGetMaxEquipmentCountForPercentageLimitItemOnPercentageLimitedSlot()
|
|
87 {
|
|
88 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
|
|
89 equip.SlotName = "slot";
|
|
90 UnitType unitType = equip.EquipmentForUnit;
|
|
91 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(25, false));
|
|
92 Unit unit = GetUnit(unitType);
|
|
93 Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
94 }
|
|
95
|
|
96 [Test()]
|
|
97 public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment()
|
|
98 {
|
|
99 UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
|
|
100 equip.SlotName = "slot";
|
|
101 UnitType unitType = equip.EquipmentForUnit;
|
|
102 unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6));
|
|
103 Unit unit = GetUnit(unitType);
|
|
104 UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType);
|
|
105 equip2.SlotName = "slot";
|
|
106 unit.SetEquipmentAmount(equip2, 5);
|
|
107 Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
|
|
108 }
|
|
109
|
|
110 private static Unit GetUnit (UnitType unitType)
|
|
111 {
|
|
112 return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory));
|
|
113 }
|
18
|
114 }
|
|
115 }
|