changeset 194:f1f4df654a91

Re #350: Add requirement to allow N of unit for specific other units * Add tests for defining minimum amount as well as allowed amount (e.g. "2 of these allow 3 of those")
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Dec 2011 19:56:58 +0000
parents cf1c0a91eaa9
children 8e95ccb8e9d5
files API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs
diffstat 1 files changed, 30 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Sat Dec 03 16:53:36 2011 +0000
     1.2 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs	Sat Dec 03 19:56:58 2011 +0000
     1.3 @@ -73,6 +73,17 @@
     1.4  		}
     1.5  
     1.6  		[Test()]
     1.7 +		public void TestCreatesCorrectRequirementWithTwoNumbers()
     1.8 +		{
     1.9 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.10 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.11 +			RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType);
    1.12 +			expectedReq.AddUnitTypeRequirement(unitType1, 2, 3);
    1.13 +			IRequirement req = factory.CreateRequirement(unitType, typeID1 + ":2;3", raceFactory);
    1.14 +			Assert.That(req, Is.EqualTo(expectedReq));
    1.15 +		}
    1.16 +
    1.17 +		[Test()]
    1.18  		public void TestCreatesCorrectRequirementForTwoIDsWithTwoNumbers()
    1.19  		{
    1.20  			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.21 @@ -118,13 +129,31 @@
    1.22  		}
    1.23  
    1.24  		[Test()]
    1.25 -		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.26 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.27  		public void TestExceptionsForInvalidNumber()
    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", raceFactory);
    1.32  		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.36 +		public void TestExceptionsForInvalidAllowedNumber()
    1.37 +		{
    1.38 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.39 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.40 +			factory.CreateRequirement(unitType, typeID1 + ":3;a", raceFactory);
    1.41 +		}
    1.42 +
    1.43 +		[Test()]
    1.44 +		[ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")]
    1.45 +		public void TestExceptionsForInvalidMinimumNumber()
    1.46 +		{
    1.47 +			UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory();
    1.48 +			UnitType unitType = new UnitType("testUnit", "Test Unit", race);
    1.49 +			factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory);
    1.50 +		}
    1.51  	}
    1.52  }
    1.53