Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
annotate API/Objects/UnitEquipmentRatioSelectionTests.cs @ 210:649759343da5
Re #379: Fix validation of requirements to check for unit
* Tidy up tests to reduce replication and fix copy-and-paste inconsistencies
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 25 Feb 2012 16:36:20 +0000 |
parents | bd38c32fb1a9 |
children | e173c5512067 |
rev | line source |
---|---|
183
bd38c32fb1a9
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 |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
2 // |
bd38c32fb1a9
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. |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
4 using System; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
5 using NUnit.Framework; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
6 using IBBoard.WarFoundry.API.Util; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
7 using IBBoard.WarFoundry.API.Factories; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
8 using IBBoard.Limits; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
9 using NUnit.Framework.SyntaxHelpers; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
10 |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
11 namespace IBBoard.WarFoundry.API.Objects |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
12 { |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
13 [TestFixture()] |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
14 public class UnitEquipmentRatioSelectionTests |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
15 { |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
16 [Test()] |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
17 public void Bug366TestAmountIsNotLimitedByAbsoluteAmount() |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
18 { |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
19 DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); |
bd38c32fb1a9
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); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
21 Category cat = new Category("cat1", "Category"); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
22 race.AddCategory(cat); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
23 EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
24 race.AddEquipmentItem(equip1); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
25 EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
26 race.AddEquipmentItem(equip2); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
27 UnitType unitType = new UnitType("type1", "UnitType", race); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
28 unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(33, true)); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
29 UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
30 unitEquip1.SlotName = "slot"; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
31 unitEquip1.RoundNumberUp = true; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
32 unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
33 unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
34 UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
35 unitEquip2.SlotName = "slot"; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
36 unitEquip2.RoundNumberUp = true; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
37 unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
38 unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
39 race.AddUnitType(unitType); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
40 Army army = new Army(race, "army", 1000); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
41 Unit unit = new Unit(unitType, army.GetCategory(cat)); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
42 unit.Size = 3; |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
43 unit.SetEquipmentAmount(unitEquip1, 1); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
44 unit.SetEquipmentRatio(unitEquip2, 33); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
45 Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(33)); |
bd38c32fb1a9
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)); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
47 Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2)); |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
48 } |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
49 } |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
50 } |
bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
IBBoard <dev@ibboard.co.uk>
parents:
diff
changeset
|
51 |