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 diff
     1.1 --- a/API/Util/UnitEquipmentUtilTest.cs	Fri Oct 30 20:48:17 2009 +0000
     1.2 +++ b/API/Util/UnitEquipmentUtilTest.cs	Fri Nov 06 20:05:29 2009 +0000
     1.3 @@ -4,6 +4,7 @@
     1.4  
     1.5  using System;
     1.6  using NUnit.Framework;
     1.7 +using IBBoard.CustomMath;
     1.8  using IBBoard.Limits;
     1.9  using IBBoard.WarFoundry.API.Objects;
    1.10  using IBBoard.WarFoundry.API.Objects.Mock;
    1.11 @@ -23,8 +24,8 @@
    1.12  			Unit unit = GetUnit (unitType);
    1.13  			Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.14  			Assert.AreEqual(4, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.15 -			Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.16 -			Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.17 +			Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.18 +			Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.19  		}
    1.20  		
    1.21  		[Test()]
    1.22 @@ -35,8 +36,8 @@
    1.23  			Unit unit = GetUnit (unitType);
    1.24  			Assert.AreEqual(4, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.25  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.26 -			Assert.AreEqual(4.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.27 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.28 +			Assert.AreEqual(IBBMath.Percentage(4, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.29 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.30  		}
    1.31  		
    1.32  		[Test()]
    1.33 @@ -49,8 +50,8 @@
    1.34  			Unit unit = GetUnit(unitType);
    1.35  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.36  			Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.37 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.38 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.39 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.40 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.41  		}
    1.42  		
    1.43  		[Test()]
    1.44 @@ -63,8 +64,8 @@
    1.45  			Unit unit = GetUnit(unitType);
    1.46  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.47  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.48 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.49 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.50 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.51 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.52  		}
    1.53  		
    1.54  		[Test()]
    1.55 @@ -77,8 +78,8 @@
    1.56  			Unit unit = GetUnit(unitType);
    1.57  			Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.58  			Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.59 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.60 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.61 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.62 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.63  		}
    1.64  		
    1.65  		[Test()]
    1.66 @@ -91,8 +92,8 @@
    1.67  			Unit unit = GetUnit(unitType);
    1.68  			Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.69  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.70 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.71 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.72 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.73 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.74  		}
    1.75  				
    1.76  		[Test()]
    1.77 @@ -120,7 +121,7 @@
    1.78  			Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.79  			Assert.AreEqual(5, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.80  			Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.81 -			Assert.AreEqual(5.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.82 +			Assert.AreEqual(IBBMath.Percentage(5, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.83  		}
    1.84  		
    1.85  		[Test()]
    1.86 @@ -136,8 +137,23 @@
    1.87  			unit.SetEquipmentAmount(equip2, 5);
    1.88  			Assert.AreEqual(1, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
    1.89  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
    1.90 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.91 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.92 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
    1.93 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
    1.94 +		}
    1.95 +		
    1.96 +		[Test()]
    1.97 +		public void TestGetEquipmentCountsForFixedLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType()
    1.98 +		{
    1.99 +			UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem(1, 3);
   1.100 +			equip.SlotName = SLOT_NAME;
   1.101 +			UnitType unitType = equip.EquipmentForUnit;
   1.102 +			unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(3));
   1.103 +			Unit unit =GetUnit(unitType);
   1.104 +			unit.SetEquipmentAmount(equip, 2);
   1.105 +			Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.106 +			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.107 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.108 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.109  		}
   1.110  		
   1.111  		[Test()]
   1.112 @@ -153,8 +169,8 @@
   1.113  			unit.SetEquipmentAmount(equip2, 5);
   1.114  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.115  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.116 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.117 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.118 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.119 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.120  		}
   1.121  		
   1.122  		[Test()]
   1.123 @@ -191,7 +207,7 @@
   1.124  			Unit unit = GetUnit(unitType);
   1.125  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.126  			Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.127 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.128 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.129  		}
   1.130  		
   1.131  		[Test()]
   1.132 @@ -204,8 +220,8 @@
   1.133  			Unit unit = GetUnit(unitType);
   1.134  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.135  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.136 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.137 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.138 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.139 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.140  		}
   1.141  		
   1.142  		[Test()]
   1.143 @@ -277,8 +293,23 @@
   1.144  			unit.SetEquipmentAmount(equip2, 5);
   1.145  			Assert.AreEqual(2, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.146  			Assert.AreEqual(2, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.147 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.148 -			Assert.AreEqual(2.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.149 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.150 +			Assert.AreEqual(IBBMath.Percentage(2, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.151 +		}
   1.152 +		
   1.153 +		[Test()]
   1.154 +		public void TestGetEquipmentCountsForPercentageLimitItemOnNumberLimitedSlotWithExistingEquipmentOfSameType()
   1.155 +		{
   1.156 +			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50);
   1.157 +			equip.SlotName = SLOT_NAME;
   1.158 +			UnitType unitType = equip.EquipmentForUnit;
   1.159 +			unitType.AddEquipmentSlot(SLOT_NAME, new AbsoluteNumericLimit(10));
   1.160 +			Unit unit = GetUnit(unitType);
   1.161 +			unit.SetEquipmentAmount(equip, 5);
   1.162 +			Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.163 +			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.164 +			Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.165 +			Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.166  		}
   1.167  		
   1.168  		[Test()]
   1.169 @@ -294,8 +325,23 @@
   1.170  			unit.SetEquipmentAmount(equip2, 5);
   1.171  			Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.172  			Assert.AreEqual(3, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.173 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.174 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.175 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.176 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.177 +		}
   1.178 +		
   1.179 +		[Test()]
   1.180 +		public void TestGetEquipmentCountsForPercentageLimitItemOnPercentageLimitedSlotWithExistingEquipmentOfSameType()
   1.181 +		{
   1.182 +			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(10, 50);
   1.183 +			equip.SlotName = SLOT_NAME;
   1.184 +			UnitType unitType = equip.EquipmentForUnit;
   1.185 +			unitType.AddEquipmentSlot(SLOT_NAME, new SimpleRoundedPercentageLimit(50, true));
   1.186 +			Unit unit = GetUnit(unitType);
   1.187 +			unit.SetEquipmentAmount(equip, 5);
   1.188 +			Assert.AreEqual(7, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.189 +			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.190 +			Assert.AreEqual(50, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.191 +			Assert.AreEqual(10, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.192  		}
   1.193  		
   1.194  		[Test()]
   1.195 @@ -311,8 +357,8 @@
   1.196  			unit.SetEquipmentAmount(equip2, 5);
   1.197  			Assert.AreEqual(3, UnitEquipmentUtil.GetMaxEquipmentCount(unit, equip));
   1.198  			Assert.AreEqual(1, UnitEquipmentUtil.GetMinEquipmentCount(unit, equip));
   1.199 -			Assert.AreEqual(3.0/15*100, UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.200 -			Assert.AreEqual(1.0/15*100, UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.201 +			Assert.AreEqual(IBBMath.Percentage(3, 15), UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, equip));
   1.202 +			Assert.AreEqual(IBBMath.Percentage(1, 15), UnitEquipmentUtil.GetMinEquipmentPercentage(unit, equip));
   1.203  		}
   1.204  		
   1.205  		[Test()]