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 diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Mon Jun 13 20:04:40 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresAtLeastNUnitsRequirementFactoryTest.cs	Tue Jun 14 14:26:18 2011 +0000
     1.3 @@ -14,34 +14,99 @@
     1.4  	public class UnitRequiresAtLeastNUnitsRequirementFactoryTest
     1.5  	{
     1.6  		private static Race race;
     1.7 -		private static string typeID = "unit1";
     1.8 +		private static string typeID1 = "unit1";
     1.9 +		private static string typeID2 = "unit2";
    1.10  		private UnitType unitType1;
    1.11 +		private UnitType unitType2;
    1.12  
    1.13  		[TestFixtureSetUp()]
    1.14  		public void Setup()
    1.15  		{
    1.16  			race = new MockRace();
    1.17 -			unitType1 = new UnitType(typeID, "Unit 1", race);
    1.18 +			unitType1 = new UnitType(typeID1, "Unit 1", race);
    1.19  			race.AddUnitType(unitType1);
    1.20 +			unitType2 = new UnitType(typeID2, "Unit 2", race);
    1.21 +			race.AddUnitType(unitType2);
    1.22  		}
    1.23  
    1.24  		[Test()]
    1.25  		public void TestCreatesRequirement()
    1.26  		{
    1.27  			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.28 -			Assert.That(factory.CreateRequirement(new MockUnitType(), typeID), Is.Not.Null);
    1.29 +			Assert.That(factory.CreateRequirement(new MockUnitType(), typeID1), Is.Not.Null);
    1.30  		}
    1.31  
    1.32  		[Test()]
    1.33  		public void TestCreatesCorrectRequirement()
    1.34  		{
    1.35  			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.36 -			UnitType unitType = new UnitType("unit2", "Unit 2", race);
    1.37 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.38  			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.39  			expectedReq.AddUnitTypeRequirement(unitType1);
    1.40 -			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID);
    1.41 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1);
    1.42  			Assert.That(req, Is.EqualTo(expectedReq));
    1.43  		}
    1.44 +
    1.45 +		[Test()]
    1.46 +		public void TestCreatesCorrectRequirementForTwoIDs()
    1.47 +		{
    1.48 +			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.49 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.50 +			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.51 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.52 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.53 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2);
    1.54 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.55 +		}
    1.56 +
    1.57 +		[Test()]
    1.58 +		public void TestCreatesCorrectRequirementWithNumber()
    1.59 +		{
    1.60 +			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.61 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.62 +			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.63 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.64 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2");
    1.65 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.66 +		}
    1.67 +
    1.68 +		[Test()]
    1.69 +		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
    1.70 +		{
    1.71 +			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.72 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.73 +			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.74 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.75 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
    1.76 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2 + ":3");
    1.77 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.78 +		}
    1.79 +
    1.80 +		[Test()]
    1.81 +		public void TestCreatesCorrectRequirementForTwoIDsWithOneNumber()
    1.82 +		{
    1.83 +			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.84 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.85 +			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.86 +			expectedReq.AddUnitTypeRequirement(unitType1, 2);
    1.87 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.88 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2|" + typeID2);
    1.89 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.90 +		}
    1.91 +
    1.92 +		[Test()]
    1.93 +		public void TestCreatesCorrectRequirementForTwoIDsWithOtherNumber()
    1.94 +		{
    1.95 +			UnitRequiresAtLeastNUnitsRequirementFactory factory = new UnitRequiresAtLeastNUnitsRequirementFactory();
    1.96 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.97 +			UnitRequiresAtLeastNUnitsRequirement expectedReq = new UnitRequiresAtLeastNUnitsRequirement(unitType);
    1.98 +			expectedReq.AddUnitTypeRequirement(unitType1);
    1.99 +			expectedReq.AddUnitTypeRequirement(unitType2, 3);
   1.100 +			UnitRequiresAtLeastNUnitsRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + ":3");
   1.101 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.102 +		}
   1.103 +
   1.104 +		//TODO Test invalid data (e.g. non-number) and throw appropriate exceptions
   1.105  	}
   1.106  }
   1.107