# HG changeset patch # User IBBoard # Date 1320612807 0 # Node ID 49b359624ea59f047aeb69ec1b1a78a02f6fc9c8 # Parent ce40484ad921e21aec9dfc102fe2b2359ad1a248 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 diff -r ce40484ad921 -r 49b359624ea5 API/Objects/UnitEquipmentLimitTests.cs --- a/API/Objects/UnitEquipmentLimitTests.cs Sun Nov 06 19:47:18 2011 +0000 +++ b/API/Objects/UnitEquipmentLimitTests.cs Sun Nov 06 20:53:27 2011 +0000 @@ -6,6 +6,7 @@ using IBBoard.WarFoundry.API.Factories; using IBBoard.Limits; using NUnit.Framework.SyntaxHelpers; +using IBBoard.WarFoundry.API.Util; namespace IBBoard.WarFoundry.API.Objects { @@ -20,17 +21,22 @@ Category cat = new Category("cat1", "Category"); race.AddCategory(cat); EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race); + equip1.Cost = 3; race.AddEquipmentItem(equip1); EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race); + equip2.Cost = 2; race.AddEquipmentItem(equip2); UnitType unitType = new UnitType("type1", "UnitType", race); + unitType.CostPerTrooper = 10; unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(34, false)); UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType); unitEquip1.SlotName = "slot"; + unitEquip1.RoundNumberUp = true; unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0); unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true); UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType); unitEquip2.SlotName = "slot"; + unitEquip2.RoundNumberUp = true; unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0); unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true); race.AddUnitType(unitType); @@ -38,8 +44,12 @@ Unit unit = new Unit(unitType, army.GetCategory(cat)); unit.Size = 3; unit.SetEquipmentRatio(unitEquip1, 33); + Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1)); + Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0)); + Assert.That(unit.Points, Is.EqualTo(33)); unit.SetEquipmentRatio(unitEquip2, 0.7); - Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1)); + Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2)); + Assert.That(unit.Points, Is.EqualTo(35)); } } }