Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 190:702a0957f9e4
Re #350: Add requirement to allow N of unit for specific other units
* Add army validation tests
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 30 Nov 2011 21:05:54 +0000 |
parents | eea440e5891b |
children | 2b19d6f18f3a |
files | API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs |
diffstat | 1 files changed, 69 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Wed Nov 30 20:45:12 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Wed Nov 30 21:05:54 2011 +0000 @@ -101,6 +101,75 @@ Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3).")); } + [Test()] + public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() + { + Army army = new Army(mockRace, "Test", 1000); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable)); + Assert.That(req.GetValidationMessage(army), Is.Empty); + } + + [Test()] + public void TestValidatingArmyWithOneUnitTypeRequiredAndOneUnitOfTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetValidationMessage(army), Is.Empty); + } + + [Test()] + public void TestValidatingArmyWithOneUnitTypeRequiredAndNoUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 0 for 1).")); + } + + [Test()] + public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (have 1 for 2).")); + } + + [Test()] + public void TestValidatingArmyWithTwoUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1, 2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetValidationMessage(army), Is.Empty); + } + + [Test()] + public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1, 2); + Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); + Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3).")); + } + private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) { army.AddUnit(CreateUnitOfType(unitType, army));