Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 29:29e81f10bb8b
Re #208: equipmentslot limit issues
* Extend unit tests to cover extra situation
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 06 Nov 2009 20:05:29 +0000 |
parents | 2395dc131401 |
children | 0cc21db8d60a |
files | API/Util/UnitEquipmentUtilTest.cs |
diffstat | 1 files changed, 72 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Util/UnitEquipmentUtilTest.cs Fri Oct 30 20:48:17 2009 +0000 +++ b/API/Util/UnitEquipmentUtilTest.cs Fri Nov 06 20:05:29 2009 +0000 @@ -4,6 +4,7 @@ using System; using NUnit.Framework; +using IBBoard.CustomMath; using IBBoard.Limits; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Objects.Mock; @@ -23,8 +24,8 @@ Unit unit = GetUnit (unitType); Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(4, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -35,8 +36,8 @@ Unit unit = GetUnit (unitType); Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -49,8 +50,8 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -63,8 +64,8 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -77,8 +78,8 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -91,8 +92,8 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -120,7 +121,7 @@ Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(5.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -136,8 +137,23 @@ unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + } + + [Test()] + public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType() + { + UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3); + equip.SlotName = SLOT_NAME; + UnitType unitType = equip.EquipmentForUnit; + unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(3)); + Unit unit =GetUnit(unitType); + unit.SetEquipmentAmount(equip, 2); + Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -153,8 +169,8 @@ unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -191,7 +207,7 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); } [Test()] @@ -204,8 +220,8 @@ Unit unit = GetUnit(unitType); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -277,8 +293,23 @@ unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + } + + [Test()] + public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType() + { + UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); + equip.SlotName = SLOT_NAME; + UnitType unitType = equip.EquipmentForUnit; + unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(10)); + Unit unit = GetUnit(unitType); + unit.SetEquipmentAmount(equip, 5); + Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); + Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -294,8 +325,23 @@ unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + } + + [Test()] + public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipmentOfSameType() + { + UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50); + equip.SlotName = SLOT_NAME; + UnitType unitType = equip.EquipmentForUnit; + unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true)); + Unit unit = GetUnit(unitType); + unit.SetEquipmentAmount(equip, 5); + Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); + Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); + Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()] @@ -311,8 +357,8 @@ unit.SetEquipmentAmount(equip2, 5); Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip)); Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip)); - Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); - Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip)); + Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip)); } [Test()]