comparison API/Objects/UnitEquipmentRatioSelectionTests.cs @ 183:bd38c32fb1a9

Re #366: Rewrite equipment handling and limits * Remove comment added during #356 - now resolved * Add test for behaviour of percentages * Add test for new "calculate number taken" util method
author IBBoard <dev@ibboard.co.uk>
date Sat, 12 Nov 2011 20:36:58 +0000
parents
children e173c5512067
comparison
equal deleted inserted replaced
182:e9be63d72b3c 183:bd38c32fb1a9
1 // This file (UnitEquipmentRatioSelectionTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
2 //
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.
4 using System;
5 using NUnit.Framework;
6 using IBBoard.WarFoundry.API.Util;
7 using IBBoard.WarFoundry.API.Factories;
8 using IBBoard.Limits;
9 using NUnit.Framework.SyntaxHelpers;
10
11 namespace IBBoard.WarFoundry.API.Objects
12 {
13 [TestFixture()]
14 public class UnitEquipmentRatioSelectionTests
15 {
16 [Test()]
17 public void Bug366TestAmountIsNotLimitedByAbsoluteAmount()
18 {
19 DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
20 Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory);
21 Category cat = new Category("cat1", "Category");
22 race.AddCategory(cat);
23 EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race);
24 race.AddEquipmentItem(equip1);
25 EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race);
26 race.AddEquipmentItem(equip2);
27 UnitType unitType = new UnitType("type1", "UnitType", race);
28 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(33, true));
29 UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType);
30 unitEquip1.SlotName = "slot";
31 unitEquip1.RoundNumberUp = true;
32 unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0);
33 unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
34 UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType);
35 unitEquip2.SlotName = "slot";
36 unitEquip2.RoundNumberUp = true;
37 unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0);
38 unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true);
39 race.AddUnitType(unitType);
40 Army army = new Army(race, "army", 1000);
41 Unit unit = new Unit(unitType, army.GetCategory(cat));
42 unit.Size = 3;
43 unit.SetEquipmentAmount(unitEquip1, 1);
44 unit.SetEquipmentRatio(unitEquip2, 33);
45 Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(33));
46 Assert.That(UnitEquipmentUtil.GetEquipmentAmountTaken(unit, unitEquip2), Is.EqualTo(1));
47 Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
48 }
49 }
50 }
51