Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 114:4fcac7e162fe
Re #27: Unit requirements
* Add unit tests for when the unit with the prerequisite doesn't exist (requirement needn't hold)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sun, 03 Apr 2011 19:03:13 +0000 |
parents | 87cff356079d |
children | bcca07bee8ea |
files | API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun Apr 03 13:31:29 2011 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun Apr 03 19:03:13 2011 +0000 @@ -112,6 +112,16 @@ } [Test()] + public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert.That(req.AllowsAdding(unitType3, army), Is.True); + } + + [Test()] public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); @@ -136,6 +146,7 @@ public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.ValidatesArmy(army), Is.False); @@ -146,10 +157,22 @@ { Army army = new Army(mockRace, "Test", 1000); AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); Assert.That(req.ValidatesArmy(army), Is.True); } + + [Test()] + public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + Assert.That(req.ValidatesArmy(army), Is.True); + } + private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) { army.AddUnit(CreateUnitOfType(unitType, army));