annotate API/Objects/UnitEquipmentNumericSelectionTests.cs @ 227:d8cd6b259a9f

Re #359: Add "only contained" attribute to unit types * Test to make sure sub-units are removed from the army
author IBBoard <dev@ibboard.co.uk>
date Mon, 16 Apr 2012 20:45:45 +0100
parents 00ea622313be
children e173c5512067
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
184
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 // This file (UnitEquipmentRatioSelectionTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 //
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 // 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.
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 using System;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 using NUnit.Framework;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 using IBBoard.WarFoundry.API.Util;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 using IBBoard.WarFoundry.API.Factories;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 using IBBoard.Limits;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 using NUnit.Framework.SyntaxHelpers;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 namespace IBBoard.WarFoundry.API.Objects
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
12 {
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 [TestFixture()]
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 public class UnitEquipmentNumericSelectionTests
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 {
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 [Test()]
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 public void Bug366TestAmountIsNotLimitedByRatioAmount()
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 {
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 Category cat = new Category("cat1", "Category");
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 race.AddCategory(cat);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 race.AddEquipmentItem(equip1);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 race.AddEquipmentItem(equip2);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 UnitType unitType = new UnitType("type1", "UnitType", race);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(33, true));
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 unitEquip1.SlotName = "slot";
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 unitEquip1.RoundNumberUp = true;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 unitEquip2.SlotName = "slot";
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 unitEquip2.RoundNumberUp = true;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
37 unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 race.AddUnitType(unitType);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 Army army = new Army(race, "army", 1000);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 Unit unit = new Unit(unitType, army.GetCategory(cat));
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 unit.Size = 3;
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 unit.SetEquipmentAmount(unitEquip2, 1);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 unit.SetEquipmentRatio(unitEquip1, 33);
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(1));
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 Assert.That(UnitEquipmentUtil.GetEquipmentAmountTaken(unit, unitEquip2), Is.EqualTo(1));
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 }
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 }
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 }
00ea622313be Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51