Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 197:aa921248ffbf
Re #350: Add requirement to allow N of unit for specific other units
* Add initial unit tests for handling multiple additive unit types
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 07 Dec 2011 21:02:13 +0000 |
parents | 498396c77601 |
children | 6a54d1787fbe |
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 Sun Dec 04 20:52:24 2011 +0000 +++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs Wed Dec 07 21:02:13 2011 +0000 @@ -18,6 +18,7 @@ private UnitType unitType1; private UnitType unitType2; private UnitType unitType3; + private UnitType unitType4; [TestFixtureSetUp()] public void SetupRace() @@ -29,6 +30,8 @@ mockRace.AddUnitType(unitType2); unitType3 = new MockUnitType("type3", "Unit Type 3"); mockRace.AddUnitType(unitType3); + unitType4 = new MockUnitType("type4", "Unit Type 4"); + mockRace.AddUnitType(unitType4); } [Test()] @@ -158,6 +161,128 @@ } [Test()] + public void TestAddingUnrelatedUnitWithNoUnitsAndTwoCombinedUnitTypesRequiredIsNA() + { + Army army = new Army(mockRace, "Test", 1000); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOneTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingOneUnitWithTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingTwoUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 1 " + unitType1.Name + " (would have 2 for 3).")); + } + + [Test()] + public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 1 " + unitType1.Name + " (would have 2 for 3).")); + } + + [Test()] + public void TestAddingThreeUnitsWithTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); + AddUnitOfTypeToArmy(unitType1, army); + RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(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 1 " + unitType1.Name + " (would have 2 for 3).")); + } + + [Test()] public void TestValidatingArmyWithNoUnitsAndOneUnitTypeRequiredIsNA() { Army army = new Army(mockRace, "Test", 1000);