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 wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/RequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 27 19:36:31 2011 +0000
@@ -0,0 +1,124 @@
+// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 NUnit.Framework.SyntaxHelpers;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	[TestFixture()]
+	public class RequiresAtLeastNUnitsRequirementTest
+	{
+		private MockRace mockRace;
+		private UnitType unitType1;
+		private UnitType unitType2;
+		private UnitType unitType3;
+
+		[TestFixtureSetUp()]
+		public void SetupRace()
+		{
+			mockRace = MockRace.GetMockRace();
+			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()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.False);
+		}
+
+		[Test()]
+		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.True);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2, unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
+		{
+			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.True);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitsAndTwoOfOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement();
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresAtLeastNUnitsRequirement req = new RequiresAtLeastNUnitsRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
+		}
+
+		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
+		{
+			army.AddUnit(CreateUnitOfType(unitType, army));
+		}
+
+		private static Unit CreateUnitOfType(UnitType unitType, Army army)
+		{
+			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
+		}
+	}
+}
+
--- a/API/Objects/Requirements/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Mar 27 19:19:04 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,105 +0,0 @@
-// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 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 NUnit.Framework.SyntaxHelpers;
-
-namespace IBBoard.WarFoundry.API.Objects.Requirements
-{
-	[TestFixture()]
-	public class UnitRequiresAtLeastNUnitsRequirementTest
-	{
-		private MockRace mockRace;
-		private UnitType unitType1;
-		private UnitType unitType2;
-		private UnitType unitType3;
-
-		[TestFixtureSetUp()]
-		public void SetupRace()
-		{
-			mockRace = MockRace.GetMockRace();
-			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()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			Unit unit = CreateUnitOfType(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.False);
-		}
-
-		[Test()]
-		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			Unit unit = CreateUnitOfType(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.True);
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType3, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType2, unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
-		}
-
-		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
-		{
-			army.AddUnit(CreateUnitOfType(unitType, army));
-		}
-
-		private static Unit CreateUnitOfType(UnitType unitType, Army army)
-		{
-			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
-		}
-	}
-}
-
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Mar 27 19:19:04 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Mar 27 19:36:31 2011 +0000
@@ -91,7 +91,7 @@
     <Compile Include="API\Factories\Xml\WarFoundryXmlFactoryTests.cs" />
     <Compile Include="API\EventListeningWarFoundryLoader.cs" />
     <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
-    <Compile Include="API\Objects\Requirements\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
+    <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -343,6 +343,6 @@
     <Folder Include="API\Savers\" />
     <Folder Include="API\Savers\Xml\" />
     <Folder Include="API\" />
-    <Folder Include="API\Objects\Requirements\" />
+    <Folder Include="API\Objects\Requirement\" />
   </ItemGroup>
 </Project>
\ No newline at end of file