changeset 180:ce40484ad921

Re #356: Exception caused by unit limits * Add test that triggers the stack overflow, based on example data file
author IBBoard <dev@ibboard.co.uk>
date Sun, 06 Nov 2011 19:47:18 +0000
parents 32b3e41bc8f0
children 49b359624ea5
files API/Objects/UnitEquipmentLimitTests.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 47 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 06 19:47:18 2011 +0000
     1.3 @@ -0,0 +1,46 @@
     1.4 +// This file (UnitEquipmentLimitTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     1.5 +// 
     1.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.
     1.7 +using System;
     1.8 +using NUnit.Framework;
     1.9 +using IBBoard.WarFoundry.API.Factories;
    1.10 +using IBBoard.Limits;
    1.11 +using NUnit.Framework.SyntaxHelpers;
    1.12 +
    1.13 +namespace IBBoard.WarFoundry.API.Objects
    1.14 +{
    1.15 +	[TestFixture()]
    1.16 +	public class UnitEquipmentLimitTests
    1.17 +	{
    1.18 +		[Test()]
    1.19 +		public void TestBug356StackOverflowWithRoundingIssues()
    1.20 +		{
    1.21 +			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
    1.22 +			Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory);
    1.23 +			Category cat = new Category("cat1", "Category");
    1.24 +			race.AddCategory(cat);
    1.25 +			EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
    1.26 +			race.AddEquipmentItem(equip1);
    1.27 +			EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
    1.28 +			race.AddEquipmentItem(equip2);
    1.29 +			UnitType unitType = new UnitType("type1", "UnitType", race);
    1.30 +			unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(34, false));
    1.31 +			UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
    1.32 +			unitEquip1.SlotName = "slot";
    1.33 +			unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
    1.34 +			unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
    1.35 +			UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
    1.36 +			unitEquip2.SlotName = "slot";
    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.SetEquipmentRatio(unitEquip1, 33);
    1.44 +			unit.SetEquipmentRatio(unitEquip2, 0.7);
    1.45 +			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1));
    1.46 +		}
    1.47 +	}
    1.48 +}
    1.49 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Oct 31 20:23:09 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Nov 06 19:47:18 2011 +0000
     2.3 @@ -109,6 +109,7 @@
     2.4      <Compile Include="API\Commands\EditArmyCommandTest.cs" />
     2.5      <Compile Include="API\Factories\AbstractNativeWarFoundryFactoryTest.cs" />
     2.6      <Compile Include="API\Factories\Mock\MockNativeWarFoundryFactory.cs" />
     2.7 +    <Compile Include="API\Objects\UnitEquipmentLimitTests.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />