changeset 200:6a0a0e228e3c

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests for additive requirements Still need tests to make sure mixing additive with non-additive is handled correctly
author IBBoard <dev@ibboard.co.uk>
date Tue, 20 Dec 2011 21:01:46 +0000
parents 925c37fa4feb
children 43b571aa4124
files API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs
diffstat 1 files changed, 129 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Tue Dec 20 20:34:48 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Tue Dec 20 21:01:46 2011 +0000
     1.3 @@ -129,7 +129,7 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
     1.8 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")]
     1.9  		public void TestExceptionsForInvalidNumber()
    1.10  		{
    1.11  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.12 @@ -138,7 +138,7 @@
    1.13  		}
    1.14  
    1.15  		[Test()]
    1.16 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.17 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")]
    1.18  		public void TestExceptionsForInvalidAllowedNumber()
    1.19  		{
    1.20  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.21 @@ -147,13 +147,139 @@
    1.22  		}
    1.23  
    1.24  		[Test()]
    1.25 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.26 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")]
    1.27  		public void TestExceptionsForInvalidMinimumNumber()
    1.28  		{
    1.29  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.30  			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.31  			factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory);
    1.32  		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestCreatesCorrectAdditiveRequirement()
    1.36 +		{
    1.37 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.38 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.39 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.40 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
    1.41 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory);
    1.42 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.43 +		}
    1.44 +
    1.45 +		[Test()]
    1.46 +		public void TestCreatesCorrectAdditiveRequirementForTwoIDs()
    1.47 +		{
    1.48 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.49 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.50 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.51 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
    1.52 +			expectedReq.AddUnitTypeRequirement(unitType2);
    1.53 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory);
    1.54 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.55 +		}
    1.56 +
    1.57 +		[Test()]
    1.58 +		public void TestCreatesCorrectAdditiveRequirementWithNumber()
    1.59 +		{
    1.60 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.61 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.62 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.63 +			expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2);
    1.64 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory);
    1.65 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.66 +		}
    1.67 +
    1.68 +		/*[Test()]
    1.69 +		public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers()
    1.70 +		{
    1.71 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.72 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.73 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.74 +			expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2);
    1.75 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory);
    1.76 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.77 +		}*/
    1.78 +
    1.79 +		[Test()]
    1.80 +		public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers()
    1.81 +		{
    1.82 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.83 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.84 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.85 +			expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2);
    1.86 +			expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1);
    1.87 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1 + ":3", raceFactory);
    1.88 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.89 +		}
    1.90 +
    1.91 +		[Test()]
    1.92 +		public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOneNumber()
    1.93 +		{
    1.94 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.95 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.96 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.97 +			expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2);
    1.98 +			expectedReq.AddUnitTypeRequirement(unitType2, unitType1);
    1.99 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1, raceFactory);
   1.100 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.101 +		}
   1.102 +
   1.103 +		[Test()]
   1.104 +		public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOtherNumber()
   1.105 +		{
   1.106 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.107 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.108 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
   1.109 +			expectedReq.AddUnitTypeRequirement(unitType1, unitType2);
   1.110 +			expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1);
   1.111 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory);
   1.112 +			Assert.That(req, Is.EqualTo(expectedReq));
   1.113 +		}
   1.114 +
   1.115 +		[Test()]
   1.116 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")]
   1.117 +		public void TestExceptionsForAdditiveRequirementWithInvalidID()
   1.118 +		{
   1.119 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.120 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.121 +			factory.CreateRequirement(unitType, "fibble;" + typeID1, raceFactory);
   1.122 +		}
   1.123 +
   1.124 +		[Test()]
   1.125 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")]
   1.126 +		public void TestExceptionsForAdditiveRequirementWithOtherInvalidID()
   1.127 +		{
   1.128 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.129 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.130 +			factory.CreateRequirement(unitType, typeID1 + ";fibble", raceFactory);
   1.131 +		}
   1.132 +
   1.133 +		[Test()]
   1.134 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")]
   1.135 +		public void TestExceptionsForAdditiveRequirementWithInvalidNumber()
   1.136 +		{
   1.137 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.138 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.139 +			factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a", raceFactory);
   1.140 +		}
   1.141 +
   1.142 +		[Test()]
   1.143 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")]
   1.144 +		public void TestExceptionsForAdditiveRequirementWithInvalidAllowedNumber()
   1.145 +		{
   1.146 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.147 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.148 +			factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;a", raceFactory);
   1.149 +		}
   1.150 +
   1.151 +		[Test()]
   1.152 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")]
   1.153 +		public void TestExceptionsForAdditiveRequirementWithInvalidMinimumNumber()
   1.154 +		{
   1.155 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
   1.156 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
   1.157 +			factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a;3", raceFactory);
   1.158 +		}
   1.159  	}
   1.160  }
   1.161