Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 222:12ac487af0ba
Re #395: Requirements can incorrectly allow based on common divisor
* Add tests to check for using common divisor (e.g. allowing 1 per 2 when we said allow 2 per 4)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 31 Mar 2012 15:24:41 +0100 |
parents | c40cb2048fc3 |
children | fd51527f6d64 |
files | API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs |
diffstat | 1 files changed, 84 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sat Mar 24 20:34:42 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sat Mar 31 15:24:41 2012 +0100 @@ -478,6 +478,90 @@ Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 2 for 5)."); } + [Test] + public void TestBug395RequirementShouldNotFindCommonDivisorAdding() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(4, 2, unitType2); + AddUnitsOfTypeToArmy(3, unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 3 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 4 for 3)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (would have 5 for 3)."); + AddUnitsOfTypeToArmy(3, unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestBug395RequirementShouldNotFindCommonDivisorValidating() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(4, 2, unitType2); + AddUnitsOfTypeToArmy(3, unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 3 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 4 for 3)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " for every 2 × " + unitType1.Name + " (have 5 for 3)."); + AddUnitsOfTypeToArmy(3, unitType2, army); + Assert_That__ValidationPasses(req, army); + } + + [Test] + public void TestBug395RequirementShouldNotFindCommonDivisorAddingMultiUnits() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(4, 2, unitType2, unitType3); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitsOfTypeToArmy(2, unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 3 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__PassesAdding(req, unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 4 for 3)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__FailsAdding(req, unitType1, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (would have 5 for 3)."); + AddUnitsOfTypeToArmy(3, unitType2, army); + Assert_That__PassesAdding(req, unitType1, army); + } + + [Test] + public void TestBug395RequirementShouldNotFindCommonDivisorValidatingMultiUnits() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNUnitsForMUnitsRequirement req = new UnitRequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(4, 2, unitType2, unitType3); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitsOfTypeToArmy(2, unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 3 for 1)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType1, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 4 for 3)."); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army must contain: 4 × " + unitType2.Name + " or " + unitType3.Name + " for every 2 × " + unitType1.Name + " (have 5 for 3)."); + AddUnitsOfTypeToArmy(3, unitType2, army); + Assert_That__ValidationPasses(req, army); + } + protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn) { return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn);