Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 235:d122354eeebc
Re #410: N per M models in parent requirement
* Add tests for adding
* Change text on adding to make more sense (tell users N, M, and how many there are now)
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 01 Aug 2012 21:01:43 +0100 |
parents | e418ba645d06 |
children | be409428bbea |
files | API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs |
diffstat | 1 files changed, 54 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs Sun Jul 29 21:05:41 2012 +0100 +++ b/API/Objects/Requirement/UnitRequiresNParentModelsForMUnitsRequirementTests.cs Wed Aug 01 21:01:43 2012 +0100 @@ -32,6 +32,28 @@ } [Test()] + public void TestAddingUnitTypeWithParentAndTwoForOneIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 2); + AddUnitOfTypeToArmy(unitType1, army, parent); + Assert_That__PassesAdding(req, unitType1, parent, army); + } + + [Test()] + public void TestAddingUnitTypeWithParentAndOneForTwoIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType2, army); + parent.Size = 2; + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1, 2); + Assert_That__PassesAdding(req, unitType1, parent, army); + } + + [Test()] public void TestAddingUnitTypeWithWrongParentAndOneUnitTypeRequiredIsNotApplicable() { Army army = new Army(mockRace, "Test", 1000); @@ -49,7 +71,34 @@ AddUnitOfTypeToArmy(unitType1, army, parent); UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType3); - Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 1 × " + unitType1.Name + " as sub-units of each " + unitType3.Name + ", would have 2"); + string msg = String.Format("Units of type {0} can only have {1} x {2} for every {3} models, would have {4} for {5}", unitType3.Name, 1, unitType1.Name, 1, 2, 1); + Assert_That__FailsAdding(req, unitType1, parent, army, msg); + } + + [Test()] + public void TestAddingTooManyUnitTypesWithParentAndTwoForOneFails() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType3, army); + AddUnitOfTypeToArmy(unitType1, army, parent); + AddUnitOfTypeToArmy(unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType3, 2); + string msg = String.Format("Units of type {0} can only have {1} x {2} for every {3} models, would have {4} for {5}", unitType3.Name, 2, unitType1.Name, 1, 3, 1); + Assert_That__FailsAdding(req, unitType1, parent, army, msg); + } + + [Test()] + public void TestAddingTooManyUnitTypesWithParentAndOneForTwoFails() + { + Army army = new Army(mockRace, "Test", 1000); + Unit parent = AddUnitOfTypeToArmy(unitType3, army); + parent.Size = 2; + AddUnitOfTypeToArmy(unitType1, army, parent); + UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); + req.AddUnitTypeRequirement(unitType3, 1, 2); + string msg = String.Format("Units of type {0} can only have {1} x {2} for every {3} models, would have {4} for {5}", unitType3.Name, 1, unitType1.Name, 2, 2, 2); + Assert_That__FailsAdding(req, unitType1, parent, army, msg); } [Test()] @@ -60,7 +109,8 @@ AddUnitsOfTypeToArmy(5, unitType1, army, parent); UnitRequiresNParentModelsForMUnitsRequirement req = new UnitRequiresNParentModelsForMUnitsRequirement(unitType1); req.AddUnitTypeRequirement(unitType2); - Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6"); + string msg = String.Format("Units of type {0} can only have {1} x {2} for every {3} models, would have {4} for {5}", unitType2.Name, 1, unitType1.Name, 1, 6, 5); + Assert_That__FailsAdding(req, unitType1, parent, army, msg); } [Test()] @@ -73,7 +123,8 @@ req.AddUnitTypeRequirement(unitType2); Assert_That__PassesAdding(req, unitType1, parent, army); AddUnitOfTypeToArmy(unitType1, army, parent); - Assert_That__FailsAdding(req, unitType1, parent, army, "Army can only contain 5 × " + unitType1.Name + " as sub-units of each " + unitType2.Name + ", would have 6"); + string msg = String.Format("Units of type {0} can only have {1} x {2} for every {3} models, would have {4} for {5}", unitType2.Name, 1, unitType1.Name, 1, 6, 5); + Assert_That__FailsAdding(req, unitType1, parent, army, msg); } [Test()]