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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/AbstractRaceUnitRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     1.3 @@ -0,0 +1,49 @@
     1.4 +// This file (AbstractUnitTypeUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +using System;
     1.8 +using NUnit.Framework;
     1.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using IBBoard.WarFoundry.API.Factories.Mock;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.13 +{
    1.14 +	public abstract class AbstractRaceUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> where OBJECT_TYPE : Race where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE>
    1.15 +	{
    1.16 +		protected MockRace mockRace;
    1.17 +		protected UnitType unitType1;
    1.18 +		protected UnitType unitType2;
    1.19 +		protected UnitType unitType3;
    1.20 +
    1.21 +		[TestFixtureSetUp()]
    1.22 +		public void SetupRace()
    1.23 +		{
    1.24 +			mockRace = new MockRace();
    1.25 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.26 +			mockRace.AddUnitType(unitType1);
    1.27 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.28 +			mockRace.AddUnitType(unitType2);
    1.29 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.30 +			mockRace.AddUnitType(unitType3);
    1.31 +		}
    1.32 +
    1.33 +		public override TEST_CLASS GetObject()
    1.34 +		{
    1.35 +			return CreateRequirement(mockRace);
    1.36 +		}
    1.37 +
    1.38 +		public override TEST_CLASS GetSameObject()
    1.39 +		{
    1.40 +			return CreateRequirement(mockRace);
    1.41 +		}
    1.42 +
    1.43 +		public override TEST_CLASS GetDifferentObject()
    1.44 +		{
    1.45 +			Race race = new Race("otherrace", "Other Race", MockGameSystem.GetMockSystem(), MockSystemFactory.GetMockFactory());
    1.46 +			return CreateRequirement(race);
    1.47 +		}
    1.48 +
    1.49 +		protected abstract TEST_CLASS CreateRequirement(Race requirementOn);
    1.50 +	}
    1.51 +}
    1.52 +
     2.1 --- a/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Sun Mar 04 21:12:44 2012 +0000
     2.2 +++ b/API/Objects/Requirement/AbstractUnitRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     2.3 @@ -4,13 +4,14 @@
     2.4  using System;
     2.5  using NUnit.Framework;
     2.6  using NUnit.Framework.SyntaxHelpers;
     2.7 +using IBBoard.NUnit;
     2.8  
     2.9  namespace IBBoard.WarFoundry.API.Objects.Requirement
    2.10  {
    2.11  	/// <summary>
    2.12  	/// Base class of helper methods for checking unit requirements
    2.13  	/// </summary>
    2.14 -	public abstract class AbstractUnitRequirementTest<OBJECT_TYPE> where OBJECT_TYPE : IWarFoundryObject
    2.15 +	public abstract class AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractEqualityTest<TEST_CLASS> where OBJECT_TYPE : IWarFoundryObject where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE>
    2.16  	{
    2.17  		protected static void Assert_That__PassesAdding(AbstractUnitRequirement<OBJECT_TYPE> req, UnitType unitType, Army army)
    2.18  		{
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/API/Objects/Requirement/AbstractUnitTypeUnitRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     3.3 @@ -0,0 +1,47 @@
     3.4 +// This file (AbstractUnitTypeUnitRequirementTest.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2012 IBBoard
     3.5 +// 
     3.6 +// 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.
     3.7 +using System;
     3.8 +using NUnit.Framework;
     3.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    3.10 +
    3.11 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    3.12 +{
    3.13 +	public abstract class AbstractUnitTypeUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> : AbstractUnitRequirementTest<OBJECT_TYPE, TEST_CLASS> where OBJECT_TYPE : UnitType where TEST_CLASS : AbstractUnitRequirement<OBJECT_TYPE>
    3.14 +	{
    3.15 +		protected MockRace mockRace;
    3.16 +		protected UnitType unitType1;
    3.17 +		protected UnitType unitType2;
    3.18 +		protected UnitType unitType3;
    3.19 +
    3.20 +		[TestFixtureSetUp()]
    3.21 +		public void SetupRace()
    3.22 +		{
    3.23 +			mockRace = new MockRace();
    3.24 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    3.25 +			mockRace.AddUnitType(unitType1);
    3.26 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    3.27 +			mockRace.AddUnitType(unitType2);
    3.28 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    3.29 +			mockRace.AddUnitType(unitType3);
    3.30 +		}
    3.31 +
    3.32 +		public override TEST_CLASS GetObject()
    3.33 +		{
    3.34 +			return CreateRequirement(unitType1);
    3.35 +		}
    3.36 +
    3.37 +		public override TEST_CLASS GetSameObject()
    3.38 +		{
    3.39 +			return CreateRequirement(unitType1);
    3.40 +		}
    3.41 +
    3.42 +		public override TEST_CLASS GetDifferentObject()
    3.43 +		{
    3.44 +			return CreateRequirement(unitType2);
    3.45 +		}
    3.46 +
    3.47 +		protected abstract TEST_CLASS CreateRequirement(UnitType requirementOn);
    3.48 +	}
    3.49 +}
    3.50 +
     4.1 --- a/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 04 21:12:44 2012 +0000
     4.2 +++ b/API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     4.3 @@ -9,25 +9,8 @@
     4.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     4.5  {
     4.6  	[TestFixture()]
     4.7 -	public class RaceRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<Race>
     4.8 +	public class RaceRequiresAtLeastNUnitsRequirementTest : AbstractRaceUnitRequirementTest<Race, RaceRequiresAtLeastNUnitsRequirement>
     4.9  	{
    4.10 -		private MockRace mockRace;
    4.11 -		private UnitType unitType1;
    4.12 -		private UnitType unitType2;
    4.13 -		private UnitType unitType3;
    4.14 -
    4.15 -		[TestFixtureSetUp()]
    4.16 -		public void SetupRace()
    4.17 -		{
    4.18 -			mockRace = new MockRace();
    4.19 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    4.20 -			mockRace.AddUnitType(unitType1);
    4.21 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    4.22 -			mockRace.AddUnitType(unitType2);
    4.23 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    4.24 -			mockRace.AddUnitType(unitType3);
    4.25 -		}
    4.26 -
    4.27  		[Test()]
    4.28  		public void TestAddingUnitTypeWithNoUnitAndOneUnitTypeRequired()
    4.29  		{
    4.30 @@ -291,6 +274,11 @@
    4.31  			AddUnitOfTypeToArmy(unitType2, army);
    4.32  			Assert_That__ValidationPasses(req, army);
    4.33  		}
    4.34 +
    4.35 +		protected override RaceRequiresAtLeastNUnitsRequirement CreateRequirement(Race requirementOn)
    4.36 +		{
    4.37 +			return new RaceRequiresAtLeastNUnitsRequirement(requirementOn);
    4.38 +		}
    4.39  	}
    4.40  }
    4.41  
     5.1 --- a/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirementTest.cs	Sun Mar 04 21:12:44 2012 +0000
     5.2 +++ b/API/Objects/Requirement/RaceRequiresNoMoreThanNUnitsRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     5.3 @@ -9,25 +9,8 @@
     5.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     5.5  {
     5.6  	[TestFixture()]
     5.7 -	public class RaceRequiresNoMoreThanNUnitsRequirementTest : AbstractUnitRequirementTest<Race>
     5.8 +	public class RaceRequiresNoMoreThanNUnitsRequirementTest : AbstractRaceUnitRequirementTest<Race, RaceRequiresNoMoreThanNUnitsRequirement>
     5.9  	{
    5.10 -		private MockRace mockRace;
    5.11 -		private UnitType unitType1;
    5.12 -		private UnitType unitType2;
    5.13 -		private UnitType unitType3;
    5.14 -
    5.15 -		[TestFixtureSetUp()]
    5.16 -		public void SetupRace()
    5.17 -		{
    5.18 -			mockRace = new MockRace();
    5.19 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    5.20 -			mockRace.AddUnitType(unitType1);
    5.21 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    5.22 -			mockRace.AddUnitType(unitType2);
    5.23 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    5.24 -			mockRace.AddUnitType(unitType3);
    5.25 -		}
    5.26 -
    5.27  		[Test()]
    5.28  		public void TestAddingUnitTypeWithNoUnitAndOneUnitTypeRequired()
    5.29  		{
    5.30 @@ -302,6 +285,11 @@
    5.31  			AddUnitOfTypeToArmy(unitType2, army);
    5.32  			Assert_That__ValidationFails(req, army, "Army cannot contain more than: 1 × " + unitType2.Name + " (have 2).");
    5.33  		}
    5.34 +
    5.35 +		protected override RaceRequiresNoMoreThanNUnitsRequirement CreateRequirement(Race requirementOn)
    5.36 +		{
    5.37 +			return new RaceRequiresNoMoreThanNUnitsRequirement(requirementOn);
    5.38 +		}
    5.39  	}
    5.40  }
    5.41  
     6.1 --- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 04 21:12:44 2012 +0000
     6.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     6.3 @@ -9,25 +9,8 @@
     6.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     6.5  {
     6.6  	[TestFixture()]
     6.7 -	public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitRequirementTest<UnitType>
     6.8 +	public class UnitRequiresAtLeastNUnitsRequirementTest : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresAtLeastNUnitsRequirement>
     6.9  	{
    6.10 -		private MockRace mockRace;
    6.11 -		private UnitType unitType1;
    6.12 -		private UnitType unitType2;
    6.13 -		private UnitType unitType3;
    6.14 -
    6.15 -		[TestFixtureSetUp()]
    6.16 -		public void SetupRace()
    6.17 -		{
    6.18 -			mockRace = new MockRace();
    6.19 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    6.20 -			mockRace.AddUnitType(unitType1);
    6.21 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    6.22 -			mockRace.AddUnitType(unitType2);
    6.23 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    6.24 -			mockRace.AddUnitType(unitType3);
    6.25 -		}
    6.26 -
    6.27  		[Test()]
    6.28  		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
    6.29  		{
    6.30 @@ -280,6 +263,11 @@
    6.31  			AddUnitOfTypeToArmy(unitType2, army);
    6.32  			Assert_That__ValidationPasses(req, army);
    6.33  		}
    6.34 +
    6.35 +		protected override UnitRequiresAtLeastNUnitsRequirement CreateRequirement(UnitType requirementOn)
    6.36 +		{
    6.37 +			return new UnitRequiresAtLeastNUnitsRequirement(requirementOn);
    6.38 +		}
    6.39  	}
    6.40  }
    6.41  
     7.1 --- a/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Sun Mar 04 21:12:44 2012 +0000
     7.2 +++ b/API/Objects/Requirement/UnitRequiresNUnitsForMUnitsRequirementTests.cs	Mon Mar 05 20:34:45 2012 +0000
     7.3 @@ -9,25 +9,8 @@
     7.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     7.5  {
     7.6  	[TestFixture()]
     7.7 -	public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitRequirementTest<UnitType>
     7.8 +	public class UnitRequiresNUnitsForMUnitsRequirementTests : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNUnitsForMUnitsRequirement>
     7.9  	{
    7.10 -		private MockRace mockRace;
    7.11 -		private UnitType unitType1;
    7.12 -		private UnitType unitType2;
    7.13 -		private UnitType unitType3;
    7.14 -
    7.15 -		[TestFixtureSetUp()]
    7.16 -		public void SetupRace()
    7.17 -		{
    7.18 -			mockRace = new MockRace();
    7.19 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    7.20 -			mockRace.AddUnitType(unitType1);
    7.21 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    7.22 -			mockRace.AddUnitType(unitType2);
    7.23 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    7.24 -			mockRace.AddUnitType(unitType3);
    7.25 -		}
    7.26 -
    7.27  		[Test()]
    7.28  		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredFails()
    7.29  		{
    7.30 @@ -309,6 +292,11 @@
    7.31  			AddUnitOfTypeToArmy(unitType1, army);
    7.32  			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " for every 1 × " + unitType1.Name + " (have 1 for 2).");
    7.33  		}
    7.34 +
    7.35 +		protected override UnitRequiresNUnitsForMUnitsRequirement CreateRequirement(UnitType requirementOn)
    7.36 +		{
    7.37 +			return new UnitRequiresNUnitsForMUnitsRequirement(requirementOn);
    7.38 +		}
    7.39  	}
    7.40  }
    7.41  
     8.1 --- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sun Mar 04 21:12:44 2012 +0000
     8.2 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Mon Mar 05 20:34:45 2012 +0000
     8.3 @@ -9,25 +9,8 @@
     8.4  namespace IBBoard.WarFoundry.API.Objects.Requirement
     8.5  {
     8.6  	[TestFixture()]
     8.7 -	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitRequirementTest<UnitType>
     8.8 +	public class UnitRequiresNoMoreThanNOfUnitTypeRequirementTest : AbstractUnitTypeUnitRequirementTest<UnitType, UnitRequiresNoMoreThanNOfUnitTypeRequirement>
     8.9  	{
    8.10 -		private MockRace mockRace;
    8.11 -		private UnitType unitType1;
    8.12 -		private UnitType unitType2;
    8.13 -		private UnitType unitType3;
    8.14 -
    8.15 -		[TestFixtureSetUp()]
    8.16 -		public void SetupRace()
    8.17 -		{
    8.18 -			mockRace = new MockRace();
    8.19 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    8.20 -			mockRace.AddUnitType(unitType1);
    8.21 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    8.22 -			mockRace.AddUnitType(unitType2);
    8.23 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    8.24 -			mockRace.AddUnitType(unitType3);
    8.25 -		}
    8.26 -
    8.27  		[Test()]
    8.28  		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed()
    8.29  		{
    8.30 @@ -301,6 +284,11 @@
    8.31  			req.AddUnitTypeRequirement(unitType3);
    8.32  			Assert_That__ValidationFails(req, army, "Army cannot contain more than: 0 × " + unitType2.Name + " (have 1); 0 × " + unitType3.Name + " (have 1).");
    8.33  		}
    8.34 +
    8.35 +		protected override UnitRequiresNoMoreThanNOfUnitTypeRequirement CreateRequirement(UnitType requirementOn)
    8.36 +		{
    8.37 +			return new UnitRequiresNoMoreThanNOfUnitTypeRequirement(requirementOn);
    8.38 +		}
    8.39  	}
    8.40  }
    8.41  
     9.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Mar 04 21:12:44 2012 +0000
     9.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Mar 05 20:34:45 2012 +0000
     9.3 @@ -119,6 +119,8 @@
     9.4      <Compile Include="API\Objects\Requirement\AbstractUnitRequirementTest.cs" />
     9.5      <Compile Include="API\Objects\Requirement\RaceRequiresAtLeastNUnitsRequirementTest.cs" />
     9.6      <Compile Include="API\Objects\Requirement\RaceRequiresNoMoreThanNUnitsRequirementTest.cs" />
     9.7 +    <Compile Include="API\Objects\Requirement\AbstractUnitTypeUnitRequirementTest.cs" />
     9.8 +    <Compile Include="API\Objects\Requirement\AbstractRaceUnitRequirementTest.cs" />
     9.9    </ItemGroup>
    9.10    <ItemGroup>
    9.11      <None Include="app.config" />