view API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs @ 108:74bfe8b325d6

Re #27: Define unit requirements * Add tests where a min count > 1 is set
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Mar 2011 19:49:51 +0000
parents e2ea6562ef08
children f5f66483032a
line source
1 // This file (UnitRequiresAtLeastNUnitsRequirement.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.Objects.Mock;
7 using NUnit.Framework.SyntaxHelpers;
9 namespace IBBoard.WarFoundry.API.Objects.Requirement
10 {
11 [TestFixture()]
12 public class RequiresAtLeastNUnitsRequirementTest
13 {
14 private MockRace mockRace;
15 private UnitType unitType1;
16 private UnitType unitType2;
17 private UnitType unitType3;
19 [TestFixtureSetUp()]
20 public void SetupRace()
21 {
22 mockRace = MockRace.GetMockRace();
23 unitType1 = new MockUnitType("type1", "Unit Type 1");
24 mockRace.AddUnitType(unitType1);
25 unitType2 = new MockUnitType("type2", "Unit Type 2");
26 mockRace.AddUnitType(unitType2);
27 unitType3 = new MockUnitType("type3", "Unit Type 3");
28 mockRace.AddUnitType(unitType3);
29 }
31 [Test()]
32 public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
33 {
34 Army army = new Army(mockRace, "Test", 1000);
35 Unit unit = CreateUnitOfType(unitType1, army);
36 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
37 Assert.That(req.AllowsAdding(unit, army), Is.False);
38 }
40 [Test()]
41 public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
42 {
43 Army army = new Army(mockRace, "Test", 1000);
44 AddUnitOfTypeToArmy(unitType2, army);
45 Unit unit = CreateUnitOfType(unitType1, army);
46 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
47 Assert.That(req.AllowsAdding(unit, army), Is.True);
48 }
50 [Test()]
51 public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
52 {
53 Army army = new Army(mockRace, "Test", 1000);
54 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
55 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
56 }
58 [Test()]
59 public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
60 {
61 Army army = new Army(mockRace, "Test", 1000);
62 AddUnitOfTypeToArmy(unitType2, army);
63 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
64 Assert.That(req.AllowsAdding(unitType1, army), Is.True);
65 }
67 [Test()]
68 public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
69 {
70 Army army = new Army(mockRace, "Test", 1000);
71 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
72 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
73 }
75 [Test()]
76 public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
77 {
78 Army army = new Army(mockRace, "Test", 1000);
79 AddUnitOfTypeToArmy(unitType2, army);
80 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
81 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
82 }
84 [Test()]
85 public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
86 {
87 Army army = new Army(mockRace, "Test", 1000);
88 AddUnitOfTypeToArmy(unitType2, army);
89 AddUnitOfTypeToArmy(unitType3, army);
90 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
91 Assert.That(req.AllowsAdding(unitType1, army), Is.True);
92 }
94 [Test()]
95 public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
96 {
97 Army army = new Army(mockRace, "Test", 1000);
98 AddUnitOfTypeToArmy(unitType2, army);
99 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
100 req.AddUnitTypeRequirement(unitType2, 2);
101 Assert.That(req.AllowsAdding(unitType1, army), Is.False);
102 }
104 [Test()]
105 public void TestAddingUnitTypeWithTwoUnitAndTwoOfOneUnitTypeRequired()
106 {
107 Army army = new Army(mockRace, "Test", 1000);
108 AddUnitOfTypeToArmy(unitType2, army);
109 AddUnitOfTypeToArmy(unitType2, army);
110 RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
111 req.AddUnitTypeRequirement(unitType2, 2);
112 Assert.That(req.AllowsAdding(unitType1, army), Is.True);
113 }
115 private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
116 {
117 army.AddUnit(CreateUnitOfType(unitType, army));
118 }
120 private static Unit CreateUnitOfType(UnitType unitType, Army army)
121 {
122 return new Unit(unitType, army.GetCategory(unitType.MainCategory));
123 }
124 }
125 }