changeset 181:49b359624ea5

Re #356: Stack overflow with some equipment limits * Add more values to data to test amount counting from various directions Note: The end of this code highlights a larger bug/design flaw
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Nov 2011 20:53:27 +0000
parents ce40484ad921
children e9be63d72b3c
files API/Objects/UnitEquipmentLimitTests.cs
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 06 19:47:18 2011 +0000
     1.2 +++ b/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 06 20:53:27 2011 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  using IBBoard.WarFoundry.API.Factories;
     1.5  using IBBoard.Limits;
     1.6  using NUnit.Framework.SyntaxHelpers;
     1.7 +using IBBoard.WarFoundry.API.Util;
     1.8  
     1.9  namespace IBBoard.WarFoundry.API.Objects
    1.10  {
    1.11 @@ -20,17 +21,22 @@
    1.12  			Category cat = new Category("cat1", "Category");
    1.13  			race.AddCategory(cat);
    1.14  			EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
    1.15 +			equip1.Cost = 3;
    1.16  			race.AddEquipmentItem(equip1);
    1.17  			EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
    1.18 +			equip2.Cost = 2;
    1.19  			race.AddEquipmentItem(equip2);
    1.20  			UnitType unitType = new UnitType("type1", "UnitType", race);
    1.21 +			unitType.CostPerTrooper = 10;
    1.22  			unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(34, false));
    1.23  			UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
    1.24  			unitEquip1.SlotName = "slot";
    1.25 +			unitEquip1.RoundNumberUp = true;
    1.26  			unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
    1.27  			unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    1.28  			UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
    1.29  			unitEquip2.SlotName = "slot";
    1.30 +			unitEquip2.RoundNumberUp = true;
    1.31  			unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0);
    1.32  			unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    1.33  			race.AddUnitType(unitType);
    1.34 @@ -38,8 +44,12 @@
    1.35  			Unit unit = new Unit(unitType, army.GetCategory(cat));
    1.36  			unit.Size = 3;
    1.37  			unit.SetEquipmentRatio(unitEquip1, 33);
    1.38 +			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1));
    1.39 +			Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0));
    1.40 +			Assert.That(unit.Points, Is.EqualTo(33));
    1.41  			unit.SetEquipmentRatio(unitEquip2, 0.7);
    1.42 -			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1));
    1.43 +			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
    1.44 +			Assert.That(unit.Points, Is.EqualTo(35));
    1.45  		}
    1.46  	}
    1.47  }