Mercurial > repos > IBBoard.WarFoundry.API.Tests
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 wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Tue Dec 20 20:34:48 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Tue Dec 20 21:01:46 2011 +0000 @@ -129,7 +129,7 @@ } [Test()] - [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] public void TestExceptionsForInvalidNumber() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); @@ -138,7 +138,7 @@ } [Test()] - [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] public void TestExceptionsForInvalidAllowedNumber() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); @@ -147,13 +147,139 @@ } [Test()] - [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit type 'unit1' for 'Requires N units for M units' requirement")] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1' for 'Requires N units for M units' requirement")] public void TestExceptionsForInvalidMinimumNumber() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); UnitType unitType = new UnitType("testUnit", "Test Unit", race); factory.CreateRequirement(unitType, typeID1 + ":a;3", raceFactory); } + + [Test()] + public void TestCreatesCorrectAdditiveRequirement() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectAdditiveRequirementForTwoIDs() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectAdditiveRequirementWithNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + /*[Test()] + public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(2, 3, unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2;3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + }*/ + + [Test()] + public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithTwoNumbers() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOneNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(2, unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2, unitType1); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":2|" + typeID2 + ";" + typeID1, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectAdditiveRequirementForTwoIDsWithOtherNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(3, unitType2, unitType1); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ";" + typeID1 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] + public void TestExceptionsForAdditiveRequirementWithInvalidID() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, "fibble;" + typeID1, raceFactory); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid unit type 'fibble' for 'Requires N units for M units' requirement")] + public void TestExceptionsForAdditiveRequirementWithOtherInvalidID() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, typeID1 + ";fibble", raceFactory); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] + public void TestExceptionsForAdditiveRequirementWithInvalidNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a", raceFactory); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid allowed amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] + public void TestExceptionsForAdditiveRequirementWithInvalidAllowedNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;a", raceFactory); + } + + [Test()] + [ExpectedException(typeof(InvalidRequirementException), ExpectedMessage="Invalid minimum amount 'a' for unit types 'unit1;unit2' for 'Requires N units for M units' requirement")] + public void TestExceptionsForAdditiveRequirementWithInvalidMinimumNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":a;3", raceFactory); + } } }