Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 219:f951595143a9
Re #394: Make requirements (or factory) more closely match Rollcall methods
* Add unit tests that match text
* "N for M" factory already handled "2,X|Y" (format: "X;Y:2" - "X|Y" is equivalent to Rollcall's "1,X,1,Y")
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 24 Mar 2012 16:46:06 +0000 |
parents | d60d93b787dc |
children | 0fa634c6391b |
files | API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs |
diffstat | 2 files changed, 98 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs Tue Mar 06 20:32:19 2012 +0000 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sat Mar 24 16:46:06 2012 +0000 @@ -58,6 +58,14 @@ Assert.That(req.GetValidationMessage(army), Is.EqualTo(message)); } + protected static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army) + { + for (int i = 0; i < count; i++) + { + AddUnitOfTypeToArmy(unitType, army); + } + } + protected static void AddUnitOfTypeToArmy(UnitType unitType, Army army) { army.AddUnit(CreateUnitOfType(unitType, army));
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Tue Mar 06 20:32:19 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sat Mar 24 16:46:06 2012 +0000 @@ -151,6 +151,96 @@ } [Test] + public void TestRequirementWithOR() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, unitType3); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestRequirementWithORWithOtherUnit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, unitType3); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestRequirementWithORWithLimit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestRequirementWithORWithLimitWithOtherUnit() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestRequirementWithORWithLimitWithBothUnits() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(2, 1, unitType2, unitType3); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 0 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 2 × " + unitType2.Name + " or " + unitType3.Name + " for every 1 × " + unitType1.Name + " (would have 1 for 1)."); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__PassesAdding(req, unitType1, 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(9, unitType1, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would 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(3, unitType1, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 2 for 5)."); + } + + [Test] public void TestValidationNotApplicableWithNoLimitedUnit() { Army army = new Army(mockRace, "Test", 1000);