Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 202:49e50238c380
Re #350: Add requirement to allow N of unit for specific other units
* Add unit tests to make sure we handle required values other than 1 (e.g. "need 2 for every 3") properly
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 23 Dec 2011 15:33:53 +0000 |
parents | 43b571aa4124 |
children | 2b27447ae74e |
files | API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs |
diffstat | 1 files changed, 74 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Fri Dec 23 14:52:22 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Fri Dec 23 15:33:53 2011 +0000 @@ -161,6 +161,44 @@ } [Test()] + public void TestAddingOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 1 for 1).")); + } + + [Test()] + public void TestAddingSecondUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 1 for 2).")); + } + + [Test()] + public void TestAddingFourthUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(3, unitType2, army); + AddUnitsOfTypeToArmy(3, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (would have 3 for 4).")); + } + + [Test()] public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA() { Army army = new Army(mockRace, "Test", 1000); @@ -511,6 +549,42 @@ } [Test()] + public void TestValidatingArmyWithOneUnitWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 1 for 1).")); + } + + [Test()] + public void TestValidatingArmyWithTwoUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitsOfTypeToArmy(2, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 1 for 2).")); + } + + [Test()] + public void TestValidatingArmyWithFourUnitsWithThreeOfUnitTypeAllowedForTwoOfUnitTypeRequiredAndThreeUnitsOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(3, unitType2, army); + AddUnitsOfTypeToArmy(4, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2, 3); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 2 " + unitType2.Name + " for every 3 " + unitType1.Name + " (have 3 for 4).")); + } + + [Test()] public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() { Army army = new Army(mockRace, "Test", 1000);