Mercurial > repos > IBBoard.WarFoundry.API.Tests
view API/Objects/UnitTest.cs @ 16:74346d5c17fe
Re #198: Add slots with counts to units
* Add tests for equipment slot amount storage and retrieval
* Add extra constructors to some mocks for constructing other objects of same type
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Oct 2009 14:02:50 +0000 |
parents | 1119b6f48e8e |
children | 4480d7151d35 |
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; namespace IBBoard.WarFoundry.API.Objects { [TestFixture()] public class UnitTest { [Test()] public void TestAddNumericAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.SetEquipmentAmount(equip, WarFoundryCore.INFINITY); Assert.AreEqual(WarFoundryCore.INFINITY, unit.GetEquipmentAmount(equip)); Assert.IsFalse(unit.GetEquipmentAmountIsRatio(equip)); } [Test()] public void TestRemoveNumericAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.SetEquipmentAmount(equip, WarFoundryCore.INFINITY); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmount(equip)); } [Test()] public void TestAddPercentageAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); Assert.AreEqual(50, unit.GetEquipmentAmount(equip)); Assert.IsTrue(unit.GetEquipmentAmountIsRatio(equip)); } [Test()] public void TestRemovePercentageAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.SetEquipmentRatio(equip, 50); unit.SetEquipmentRatio(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmount(equip)); } [Test()] public void TestAddNumericAmountOfPercentageAmountEquipmentAddsEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentAmount(equip, 2); Assert.AreEqual(2, unit.GetEquipmentAmount(equip)); Assert.IsFalse(unit.GetEquipmentAmountIsRatio(equip)); } [Test()] public void TestRemoveNumericAmountOfPercentageAmountEquipmentRemovesEquipmentSelection() { UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); UnitType unitType = equip.EquipmentForUnit; Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.Size = 5; unit.SetEquipmentAmount(equip, 2); unit.SetEquipmentAmount(equip, 0); Assert.AreEqual(0, unit.GetEquipmentAmount(equip)); } [Test()] public void TestAmountInSlotWithNoItems() { UnitType unitType = new MockUnitType(); Unit unit = new MockUnit(unitType, new MockArmyCategory(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 MockUnit(unitType, new MockArmyCategory(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 MockUnit(unitType, new MockArmyCategory(unitType.MainCategory)); unit.Size = 10; unit.SetEquipmentRatio(equip1, 50); UnitEquipmentItem equip2 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip2"), unitType); equip2.SlotName = slotName; equip2.MinPercentage = 0; UnitEquipmentItem equip3 = new MockPercentageAmountUnitEquipmentItem(new MockEquipmentItem("equip3"), unitType); equip3.SlotName = slotName; equip3.MinPercentage = 0; unit.SetEquipmentRatio(equip2, 25); unit.SetEquipmentRatio(equip3, 10); Assert.AreEqual(8, unit.GetEquipmentAmountInSlot(slotName)); } } }