Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 220:0fa634c6391b
Re #394: Make requirements (or factory) more closely match Rollcall methods
* Add matching unit tests for validation
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Mar 2012 19:32:47 +0000 |
parents | f951595143a9 |
children | c40cb2048fc3 |
files | API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs |
diffstat | 1 files changed, 102 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sat Mar 24 16:46:06 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sat Mar 24 19:32:47 2012 +0000 @@ -151,7 +151,7 @@ } [Test] - public void TestRequirementWithOR() + public void TestAddingRequirementWithOR() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -162,7 +162,7 @@ } [Test] - public void TestRequirementWithORWithOtherUnit() + public void TestAddingRequirementWithORWithOtherUnit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -173,7 +173,7 @@ } [Test] - public void TestRequirementWithORWithLimit() + public void TestAddingRequirementWithORWithLimit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -186,7 +186,7 @@ } [Test] - public void TestRequirementWithORWithLimitWithOtherUnit() + public void TestAddingRequirementWithORWithLimitWithOtherUnit() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -199,7 +199,7 @@ } [Test] - public void TestRequirementWithORWithLimitWithBothUnits() + public void TestAddingRequirementWithORWithLimitWithBothUnits() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -212,7 +212,7 @@ } [Test] - public void TestRequirementWithORBasedOnRollcall() + public void TestAddingRequirementWithORBasedOnRollcall() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -226,7 +226,7 @@ } [Test] - public void TestRequirementWithoutORBasedOnRollcall() + public void TestAddingRequirementWithoutORBasedOnRollcall() { Army army = new Army(mockRace, "Test", 1000); UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); @@ -383,6 +383,101 @@ Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2)."); } + [Test] + public void TestRequirementWithOR() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, unitType3); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestRequirementWithORWithOtherUnit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, unitType3); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestRequirementWithORWithLimit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestRequirementWithORWithLimitWithOtherUnit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestRequirementWithORWithLimitWithBothUnits() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (have 1 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestRequirementWithORBasedOnRollcall() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, unitType2, unitType3); + AddUnitsOfTypeToArmy(3, unitType2, army); + AddUnitsOfTypeToArmy(2, unitType3, army); + AddUnitsOfTypeToArmy(10, unitType1, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 5 for 11)."); + } + + [Test] + public void TestRequirementWithoutORBasedOnRollcall() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, unitType2); + req.AddUnitTypeRequirement(2, unitType3); + AddUnitsOfTypeToArmy(3, unitType2, army); + AddUnitsOfTypeToArmy(2, unitType3, army); + AddUnitsOfTypeToArmy(4, unitType1, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 2 for 5)."); + } + protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn) { return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn);