Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 217:9bf34e88da89
Re #379: Fix validation of requirements to check for unit
* Add equality tests to try to resolve UnitType tests for limits as requirements
* Ensure consistency with extra layer in hierarchy
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Mon, 05 Mar 2012 20:34:45 +0000 |
parents | 442bcf7306b9 |
children | d60d93b787dc |
files | API/Objects/Requirement/AbstractRaceUnitRequirementTest.cs API/Objects/Requirement/AbstractUnitRequirementTest.cs API/Objects/Requirement/AbstractUnitTypeUnitRequirementTest.cs API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 9 files changed, 130 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/AbstractRaceUnitRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -0,0 +1,49 @@ +// This file (AbstractUnitTypeUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using NUnit.Framework; +using IBBoard.WarFoundry.API.Objects.Mock; +using IBBoard.WarFoundry.API.Factories.Mock; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + public abstract class AbstractRaceUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> where OBJECT_TYPE : Race where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE> + { + protected MockRace mockRace; + protected UnitType unitType1; + protected UnitType unitType2; + protected UnitType unitType3; + + [TestFixtureSetUp()] + public void SetupRace() + { + mockRace = new MockRace(); + unitType1 = new MockUnitType("type1", "Unit Type 1"); + mockRace.AddUnitType(unitType1); + unitType2 = new MockUnitType("type2", "Unit Type 2"); + mockRace.AddUnitType(unitType2); + unitType3 = new MockUnitType("type3", "Unit Type 3"); + mockRace.AddUnitType(unitType3); + } + + public override TEST_CLASS GetObject() + { + return CreateRequirement(mockRace); + } + + public override TEST_CLASS GetSameObject() + { + return CreateRequirement(mockRace); + } + + public override TEST_CLASS GetDifferentObject() + { + Race race = new Race("otherrace", "Other Race", MockGameSystem.GetMockSystem(), MockSystemFactory.GetMockFactory()); + return CreateRequirement(race); + } + + protected abstract TEST_CLASS CreateRequirement(Race requirementOn); + } +} +
--- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -4,13 +4,14 @@ using System; using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; +using IBBoard.NUnit; namespace IBBoard.WarFoundry.API.Objects.Requirement { /// <summary> /// Base class of helper methods for checking unit requirements /// </summary> - public abstract class AbstractUnitRequirementTest<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject + public abstract class AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractEqualityTest<TEST_CLASS> where OBJECT_TYPE : IWarFoundryObject where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE> { protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/AbstractUnitTypeUnitRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -0,0 +1,47 @@ +// This file (AbstractUnitTypeUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. +using System; +using NUnit.Framework; +using IBBoard.WarFoundry.API.Objects.Mock; + +namespace IBBoard.WarFoundry.API.Objects.Requirement +{ + public abstract class AbstractUnitTypeUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> where OBJECT_TYPE : UnitType where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE> + { + protected MockRace mockRace; + protected UnitType unitType1; + protected UnitType unitType2; + protected UnitType unitType3; + + [TestFixtureSetUp()] + public void SetupRace() + { + mockRace = new MockRace(); + unitType1 = new MockUnitType("type1", "Unit Type 1"); + mockRace.AddUnitType(unitType1); + unitType2 = new MockUnitType("type2", "Unit Type 2"); + mockRace.AddUnitType(unitType2); + unitType3 = new MockUnitType("type3", "Unit Type 3"); + mockRace.AddUnitType(unitType3); + } + + public override TEST_CLASS GetObject() + { + return CreateRequirement(unitType1); + } + + public override TEST_CLASS GetSameObject() + { + return CreateRequirement(unitType1); + } + + public override TEST_CLASS GetDifferentObject() + { + return CreateRequirement(unitType2); + } + + protected abstract TEST_CLASS CreateRequirement(UnitType requirementOn); + } +} +
--- a/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -9,25 +9,8 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class RaceRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<Race> + public class RaceRequiresAtLeastNUnitsRequirementTest : AbstractRaceUnitRequirementTest<Race, RaceRequiresAtLeastNUnitsRequirement> { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - unitType1 = new MockUnitType("type1", "Unit Type 1"); - mockRace.AddUnitType(unitType1); - unitType2 = new MockUnitType("type2", "Unit Type 2"); - mockRace.AddUnitType(unitType2); - unitType3 = new MockUnitType("type3", "Unit Type 3"); - mockRace.AddUnitType(unitType3); - } - [Test()] public void TestAddingUnitTypeWithNoUnitAndOneUnitTypeRequired() { @@ -291,6 +274,11 @@ AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationPasses(req, army); } + + protected override RaceRequiresAtLeastNUnitsRequirement CreateRequirement(Race requirementOn) + { + return new RaceRequiresAtLeastNUnitsRequirement(requirementOn); + } } }
--- a/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirementTest.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -9,25 +9,8 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class RaceRequiresNoMoreThanNUnitsRequirementTest : AbstractUnitRequirementTest<Race> + public class RaceRequiresNoMoreThanNUnitsRequirementTest : AbstractRaceUnitRequirementTest<Race, RaceRequiresNoMoreThanNUnitsRequirement> { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - unitType1 = new MockUnitType("type1", "Unit Type 1"); - mockRace.AddUnitType(unitType1); - unitType2 = new MockUnitType("type2", "Unit Type 2"); - mockRace.AddUnitType(unitType2); - unitType3 = new MockUnitType("type3", "Unit Type 3"); - mockRace.AddUnitType(unitType3); - } - [Test()] public void TestAddingUnitTypeWithNoUnitAndOneUnitTypeRequired() { @@ -302,6 +285,11 @@ AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationFails(req, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (have 2)."); } + + protected override RaceRequiresNoMoreThanNUnitsRequirement CreateRequirement(Race requirementOn) + { + return new RaceRequiresNoMoreThanNUnitsRequirement(requirementOn); + } } }
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -9,25 +9,8 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<UnitType> + public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresAtLeastNUnitsRequirement> { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - unitType1 = new MockUnitType("type1", "Unit Type 1"); - mockRace.AddUnitType(unitType1); - unitType2 = new MockUnitType("type2", "Unit Type 2"); - mockRace.AddUnitType(unitType2); - unitType3 = new MockUnitType("type3", "Unit Type 3"); - mockRace.AddUnitType(unitType3); - } - [Test()] public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired() { @@ -280,6 +263,11 @@ AddUnitOfTypeToArmy(unitType2, army); Assert_That__ValidationPasses(req, army); } + + protected override UnitRequiresAtLeastNUnitsRequirement CreateRequirement(UnitType requirementOn) + { + return new UnitRequiresAtLeastNUnitsRequirement(requirementOn); + } } }
--- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs Mon Mar 05 20:34:45 2012 +0000 @@ -9,25 +9,8 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitRequirementTest<UnitType> + public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNUnitsForMUnitsRequirement> { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - unitType1 = new MockUnitType("type1", "Unit Type 1"); - mockRace.AddUnitType(unitType1); - unitType2 = new MockUnitType("type2", "Unit Type 2"); - mockRace.AddUnitType(unitType2); - unitType3 = new MockUnitType("type3", "Unit Type 3"); - mockRace.AddUnitType(unitType3); - } - [Test()] public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredFails() { @@ -309,6 +292,11 @@ AddUnitOfTypeToArmy(unitType1, army); Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2)."); } + + protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn) + { + return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn); + } } }
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Sun Mar 04 21:12:44 2012 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Mon Mar 05 20:34:45 2012 +0000 @@ -9,25 +9,8 @@ namespace IBBoard.WarFoundry.API.Objects.Requirement { [TestFixture()] - public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitRequirementTest<UnitType> + public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNoMoreThanNOfUnitTypeRequirement> { - private MockRace mockRace; - private UnitType unitType1; - private UnitType unitType2; - private UnitType unitType3; - - [TestFixtureSetUp()] - public void SetupRace() - { - mockRace = new MockRace(); - unitType1 = new MockUnitType("type1", "Unit Type 1"); - mockRace.AddUnitType(unitType1); - unitType2 = new MockUnitType("type2", "Unit Type 2"); - mockRace.AddUnitType(unitType2); - unitType3 = new MockUnitType("type3", "Unit Type 3"); - mockRace.AddUnitType(unitType3); - } - [Test()] public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() { @@ -301,6 +284,11 @@ req.AddUnitTypeRequirement(unitType3); Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1)."); } + + protected override UnitRequiresNoMoreThanNOfUnitTypeRequirement CreateRequirement(UnitType requirementOn) + { + return new UnitRequiresNoMoreThanNOfUnitTypeRequirement(requirementOn); + } } }
--- a/IBBoard.WarFoundry.API.Tests.csproj Sun Mar 04 21:12:44 2012 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Mon Mar 05 20:34:45 2012 +0000 @@ -119,6 +119,8 @@ <Compile Include="API\Objects\Requirement\AbstractUnitRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\RaceRequiresAtLeastNUnitsRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\RaceRequiresNoMoreThanNUnitsRequirementTest.cs" /> + <Compile Include="API\Objects\Requirement\AbstractUnitTypeUnitRequirementTest.cs" /> + <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />