# HG changeset patch # User IBBoard # Date 1320608838 0 # Node ID ce40484ad921e21aec9dfc102fe2b2359ad1a248 # Parent 32b3e41bc8f0377a09adc0b959429af96ceebd80 Re #356: Exception caused by unit limits * Add test that triggers the stack overflow, based on example data file diff -r 32b3e41bc8f0 -r ce40484ad921 API/Objects/UnitEquipmentLimitTests.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/UnitEquipmentLimitTests.cs Sun Nov 06 19:47:18 2011 +0000 @@ -0,0 +1,46 @@ +// This file (UnitEquipmentLimitTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard +// +// 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. +using System; +using NUnit.Framework; +using IBBoard.WarFoundry.API.Factories; +using IBBoard.Limits; +using NUnit.Framework.SyntaxHelpers; + +namespace IBBoard.WarFoundry.API.Objects +{ + [TestFixture()] + public class UnitEquipmentLimitTests + { + [Test()] + public void TestBug356StackOverflowWithRoundingIssues() + { + DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); + Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory); + Category cat = new Category("cat1", "Category"); + race.AddCategory(cat); + EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race); + race.AddEquipmentItem(equip1); + EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race); + race.AddEquipmentItem(equip2); + UnitType unitType = new UnitType("type1", "UnitType", race); + unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(34, false)); + UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType); + unitEquip1.SlotName = "slot"; + unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0); + unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true); + UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType); + unitEquip2.SlotName = "slot"; + unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0); + unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true); + race.AddUnitType(unitType); + Army army = new Army(race, "army", 1000); + Unit unit = new Unit(unitType, army.GetCategory(cat)); + unit.Size = 3; + unit.SetEquipmentRatio(unitEquip1, 33); + unit.SetEquipmentRatio(unitEquip2, 0.7); + Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1)); + } + } +} + diff -r 32b3e41bc8f0 -r ce40484ad921 IBBoard.WarFoundry.API.Tests.csproj --- a/IBBoard.WarFoundry.API.Tests.csproj Mon Oct 31 20:23:09 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sun Nov 06 19:47:18 2011 +0000 @@ -109,6 +109,7 @@ +