Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 195:8e95ccb8e9d5
Re #350: Add requirement to allow N of unit for specific other units
* Add tests for multiple failures
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 03 Dec 2011 20:09:25 +0000 |
parents | f1f4df654a91 |
children | 498396c77601 |
files | API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs |
diffstat | 1 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Sat Dec 03 19:56:58 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Sat Dec 03 20:09:25 2011 +0000 @@ -116,6 +116,34 @@ } [Test()] + public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1, 1); + req.AddUnitTypeRequirement(unitType3, 1, 1); + 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: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2).")); + } + + [Test()] + public void TestAddingSecondUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2, unitType3); + 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: 1 " + unitType2.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2).")); + } + + [Test()] public void TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() { Army army = new Army(mockRace, "Test", 1000); @@ -213,6 +241,34 @@ } [Test()] + public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1, 1); + req.AddUnitTypeRequirement(unitType3, 1, 1); + 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); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2).")); + } + + [Test()] + public void TestValidatingArmyWithTwoUnitsWithOneAllowedForTwoTypesFails_ShorthandMethod() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1, unitType2, unitType3); + 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); 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2).")); + } + + [Test()] public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails() { Army army = new Army(mockRace, "Test", 1000);