changeset 151:60de02ce78d8

Re #351: Add extensible requirement handling method * Test multiple unit types and limit amounts Still needs to test invalid data and partially loaded races (which is where it'll be used most)
author IBBoard <dev@ibboard.co.uk>
date Tue, 14 Jun 2011 14:26:18 +0000
parents b86955aa252c
children dd283afa5971
files API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs
diffstat 1 files changed, 70 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Mon Jun 13 20:04:40 2011 +0000
+++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Tue Jun 14 14:26:18 2011 +0000
@@ -14,34 +14,99 @@
 	public class UnitRequiresAtLeastNUnitsRequirementFactoryTest
 	{
 		private static Race race;
-		private static string typeID = "unit1";
+		private static string typeID1 = "unit1";
+		private static string typeID2 = "unit2";
 		private UnitType unitType1;
+		private UnitType unitType2;
 
 		[TestFixtureSetUp()]
 		public void Setup()
 		{
 			race = new MockRace();
-			unitType1 = new UnitType(typeID, "Unit 1", race);
+			unitType1 = new UnitType(typeID1, "Unit 1", race);
 			race.AddUnitType(unitType1);
+			unitType2 = new UnitType(typeID2, "Unit 2", race);
+			race.AddUnitType(unitType2);
 		}
 
 		[Test()]
 		public void TestCreatesRequirement()
 		{
 			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
-			Assert.That(factory.CreateRequirement(new MockUnitType(), typeID), Is.Not.Null);
+			Assert.That(factory.CreateRequirement(new MockUnitType(), typeID1), Is.Not.Null);
 		}
 
 		[Test()]
 		public void TestCreatesCorrectRequirement()
 		{
 			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
-			UnitType unitType = new UnitType("unit2", "Unit 2", race);
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDs()
+		{
+			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
 			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
 			expectedReq.AddUnitTypeRequirement(unitType1);
-			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID);
+			expectedReq.AddUnitTypeRequirement(unitType2);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementWithNumber()
+		{
+			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2");
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
+		{
+			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			expectedReq.AddUnitTypeRequirement(unitType2, 3);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3");
 			Assert.That(req, Is.EqualTo(expectedReq));
 		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
+		{
+			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1, 2);
+			expectedReq.AddUnitTypeRequirement(unitType2);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2);
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		[Test()]
+		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
+		{
+			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
+			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
+			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			expectedReq.AddUnitTypeRequirement(unitType1);
+			expectedReq.AddUnitTypeRequirement(unitType2, 3);
+			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3");
+			Assert.That(req, Is.EqualTo(expectedReq));
+		}
+
+		//TODO Test invalid data (e.g. non-number) and throw appropriate exceptions
 	}
 }