Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 213:0416df2ab39b
Re #379: Fix validation of requirements to check for unit
* Add army validation tests for UnitRequiresNoMoreThanNOfUnitTypeRequirementTest
TODO: one test broken (should be NA, not Passed)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 26 Feb 2012 15:38:13 +0000 |
parents | 325943cb1db0 |
children | 1674a499168e |
files | API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs |
diffstat | 1 files changed, 131 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Feb 26 15:20:48 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Feb 26 15:38:13 2012 +0000 @@ -193,6 +193,137 @@ req.AddUnitTypeRequirement(unitType3); Assert_That__FailsAdding(req, unitType2, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (would have 1); 0 × " + unitType3.Name + " (would have 1)."); } + + [Test()] + public void TestValidatingWithNoUnitsAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationPasses(req, army); + } + + [Test()] + public void TestValidatingWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."); + } + + [Test()] + public void TestValidatingUnitTypeSetsLimit() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert_That__ValidationPasses(req, army); + } + + [Test()] + public void TestSetsLimitForValidationFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (have 2)."); + } + + [Test()] + public void TestAddingUnitTriggersValidationFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (have 2)."); + } + + [Test()] + public void TestValidationUnitTypeDefaultsToNoMoreThanZero() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."); + } + + [Test] + public void TestRequirementValidationNotApplicableWhenAddingUnrelatedTypes() + { + Army army = new Army(mockRace, "Test", 1000); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + AddUnitOfTypeToArmy(unitType3, army); + Assert_That__NotApplicable(req, army); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__NotApplicable(req, army); + } + + [Test()] + public void TestAddingRequirementUnitTriggersValidationFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationPasses(req, army); + AddUnitOfTypeToArmy(unitType2, army); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (have 2)."); + } + + [Test] + public void TestValidationFailsWithTwoUnitTypesProhibitedAndOneUnitTypeInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1)."); + } + + [Test] + public void TestValidationFailsWithTwoUnitTypesProhibitedAndOneOfOtherUnitTypeInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType3, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType3.Name + " (have 1)."); + } + + [Test] + public void TestValidationFailsWithTwoUnitTypesProhibitedAndOneUnitTypeAlreadyInArmy() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + UnitRequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType3); + Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1)."); + } } }