changeset 234:e418ba645d06

Re #410: Create "N units per M models in parent unit" requirement * Add tests, based on NUnitsForMUnits requirement factory TODO: * Test new methods on adding to requirement properly (e.g. multiple requirements for multi-parentage don't break things) * Test loading from XML (manually?)
author IBBoard <dev@ibboard.co.uk>
date Sun, 29 Jul 2012 21:05:41 +0100
parents 99248d05ba9c
children d122354eeebc
files API/Factories/Requirement/UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 177 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Factories/Requirement/UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs	Sun Jul 29 21:05:41 2012 +0100
@@ -0,0 +1,176 @@
+// This file (UnitUnitRequiresNParentModelsForMUnitsRequirementFactoryTest.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;
+using IBBoard.WarFoundry.API.Objects;
+using IBBoard.WarFoundry.API.Objects.Requirement;
+using IBBoard.WarFoundry.API.Factories.Mock;
+
+namespace IBBoard.WarFoundry.API.Factories.Requirement
+{
+	[TestFixture()]
+	public class UnitRequiresNParentModelsForMUnitsRequirementFactoryTest
+	{
+		private static Race race;
+		private static string typeID1 = "unit1";
+		private static string typeID2 = "unit2";
+		private static string typeID3 = "unit3";
+		private static UnitType unitType1;
+		private static UnitType unitType2;
+		private static UnitType unitType3;
+		private static MockRaceFactory raceFactory = new MockRaceFactory();
+
+		[TestFixtureSetUp()]
+		public void Setup()
+		{
+			race = new MockRace();
+			unitType1 = new UnitType(typeID1, "Unit 1", race);
+			race.AddUnitType(unitType1);
+			unitType2 = new UnitType(typeID2, "Unit 2", race);
+			race.AddUnitType(unitType2);
+			unitType3 = new UnitType(typeID3, "Unit 3", race);
+			race.AddUnitType(unitType3);
+		}
+
+		[Test()]
+		public void TestCreatesRequirement()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			Assert.That(factory.CreateRequirement(unitType2, typeID1, raceFactory), Is.Not.Null);
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirement()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1, raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDs()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			expectedReq.AddUnitTypeRequirement(unitType2);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2, raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForThreeIDs()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			expectedReq.AddUnitTypeRequirement(unitType2);
+			expectedReq.AddUnitTypeRequirement(unitType3);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + "|" + typeID3, raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementWithNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2", raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementWithTwoNumbers()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2, 3);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2;3", raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			expectedReq.AddUnitTypeRequirement(unitType2, 3);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3", raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			expectedReq.AddUnitTypeRequirement(unitType2);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2, raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresNParentModelsForMUnitsRequirement expectedReq = new UnitRequiresNParentModelsForMUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			expectedReq.AddUnitTypeRequirement(unitType2, 3);
+			IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3", raceFactory);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N models in parent unit for M units' requirement")]
+		public void TestExceptionsForInvalidID()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			factory.CreateRequirement(unitType, "fibble", raceFactory);
+		}
+
+		[Test()]
+		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
+		public void TestExceptionsForInvalidNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			factory.CreateRequirement(unitType, typeID1 + ":a", raceFactory);
+		}
+
+		[Test()]
+		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid model amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
+		public void TestExceptionsForInvalidAllowedNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			factory.CreateRequirement(unitType, typeID1 + ":3;a", raceFactory);
+		}
+
+		[Test()]
+		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N models in parent unit for M units' requirement")]
+		public void TestExceptionsForInvalidMinimumNumber()
+		{
+			UnitRequiresNParentModelsForMUnitsRequirementFactory factory = new UnitRequiresNParentModelsForMUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory);
+		}
+	}
+}
+
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Jul 29 15:29:43 2012 +0100
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sun Jul 29 21:05:41 2012 +0100
@@ -128,6 +128,7 @@
     <Compile Include="API\Loading\LoadableObjectSourceDirectoryTests.cs" />
     <Compile Include="API\Factories\Mock\MockRaceAndSystemFactory.cs" />
     <Compile Include="API\Objects\Requirement\UnitRequiresNParentModelsForMUnitsRequirementTests.cs" />
+    <Compile Include="API\Factories\Requirement\UnitRequiresNParentModelsForMUnitsRequirementFactoryTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />