changeset 185:ba9af0ce916a

Fixes #366: Rewrite equipment handling and limits * Add on more test to make sure that things behave as expected
author IBBoard <dev@ibboard.co.uk>
date Sun, 13 Nov 2011 20:14:36 +0000
parents 00ea622313be
children 3263691443be
files API/Objects/UnitEquipmentLimitTests.cs
diffstat 1 files changed, 34 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/UnitEquipmentLimitTests.cs	Sat Nov 12 20:49:11 2011 +0000
     1.2 +++ b/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 13 20:14:36 2011 +0000
     1.3 @@ -7,6 +7,7 @@
     1.4  using IBBoard.Limits;
     1.5  using NUnit.Framework.SyntaxHelpers;
     1.6  using IBBoard.WarFoundry.API.Util;
     1.7 +using IBBoard.CustomMath;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Objects
    1.10  {
    1.11 @@ -51,6 +52,39 @@
    1.12  			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
    1.13  			Assert.That(unit.Points, Is.EqualTo(35));
    1.14  		}
    1.15 +
    1.16 +		[Test]
    1.17 +		public void TestBug366CheckExtraEquipmentAllowed()
    1.18 +		{
    1.19 +			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
    1.20 +			Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory);
    1.21 +			Category cat = new Category("cat1", "Category");
    1.22 +			race.AddCategory(cat);
    1.23 +			EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
    1.24 +			race.AddEquipmentItem(equip1);
    1.25 +			EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
    1.26 +			race.AddEquipmentItem(equip2);
    1.27 +			UnitType unitType = new UnitType("type1", "UnitType", race);
    1.28 +			unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(34, false));
    1.29 +			UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
    1.30 +			unitEquip1.SlotName = "slot";
    1.31 +			unitEquip1.RoundNumberUp = true;
    1.32 +			unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
    1.33 +			unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    1.34 +			UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
    1.35 +			unitEquip2.SlotName = "slot";
    1.36 +			unitEquip2.RoundNumberUp = true;
    1.37 +			unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0);
    1.38 +			unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    1.39 +			race.AddUnitType(unitType);
    1.40 +			Army army = new Army(race, "army", 1000);
    1.41 +			Unit unit = new Unit(unitType, army.GetCategory(cat));
    1.42 +			unit.Size = 3;
    1.43 +			unit.SetEquipmentAmount(unitEquip1, 1);
    1.44 +			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1));
    1.45 +			Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0));
    1.46 +			Assert.That(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, unitEquip2), Is.EqualTo(34 - IBBMath.Percentage(1, 3)));
    1.47 +		}
    1.48  	}
    1.49  }
    1.50