Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view 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 |
line wrap: on
line source
// This file (UnitEquipmentItemUtilTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 IBBoard // // 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. using System; using NUnit.Framework; using IBBoard.Limits; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Objects.Mock; namespace IBBoard.WarFoundry.API.Util { [TestFixture()] public class UnitEquipmentUtilTest { [Test()] public void TestGetMaxEquipmentCountForFixedLimitItemOnDefaultSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(3); UnitType unitType = equip.EquipmentForUnit; Unit unit = GetUnit (unitType); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = new NumericSizeConstrainedLimit(3); equip.SlotName = "slot"; UnitType unitType = equip.EquipmentForUnit; unitType.AddEquipmentSlot("slot", new AbsoluteNumericLimit(2)); Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForFixedLimitItemOnPercentageLimitedSlot() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = 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.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForFixedLimitItemOnNumberLimitedSlotWithExistingEquipment() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); equip.MaxLimit = 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.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForPercentageLimitItemOnDefaultSlot() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = GetUnit(unitType); Assert.AreEqual(5, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlot() { 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.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForPercentageLimitItemOnPercentageLimitedSlot() { 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.GetMaxEquipmentCount(unit, equip)); } [Test()] public void TestGetMaxEquipmentCountForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipment() { 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.GetMaxEquipmentCount(unit, equip)); } private static Unit GetUnit (UnitType unitType) { return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory)); } } }