changeset 107:e2ea6562ef08

Re #27: Define unit requirements * Rename class to match behaviour (no longer just units)
author IBBoard <dev@ibboard.co.uk>
date Sun, 27 Mar 2011 19:36:31 +0000
parents 4dad874f4862
children 74bfe8b325d6
files API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 3 files changed, 126 insertions(+), 107 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 27 19:36:31 2011 +0000
     1.3 @@ -0,0 +1,124 @@
     1.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 NUnit.Framework.SyntaxHelpers;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.13 +{
    1.14 +	[TestFixture()]
    1.15 +	public class RequiresAtLeastNUnitsRequirementTest
    1.16 +	{
    1.17 +		private MockRace mockRace;
    1.18 +		private UnitType unitType1;
    1.19 +		private UnitType unitType2;
    1.20 +		private UnitType unitType3;
    1.21 +
    1.22 +		[TestFixtureSetUp()]
    1.23 +		public void SetupRace()
    1.24 +		{
    1.25 +			mockRace = MockRace.GetMockRace();
    1.26 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.27 +			mockRace.AddUnitType(unitType1);
    1.28 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.29 +			mockRace.AddUnitType(unitType2);
    1.30 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.31 +			mockRace.AddUnitType(unitType3);
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
    1.36 +		{
    1.37 +			Army army = new Army(mockRace, "Test", 1000);
    1.38 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.39 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.40 +			Assert.That(req.AllowsAdding(unit, army), Is.False);
    1.41 +		}
    1.42 +
    1.43 +		[Test()]
    1.44 +		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
    1.45 +		{
    1.46 +			Army army = new Army(mockRace, "Test", 1000);
    1.47 +			AddUnitOfTypeToArmy(unitType2, army);
    1.48 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.49 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.50 +			Assert.That(req.AllowsAdding(unit, army), Is.True);
    1.51 +		}
    1.52 +
    1.53 +		[Test()]
    1.54 +		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
    1.55 +		{
    1.56 +			Army army = new Army(mockRace, "Test", 1000);
    1.57 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.58 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.59 +		}
    1.60 +
    1.61 +		[Test()]
    1.62 +		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
    1.63 +		{
    1.64 +			Army army = new Army(mockRace, "Test", 1000);
    1.65 +			AddUnitOfTypeToArmy(unitType2, army);
    1.66 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
    1.67 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.68 +		}
    1.69 +
    1.70 +		[Test()]
    1.71 +		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
    1.72 +		{
    1.73 +			Army army = new Army(mockRace, "Test", 1000);
    1.74 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.75 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.76 +		}
    1.77 +
    1.78 +		[Test()]
    1.79 +		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
    1.80 +		{
    1.81 +			Army army = new Army(mockRace, "Test", 1000);
    1.82 +			AddUnitOfTypeToArmy(unitType2, army);
    1.83 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.84 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.85 +		}
    1.86 +
    1.87 +		[Test()]
    1.88 +		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
    1.89 +		{
    1.90 +			Army army = new Army(mockRace, "Test", 1000);
    1.91 +			AddUnitOfTypeToArmy(unitType2, army);
    1.92 +			AddUnitOfTypeToArmy(unitType3, army);
    1.93 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    1.94 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.95 +		}
    1.96 +
    1.97 +		[Test()]
    1.98 +		public void TestAddingUnitTypeWithOneUnitsAndTwoOfOneUnitTypeRequired()
    1.99 +		{
   1.100 +			Army army = new Army(mockRace, "Test", 1000);
   1.101 +			AddUnitOfTypeToArmy(unitType2, army);
   1.102 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
   1.103 +			req.AddUnitTypeRequirement(unitType2, 2);
   1.104 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
   1.105 +		}
   1.106 +
   1.107 +		[Test()]
   1.108 +		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
   1.109 +		{
   1.110 +			Army army = new Army(mockRace, "Test", 1000);
   1.111 +			AddUnitOfTypeToArmy(unitType2, army);
   1.112 +			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
   1.113 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
   1.114 +		}
   1.115 +
   1.116 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   1.117 +		{
   1.118 +			army.AddUnit(CreateUnitOfType(unitType, army));
   1.119 +		}
   1.120 +
   1.121 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   1.122 +		{
   1.123 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
   1.124 +		}
   1.125 +	}
   1.126 +}
   1.127 +
     2.1 --- a/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 27 19:19:04 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,105 +0,0 @@
     2.4 -// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     2.5 -// 
     2.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.
     2.7 -using System;
     2.8 -using NUnit.Framework;
     2.9 -using IBBoard.WarFoundry.API.Objects.Mock;
    2.10 -using NUnit.Framework.SyntaxHelpers;
    2.11 -
    2.12 -namespace IBBoard.WarFoundry.API.Objects.Requirements
    2.13 -{
    2.14 -	[TestFixture()]
    2.15 -	public class UnitRequiresAtLeastNUnitsRequirementTest
    2.16 -	{
    2.17 -		private MockRace mockRace;
    2.18 -		private UnitType unitType1;
    2.19 -		private UnitType unitType2;
    2.20 -		private UnitType unitType3;
    2.21 -
    2.22 -		[TestFixtureSetUp()]
    2.23 -		public void SetupRace()
    2.24 -		{
    2.25 -			mockRace = MockRace.GetMockRace();
    2.26 -			unitType1 = new MockUnitType("type1", "Unit Type 1");
    2.27 -			mockRace.AddUnitType(unitType1);
    2.28 -			unitType2 = new MockUnitType("type2", "Unit Type 2");
    2.29 -			mockRace.AddUnitType(unitType2);
    2.30 -			unitType3 = new MockUnitType("type3", "Unit Type 3");
    2.31 -			mockRace.AddUnitType(unitType3);
    2.32 -		}
    2.33 -
    2.34 -		[Test()]
    2.35 -		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
    2.36 -		{
    2.37 -			Army army = new Army(mockRace, "Test", 1000);
    2.38 -			Unit unit = CreateUnitOfType(unitType1, army);
    2.39 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    2.40 -			Assert.That(req.AllowsAdding(unit, army), Is.False);
    2.41 -		}
    2.42 -
    2.43 -		[Test()]
    2.44 -		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
    2.45 -		{
    2.46 -			Army army = new Army(mockRace, "Test", 1000);
    2.47 -			AddUnitOfTypeToArmy(unitType2, army);
    2.48 -			Unit unit = CreateUnitOfType(unitType1, army);
    2.49 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    2.50 -			Assert.That(req.AllowsAdding(unit, army), Is.True);
    2.51 -		}
    2.52 -
    2.53 -		[Test()]
    2.54 -		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
    2.55 -		{
    2.56 -			Army army = new Army(mockRace, "Test", 1000);
    2.57 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    2.58 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.59 -		}
    2.60 -
    2.61 -		[Test()]
    2.62 -		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
    2.63 -		{
    2.64 -			Army army = new Army(mockRace, "Test", 1000);
    2.65 -			AddUnitOfTypeToArmy(unitType2, army);
    2.66 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
    2.67 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.68 -		}
    2.69 -
    2.70 -		[Test()]
    2.71 -		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
    2.72 -		{
    2.73 -			Army army = new Army(mockRace, "Test", 1000);
    2.74 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    2.75 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.76 -		}
    2.77 -
    2.78 -		[Test()]
    2.79 -		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
    2.80 -		{
    2.81 -			Army army = new Army(mockRace, "Test", 1000);
    2.82 -			AddUnitOfTypeToArmy(unitType2, army);
    2.83 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    2.84 -			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    2.85 -		}
    2.86 -
    2.87 -		[Test()]
    2.88 -		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
    2.89 -		{
    2.90 -			Army army = new Army(mockRace, "Test", 1000);
    2.91 -			AddUnitOfTypeToArmy(unitType2, army);
    2.92 -			AddUnitOfTypeToArmy(unitType3, army);
    2.93 -			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
    2.94 -			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    2.95 -		}
    2.96 -
    2.97 -		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
    2.98 -		{
    2.99 -			army.AddUnit(CreateUnitOfType(unitType, army));
   2.100 -		}
   2.101 -
   2.102 -		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   2.103 -		{
   2.104 -			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
   2.105 -		}
   2.106 -	}
   2.107 -}
   2.108 -
     3.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Mar 27 19:19:04 2011 +0000
     3.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Mar 27 19:36:31 2011 +0000
     3.3 @@ -91,7 +91,7 @@
     3.4      <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
     3.5      <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     3.6      <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
     3.7 -    <Compile Include="API\Objects\Requirements\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
     3.8 +    <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
     3.9    </ItemGroup>
    3.10    <ItemGroup>
    3.11      <None Include="app.config" />
    3.12 @@ -343,6 +343,6 @@
    3.13      <Folder Include="API\Savers\" />
    3.14      <Folder Include="API\Savers\Xml\" />
    3.15      <Folder Include="API\" />
    3.16 -    <Folder Include="API\Objects\Requirements\" />
    3.17 +    <Folder Include="API\Objects\Requirement\" />
    3.18    </ItemGroup>
    3.19  </Project>
    3.20 \ No newline at end of file