Mercurial > repos > IBBoard.WarFoundry.API.Tests
comparison API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs @ 232:fdebdeb52a40
Re #410: Create "N units per M models in parent unit" requirement
* Finish "adding" tests
* Add common methods for handling adding units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Jul 2012 14:17:21 +0100 |
parents | 5e03b68dd214 |
children | 99248d05ba9c |
comparison
equal
deleted
inserted
replaced
231:5e03b68dd214 | 232:fdebdeb52a40 |
---|---|
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. | 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; | 4 using System; |
5 using NUnit.Framework; | 5 using NUnit.Framework; |
6 using NUnit.Framework.SyntaxHelpers; | 6 using NUnit.Framework.SyntaxHelpers; |
7 using IBBoard.WarFoundry.API.Objects.Requirement.Context; | 7 using IBBoard.WarFoundry.API.Objects.Requirement.Context; |
8 using System.Collections.Generic; | |
8 | 9 |
9 namespace IBBoard.WarFoundry.API.Objects.Requirement | 10 namespace IBBoard.WarFoundry.API.Objects.Requirement |
10 { | 11 { |
11 [TestFixture()] | 12 [TestFixture()] |
12 public class UnitRequiresNParentModelsForMUnitsRequirementTests: AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNParentModelsForMUnitsRequirement> | 13 public class UnitRequiresNParentModelsForMUnitsRequirementTests: AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNParentModelsForMUnitsRequirement> |
43 [Test()] | 44 [Test()] |
44 public void TestAddingTooManyUnitTypesWithParentAndOneUnitTypeRequiredFails() | 45 public void TestAddingTooManyUnitTypesWithParentAndOneUnitTypeRequiredFails() |
45 { | 46 { |
46 Army army = new Army(mockRace, "Test", 1000); | 47 Army army = new Army(mockRace, "Test", 1000); |
47 Unit parent = AddUnitOfTypeToArmy(unitType3, army); | 48 Unit parent = AddUnitOfTypeToArmy(unitType3, army); |
48 Unit firstChild = AddUnitOfTypeToArmy(unitType1, army); | 49 AddUnitOfTypeToArmy(unitType1, army, parent); |
49 parent.AddContainedUnit(firstChild); | |
50 UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); | 50 UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); |
51 req.AddUnitTypeRequirement(unitType3); | 51 req.AddUnitTypeRequirement(unitType3); |
52 Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 1 × " + unitType1.Name + " as a sub-unit of each " + unitType3.Name + ", would have 2"); | 52 Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 1 × " + unitType1.Name + " as sub-units of each " + unitType3.Name + ", would have 2"); |
53 } | |
54 | |
55 [Test()] | |
56 public void TestAddingTooManyUnitTypesWithParentAndFiveUnitTypeRequiredFails() | |
57 { | |
58 Army army = new Army(mockRace, "Test", 1000); | |
59 Unit parent = AddUnitOfTypeToArmy(unitType2, army); | |
60 AddUnitsOfTypeToArmy(5, unitType1, army, parent); | |
61 UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); | |
62 req.AddUnitTypeRequirement(unitType2); | |
63 Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6"); | |
64 } | |
65 | |
66 [Test()] | |
67 public void TestAddingTooManyUnitsAtThreshold() | |
68 { | |
69 Army army = new Army(mockRace, "Test", 1000); | |
70 Unit parent = AddUnitOfTypeToArmy(unitType2, army); | |
71 AddUnitsOfTypeToArmy(4, unitType1, army, parent); | |
72 UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); | |
73 req.AddUnitTypeRequirement(unitType2); | |
74 Assert_That__PassesAdding(req, unitType1, parent, army); | |
75 AddUnitOfTypeToArmy(unitType1, army, parent); | |
76 Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6"); | |
53 } | 77 } |
54 | 78 |
55 protected override UnitRequiresNParentModelsForMUnitsRequirement CreateRequirement(UnitType requirementOn) | 79 protected override UnitRequiresNParentModelsForMUnitsRequirement CreateRequirement(UnitType requirementOn) |
56 { | 80 { |
57 return new UnitRequiresNParentModelsForMUnitsRequirement(requirementOn); | 81 return new UnitRequiresNParentModelsForMUnitsRequirement(requirementOn); |
84 Assert.That(req.GetAllowsAddingMessage(unitType, army, ctx), Is.EqualTo(message)); | 108 Assert.That(req.GetAllowsAddingMessage(unitType, army, ctx), Is.EqualTo(message)); |
85 Unit unit = CreateUnitOfType(unitType, army); | 109 Unit unit = CreateUnitOfType(unitType, army); |
86 Assert.That(req.AllowsAdding(unit, army, ctx), Is.EqualTo(Validation.Failed)); | 110 Assert.That(req.AllowsAdding(unit, army, ctx), Is.EqualTo(Validation.Failed)); |
87 Assert.That(req.GetAllowsAddingMessage(unit, army, ctx), Is.EqualTo(message)); | 111 Assert.That(req.GetAllowsAddingMessage(unit, army, ctx), Is.EqualTo(message)); |
88 } | 112 } |
113 | |
114 private Unit AddUnitOfTypeToArmy(UnitType unitType, Army army, Unit parent) | |
115 { | |
116 Unit child = AddUnitOfTypeToArmy(unitType, army); | |
117 parent.AddContainedUnit(child); | |
118 return child; | |
119 } | |
120 | |
121 private ICollection<Unit> AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army, Unit parent) | |
122 { | |
123 ICollection<Unit> units = new List<Unit>(); | |
124 | |
125 for (int i = 0; i < count; i++) | |
126 { | |
127 units.Add(AddUnitOfTypeToArmy(unitType, army, parent)); | |
128 } | |
129 | |
130 return units; | |
131 } | |
89 } | 132 } |
90 } | 133 } |
91 | 134 |