Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 130:7fa4d5215afe
Re #27: Unit requirements
* Initial rebuild of tests so that we check for "N/A" in more of the appropriate cases for adding units
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 09 Apr 2011 19:54:10 +0000 |
parents | 95dac00e9330 |
children | 5ede1c0a1454 |
files | API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs |
diffstat | 1 files changed, 44 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs Sat Apr 09 19:13:42 2011 +0000 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs Sat Apr 09 19:54:10 2011 +0000 @@ -29,38 +29,56 @@ } [Test()] - public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() + public void TestAddingUnrelatedUnitWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); Unit unit = CreateUnitOfType(unitType1, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.NotApplicable)); + } + + [Test()] + public void TestAddingOneUnitWithOneUnitTypeRequired() + { + Army army = new Army(mockRace, "Test", 1000); + Unit unit = CreateUnitOfType(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); } [Test()] - public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired() + public void TestAddingUnitWithOneUnitAndTwoOfUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); + req.AddUnitTypeRequirement(unitType1, 2); + AddUnitOfTypeToArmy(unitType1, army); Unit unit = CreateUnitOfType(unitType1, army); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestAddingUnrelatedUnitTypeWithNoUnitsAndOneUnitTypeRequired() + { + Army army = new Army(mockRace, "Test", 1000); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); - Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.NotApplicable)); } [Test()] public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } [Test()] public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); + AddUnitOfTypeToArmy(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -69,16 +87,16 @@ { Army army = new Army(mockRace, "Test", 1000); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); } [Test()] public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType3, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); } [Test()] @@ -88,27 +106,25 @@ AddUnitOfTypeToArmy(unitType2, army); AddUnitOfTypeToArmy(unitType3, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3); - Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); } [Test()] - public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() + public void TestAddingOneOfUnitTypeWithTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); - req.AddUnitTypeRequirement(unitType2, 2); + req.AddUnitTypeRequirement(unitType1, 2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); } [Test()] - public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired() + public void TestAddingOneUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType1, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); - req.AddUnitTypeRequirement(unitType2, 2); + req.AddUnitTypeRequirement(unitType1, 2); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -116,9 +132,8 @@ public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); - req.AddUnitTypeRequirement(unitType2); + req.AddUnitTypeRequirement(unitType1); Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } @@ -126,7 +141,7 @@ public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed)); } @@ -134,8 +149,8 @@ public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired() { Army army = new Army(mockRace, "Test", 1000); - AddUnitOfTypeToArmy(unitType2, army); - RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2); + AddUnitOfTypeToArmy(unitType1, army); + RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType1); Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed)); } @@ -144,10 +159,10 @@ { Army army = new Army(mockRace, "Test", 1000); RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(); - req.AddUnitTypeRequirement(unitType2, 2); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed)); - AddUnitOfTypeToArmy(unitType2, army); - Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed)); + req.AddUnitTypeRequirement(unitType1, 2); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + AddUnitOfTypeToArmy(unitType1, army); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); } private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)