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 wrap: on
line diff
--- a/API/Objects/UnitEquipmentLimitTests.cs	Sat Nov 12 20:49:11 2011 +0000
+++ b/API/Objects/UnitEquipmentLimitTests.cs	Sun Nov 13 20:14:36 2011 +0000
@@ -7,6 +7,7 @@
 using IBBoard.Limits;
 using NUnit.Framework.SyntaxHelpers;
 using IBBoard.WarFoundry.API.Util;
+using IBBoard.CustomMath;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
@@ -51,6 +52,39 @@
 			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
 			Assert.That(unit.Points, Is.EqualTo(35));
 		}
+
+		[Test]
+		public void TestBug366CheckExtraEquipmentAllowed()
+		{
+			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.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);
+			Army army = new Army(race, "army", 1000);
+			Unit unit = new Unit(unitType, army.GetCategory(cat));
+			unit.Size = 3;
+			unit.SetEquipmentAmount(unitEquip1, 1);
+			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(1));
+			Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0));
+			Assert.That(UnitEquipmentUtil.GetMaxEquipmentPercentage(unit, unitEquip2), Is.EqualTo(34 - IBBMath.Percentage(1, 3)));
+		}
 	}
 }