Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 24:92db6f6a6b0b
Re #198: Add equipment slots
* Consolidate unit tests and add first test for percentage limit retrieval
* Add tests to highlight problem with max limit actually taking min limit
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 27 Oct 2009 20:52:56 +0000 |
parents | 54abb61b9db8 |
children | d48e73488838 |
files | API/Util/UnitEquipmentUtilTest.cs |
diffstat | 1 files changed, 39 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Util/UnitEquipmentUtilTest.cs Tue Oct 27 20:30:12 2009 +0000 +++ b/API/Util/UnitEquipmentUtilTest.cs Tue Oct 27 20:52:56 2009 +0000 @@ -14,16 +14,27 @@ public class UnitEquipmentUtilTest { [Test()] - public void TestGetMaxEquipmentCountForFixedLimitItemOnDefaultSlot() + public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); UnitType unitType = equip.EquipmentForUnit; Unit unit = GetUnit (unitType); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlot() + public void TestGetEquipmentCountsForFixedLimitItemOnDefaultSlotWithDifferentMinLimit() + { + UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1,3); + UnitType unitType = equip.EquipmentForUnit; + Unit unit = GetUnit (unitType); + Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); + } + + [Test()] + public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = new NumericSizeConstrainedLimit(3); @@ -32,10 +43,11 @@ unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForFixedLimitItemOnPercentageLimitedSlot() + public void TestGetEquipmentCountsForFixedLimitItemOnPercentageLimitedSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = new NumericSizeConstrainedLimit(7); @@ -44,10 +56,11 @@ unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, false)); Unit unit = GetUnit(unitType); Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() + public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = new NumericSizeConstrainedLimit(3); @@ -59,19 +72,21 @@ equip2.SlotName = "slot"; unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForPercentageLimitItemOnDefaultSlot() + public void TestGetEquipmentCountsForPercentageLimitItemOnDefaultSlot() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = GetUnit(unitType); Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlot() + public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlot() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; @@ -79,10 +94,11 @@ unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForPercentageLimitItemOnPercentageLimitedSlot() + public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlot() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; @@ -90,10 +106,11 @@ unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(25, false)); Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } [Test()] - public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() + public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; @@ -104,99 +121,6 @@ equip2.SlotName = "slot"; unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); - } - - - [Test()] - public void TestGetMinEquipmentCountForFixedLimitItemOnDefaultSlot() - { - UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); - UnitType unitType = equip.EquipmentForUnit; - Unit unit = GetUnit (unitType); - Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForFixedLimitItemOnNumberLimitedSlot() - { - UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); - equip.MinLimit = new NumericSizeConstrainedLimit(3); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); - Unit unit = GetUnit(unitType); - Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForFixedLimitItemOnPercentageLimitedSlot() - { - UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); - equip.MinLimit = new NumericSizeConstrainedLimit(7); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, false)); - Unit unit = GetUnit(unitType); - Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() - { - UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); - equip.MinLimit = new NumericSizeConstrainedLimit(3); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6)); - Unit unit =GetUnit(unitType); - UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); - equip2.SlotName = "slot"; - unit.SetEquipmentAmount(equip2, 5); - Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForPercentageLimitItemOnDefaultSlot() - { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); - UnitType unitType = equip.EquipmentForUnit; - Unit unit = GetUnit(unitType); - Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForPercentageLimitItemOnNumberLimitedSlot() - { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); - Unit unit = GetUnit(unitType); - Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForPercentageLimitItemOnPercentageLimitedSlot() - { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(25, false)); - Unit unit = GetUnit(unitType); - Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - } - - [Test()] - public void TestGetMinEquipmentCountForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() - { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); - equip.SlotName = "slot"; - UnitType unitType = equip.EquipmentForUnit; - unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(6)); - Unit unit = GetUnit(unitType); - UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); - equip2.SlotName = "slot"; - unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); } @@ -205,7 +129,6 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new SimpleRoundedPercentageLimit(50, true); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new UnlimitedLimit()); Unit unit = GetUnit(unitType); @@ -217,7 +140,6 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new SimpleRoundedPercentageLimit(50, true); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, true)); Unit unit = GetUnit(unitType); @@ -229,7 +151,6 @@ { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new SimpleRoundedPercentageLimit(50, true); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(5)); Unit unit = GetUnit(unitType); @@ -239,9 +160,8 @@ [Test()] public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndAbsoluteSlot() { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); + UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new AbsoluteNumericLimit(50); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(5)); Unit unit = GetUnit(unitType); @@ -251,9 +171,8 @@ [Test()] public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndUnlimitedSlot() { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); + UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new AbsoluteNumericLimit(50); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new UnlimitedLimit()); Unit unit = GetUnit(unitType); @@ -263,16 +182,24 @@ [Test()] public void TestIsEquipmentRatioLimitsWithAbsoluteLimitedEquipmentAndRatioSlot() { - UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); + UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.SlotName = "slot"; - equip.MinLimit = new AbsoluteNumericLimit(50); UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(50, true)); Unit unit = GetUnit(unitType); Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); } - - private static Unit GetUnit (UnitType unitType) + + [Test()] + public void TestGetMaxPercentageForPercentageLimitedEquipmentOnUnlimitedSlot() + { + UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(75); + UnitType unitType = equip.EquipmentForUnit; + Unit unit = GetUnit(unitType); + Assert.AreEqual(75, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + } + + private Unit GetUnit (UnitType unitType) { return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory)); }