view API/Util/UnitEquipmentUtilTest.cs @ 22:25b21f564348

Re #198: Add equipment slot * Add initial unit tests for new "is equipment and slot ratio limited" method
author IBBoard <dev@ibboard.co.uk>
date Tue, 27 Oct 2009 20:27:02 +0000
parents 40a2fd337907
children 54abb61b9db8
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));
		}
		
		
		[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));
		}
		
		[Test()]
		public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndUnlimitedSlot()
		{
			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
			equip.MinLimit = new SimpleRoundedPercentageLimit(50, true);
			UnitType unitType = equip.EquipmentForUnit;
			Unit unit = GetUnit(unitType);
			Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip));
		}
		
		[Test()]
		public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndRatioSlot()
		{
			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);
			Assert.IsTrue(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip));
		}
		
		[Test()]
		public void TestIsEquipmentRatioLimitsWithRatioLimitedEquipmentAndAbsoluteSlot()
		{
			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);
			Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip));
		}

		private static Unit GetUnit (UnitType unitType)
		{
			return new Unit ("unit", "Test Unit", 10, unitType, new MockArmyCategory (unitType.MainCategory));
		}
	}
}