Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Objects/UnitTest.cs @ 210:649759343da5
Re #379: Fix validation of requirements to check for unit
* Tidy up tests to reduce replication and fix copy-and-paste inconsistencies
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Feb 2012 16:36:20 +0000 |
parents | c026c02583ca |
children |
line wrap: on
line source
// This file (UnitTest.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.WarFoundry.API.Objects.Mock; using IBBoard.WarFoundry.API.Util; using IBBoard.Limits; namespace IBBoard.WarFoundry.API.Objects { [TestFixture()] public class UnitTest { [Test()] public void TestAddNumericAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); Assert.IsTrue(equip.MaxLimit is Limits.NumericSizeConstrainedLimit); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 5); Assert.AreEqual(5, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); Assert.IsFalse(UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)); } [Test()] public void TestRemoveNumericAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(5); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 5); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); } [Test()] public void TestAddPercentageAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); Assert.AreEqual(50, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); Assert.IsTrue(UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)); } [Test()] public void TestRemovePercentageAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); unit.SetEquipmentRatio(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); } [Test()] public void TestAddNumericAmountOfPercentageAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentAmount(equip, 2); Assert.AreEqual(2, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); Assert.IsFalse(UnitEquipmentUtil.GetEquipmentAmountIsRatio(unit, equip)); } [Test()] public void TestRemoveNumericAmountOfPercentageAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentAmount(equip, 2); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, UnitEquipmentUtil.GetEquipmentAmount(unit, equip)); } [Test()] public void TestAmountInSlotWithNoItems() { UnitType unitType = new MockUnitType(); Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); Assert.AreEqual(0, unit.GetEquipmentAmountInSlot("")); } [Test()] public void TestAmountInSlotWithOneItem() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); string slotName = "TestSlot"; equip.SlotName = slotName; UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentRatio(equip, 50); Assert.AreEqual(2, unit.GetEquipmentAmountInSlot(slotName)); } [Test()] public void TestAmountInSlotWithMultipleItems() { UnitEquipmentItem equip1 = new MockPercentageAmountUnitEquipmentItem(); string slotName = "TestSlot"; equip1.SlotName = slotName; UnitType unitType = equip1.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip1, 50); UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); equip2.SlotName = slotName; equip2.MinLimit = new SimpleRoundedPercentageLimit(0); UnitEquipmentItem equip3 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip3"), unitType); equip3.SlotName = slotName; equip3.MinLimit = new SimpleRoundedPercentageLimit(0); unit.SetEquipmentRatio(equip2, 25); unit.SetEquipmentRatio(equip3, 10); Assert.AreEqual(8, unit.GetEquipmentAmountInSlot(slotName)); } [Test()] public void TestAmountInSlotWithOneItemAfterRemove() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); string slotName = "TestSlot"; equip.SlotName = slotName; UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 5, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); unit.SetEquipmentRatio(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmountInSlot(slotName)); } [Test()] public void TestAmountInSlotWithMultipleItemsAfterRemove() { UnitEquipmentItem equip1 = new MockPercentageAmountUnitEquipmentItem(); string slotName = "TestSlot"; equip1.SlotName = slotName; UnitType unitType = equip1.EquipmentForUnit; Unit unit = new Unit("unit", "Test Unit", 10, unitType, new ArmyCategory(new MockArmy(), unitType.MainCategory)); unit.SetEquipmentRatio(equip1, 50); UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); equip2.SlotName = slotName; equip2.MinLimit = new SimpleRoundedPercentageLimit(0); UnitEquipmentItem equip3 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip3"), unitType); equip3.SlotName = slotName; equip3.MinLimit = new SimpleRoundedPercentageLimit(0); unit.SetEquipmentRatio(equip2, 25); unit.SetEquipmentRatio(equip3, 10); unit.SetEquipmentAmount(equip1, 0); Assert.AreEqual(3, unit.GetEquipmentAmountInSlot(slotName)); } } }