changeset 183:bd38c32fb1a9

Re #366: Rewrite equipment handling and limits * Remove comment added during #356 - now resolved * Add test for behaviour of percentages * Add test for new "calculate number taken" util method
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Nov 2011 20:36:58 +0000
parents e9be63d72b3c
children 00ea622313be
files API/Objects/UnitEquipmentLimitTests.cs API/Objects/UnitEquipmentRatioSelectionTests.cs API/Util/UnitEquipmentUtilTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 4 files changed, 67 insertions(+), 2 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 06 21:02:00 2011 +0000
     1.2 +++ b/API/Objects/UnitEquipmentLimitTests.cs	Sat Nov 12 20:36:58 2011 +0000
     1.3 @@ -48,8 +48,6 @@
     1.4  			Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0));
     1.5  			Assert.That(unit.Points, Is.EqualTo(33));
     1.6  			unit.SetEquipmentRatio(unitEquip2, 0.7);
     1.7 -			//FIXME: Current values based on pre-Ticket 366 expectations (adding equipment that rounds up
     1.8 -			//   adds to amount, even if it goes over the limit)
     1.9  			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
    1.10  			Assert.That(unit.Points, Is.EqualTo(35));
    1.11  		}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/API/Objects/UnitEquipmentRatioSelectionTests.cs	Sat Nov 12 20:36:58 2011 +0000
     2.3 @@ -0,0 +1,51 @@
     2.4 +// This file (UnitEquipmentRatioSelectionTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     2.5 +// 
     2.6 +// 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.
     2.7 +using System;
     2.8 +using NUnit.Framework;
     2.9 +using IBBoard.WarFoundry.API.Util;
    2.10 +using IBBoard.WarFoundry.API.Factories;
    2.11 +using IBBoard.Limits;
    2.12 +using NUnit.Framework.SyntaxHelpers;
    2.13 +
    2.14 +namespace IBBoard.WarFoundry.API.Objects
    2.15 +{
    2.16 +	[TestFixture()]
    2.17 +	public class UnitEquipmentRatioSelectionTests
    2.18 +	{
    2.19 +		[Test()]
    2.20 +		public void Bug366TestAmountIsNotLimitedByAbsoluteAmount()
    2.21 +		{
    2.22 +			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
    2.23 +			Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory);
    2.24 +			Category cat = new Category("cat1", "Category");
    2.25 +			race.AddCategory(cat);
    2.26 +			EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
    2.27 +			race.AddEquipmentItem(equip1);
    2.28 +			EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
    2.29 +			race.AddEquipmentItem(equip2);
    2.30 +			UnitType unitType = new UnitType("type1", "UnitType", race);
    2.31 +			unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(33, true));
    2.32 +			UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
    2.33 +			unitEquip1.SlotName = "slot";
    2.34 +			unitEquip1.RoundNumberUp = true;
    2.35 +			unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
    2.36 +			unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    2.37 +			UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
    2.38 +			unitEquip2.SlotName = "slot";
    2.39 +			unitEquip2.RoundNumberUp = true;
    2.40 +			unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0);
    2.41 +			unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    2.42 +			race.AddUnitType(unitType);
    2.43 +			Army army = new Army(race, "army", 1000);
    2.44 +			Unit unit = new Unit(unitType, army.GetCategory(cat));
    2.45 +			unit.Size = 3;
    2.46 +			unit.SetEquipmentAmount(unitEquip1, 1);
    2.47 +			unit.SetEquipmentRatio(unitEquip2, 33);
    2.48 +			Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(33));
    2.49 +			Assert.That(UnitEquipmentUtil.GetEquipmentAmountTaken(unit, unitEquip2), Is.EqualTo(1));
    2.50 +			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
    2.51 +		}
    2.52 +	}
    2.53 +}
    2.54 +
     3.1 --- a/API/Util/UnitEquipmentUtilTest.cs	Sun Nov 06 21:02:00 2011 +0000
     3.2 +++ b/API/Util/UnitEquipmentUtilTest.cs	Sat Nov 12 20:36:58 2011 +0000
     3.3 @@ -8,6 +8,7 @@
     3.4  using IBBoard.Limits;
     3.5  using IBBoard.WarFoundry.API.Objects;
     3.6  using IBBoard.WarFoundry.API.Objects.Mock;
     3.7 +using NUnit.Framework.SyntaxHelpers;
     3.8  
     3.9  namespace IBBoard.WarFoundry.API.Util
    3.10  {
    3.11 @@ -427,6 +428,20 @@
    3.12  			Unit unit = GetUnit(unitType);
    3.13  			Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip));
    3.14  		}
    3.15 +
    3.16 +		[Test()]
    3.17 +		public void TestCalculateEquipmentAmountTakenFromRatio()
    3.18 +		{
    3.19 +			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
    3.20 +			UnitType unitType = equip.EquipmentForUnit;
    3.21 +			Unit unit = GetUnit(unitType);
    3.22 +			Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 33.4), Is.EqualTo(5));
    3.23 +			Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 50), Is.EqualTo(7));
    3.24 +			equip.RoundNumberUp = true;
    3.25 +			Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 33.4), Is.EqualTo(6));
    3.26 +			Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 50), Is.EqualTo(8));
    3.27 +
    3.28 +		}
    3.29  		
    3.30  		private Unit GetUnit (UnitType unitType)
    3.31  		{
     4.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Nov 06 21:02:00 2011 +0000
     4.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Nov 12 20:36:58 2011 +0000
     4.3 @@ -110,6 +110,7 @@
     4.4      <Compile Include="API\Factories\AbstractNativeWarFoundryFactoryTest.cs" />
     4.5      <Compile Include="API\Factories\Mock\MockNativeWarFoundryFactory.cs" />
     4.6      <Compile Include="API\Objects\UnitEquipmentLimitTests.cs" />
     4.7 +    <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" />
     4.8    </ItemGroup>
     4.9    <ItemGroup>
    4.10      <None Include="app.config" />