Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 233:99248d05ba9c
Re #410: Create "N units per M models in parent unit" requirement
* Add "add unit" test helper method that sets a unit name
* Add validation tests
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 29 Jul 2012 15:29:43 +0100 |
parents | fdebdeb52a40 |
children | e418ba645d06 |
files | API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs |
diffstat | 2 files changed, 75 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sun Jul 29 14:17:21 2012 +0100 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sun Jul 29 15:29:43 2012 +0100 @@ -78,6 +78,14 @@ return unit; } + protected static Unit AddUnitOfTypeToArmy(UnitType unitType, Army army, string name) + { + Unit unit = AddUnitOfTypeToArmy(unitType, army); + unit.Name = name; + return unit; + + } + protected static Unit CreateUnitOfType(UnitType unitType, Army army) { return new Unit(unitType, army.GetCategory(unitType.MainCategory));
--- a/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs Sun Jul 29 14:17:21 2012 +0100 +++ b/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs Sun Jul 29 15:29:43 2012 +0100 @@ -76,6 +76,73 @@ Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6"); } + [Test()] + public void TestValidatingUnitTypeWithNoParentAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__NotApplicable(req, army); + } + + [Test()] + public void TestValidatingUnitTypeWithParentAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationPasses(req, army); + } + + [Test()] + public void TestValidatingUnitTypeWithWrongParentAndOneUnitTypeRequiredIsNotApplicable() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType3); + Assert_That__NotApplicable(req, army); + } + + [Test()] + public void TestValidatingTooManyUnitTypesWithParentAndOneUnitTypeRequiredFails() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType3, army, "TheParent"); + AddUnitsOfTypeToArmy(2, unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType3); + Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType3.Name + ": TheParent has 2 for 1."); + } + + [Test()] + public void TestValidatingTooManyUnitTypesWithParentAndFiveUnitTypeRequiredFails() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army, "TheParent"); + AddUnitsOfTypeToArmy(6, unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType2.Name + ": TheParent has 6 for 5."); + } + + [Test()] + public void TestValidatingTooManyUnitsAtThreshold() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army, "TheParent"); + AddUnitsOfTypeToArmy(5, unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army, parent); + Assert_That__ValidationFails(req, army, "Army can only contain 1 × " + unitType1.Name + " for every 1 model in a parent unit of " + unitType2.Name + ": TheParent has 6 for 5."); + } + protected override UnitRequiresNParentModelsForMUnitsRequirement CreateRequirement(UnitType requirementOn) { return new UnitRequiresNParentModelsForMUnitsRequirement(requirementOn);