Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 198:6a54d1787fbe
Re #350: Add requirement to allow N of unit for specific other units
* Add big stack of test methods to test additive requirements with allowed values other than one
* Add helper method to reduce repetition (used in new code, but not yet in old code)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Thu, 15 Dec 2011 21:00:37 +0000 |
parents | aa921248ffbf |
children | 925c37fa4feb |
files | API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs |
diffstat | 1 files changed, 125 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Wed Dec 07 21:02:13 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Thu Dec 15 21:00:37 2011 +0000 @@ -283,6 +283,123 @@ } [Test()] + public void TestAddingUnrelatedUnitWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA() + { + Army army = new Army(mockRace, "Test", 1000); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType4, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitsOfTypeToArmy(2, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingThirdUnitWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitsOfTypeToArmy(2, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitsOfTypeToArmy(5, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(2, unitType3, army); + AddUnitsOfTypeToArmy(5, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingSixthUnitWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(2, unitType2, army); + AddUnitsOfTypeToArmy(5, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, unitType2, unitType3); + Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.Empty); + } + + [Test()] + public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitsOfTypeToArmy(6, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, 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 + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7).")); + } + + [Test()] + public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(2, unitType3, army); + AddUnitsOfTypeToArmy(6, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, 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 + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7).")); + } + + [Test()] + public void TestAddingSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitsOfTypeToArmy(2, unitType2, army); + AddUnitsOfTypeToArmy(6, unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(3, 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 + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (would have 2 for 7).")); + } + + [Test()] public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() { Army army = new Army(mockRace, "Test", 1000); @@ -407,6 +524,14 @@ 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 AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army) + { + for (int i = 0; i < count; i++) + { + AddUnitOfTypeToArmy(unitType, army); + } + } + private static void AddUnitOfTypeToArmy(UnitType unitType, Army army) { army.AddUnit(CreateUnitOfType(unitType, army));