Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 201:43b571aa4124
Re #350: Add requirement to allow N of unit for specific other units
* Add tests on factory for different combinations of additive and non-additive requirements
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Fri, 23 Dec 2011 14:52:22 +0000 |
parents | 6a0a0e228e3c |
children | 49e50238c380 |
files | API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs |
diffstat | 1 files changed, 174 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Tue Dec 20 21:01:46 2011 +0000 +++ b/API/Factories/Requirement/UnitRequiresNUnitsForMUnitsRequirementFactoryTest.cs Fri Dec 23 14:52:22 2011 +0000 @@ -17,8 +17,10 @@ private static Race race; private static string typeID1 = "unit1"; private static string typeID2 = "unit2"; + private static string typeID3 = "unit3"; private static UnitType unitType1; private static UnitType unitType2; + private static UnitType unitType3; private static MockRaceFactory raceFactory = new MockRaceFactory(); [TestFixtureSetUp()] @@ -29,6 +31,8 @@ race.AddUnitType(unitType1); unitType2 = new UnitType(typeID2, "Unit 2", race); race.AddUnitType(unitType2); + unitType3 = new UnitType(typeID3, "Unit 3", race); + race.AddUnitType(unitType3); } [Test()] @@ -62,6 +66,19 @@ } [Test()] + public void TestCreatesCorrectRequirementForThreeIDs() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1); + expectedReq.AddUnitTypeRequirement(unitType2); + expectedReq.AddUnitTypeRequirement(unitType3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + "|" + typeID2 + "|" + typeID3, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] public void TestCreatesCorrectRequirementWithNumber() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); @@ -167,6 +184,17 @@ } [Test()] + public void TestCreatesCorrectTripleAdditiveRequirement() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2, unitType3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ";" + typeID3, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] public void TestCreatesCorrectAdditiveRequirementForTwoIDs() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); @@ -189,7 +217,7 @@ Assert.That(req, Is.EqualTo(expectedReq)); } - /*[Test()] + [Test()] public void TestCreatesCorrectAdditiveRequirementWithTwoNumbers() { UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); @@ -198,7 +226,7 @@ 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() @@ -237,6 +265,150 @@ } [Test()] + public void TestCreatesCorrectRequirementForOneIDAndOneAdditive() + { + 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 TestCreatesCorrectRequirementForOneIDAndOneAdditiveInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType2); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditive() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDAndOneAdditiveWithNumberInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType2); + expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + "|" + typeID1 + ";" + typeID2 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditive() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(3, 2, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + "|" + typeID2 + ":3;2", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(3, 2, unitType2); + expectedReq.AddUnitTypeRequirement(unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2, raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowed() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3;2|" + typeID2 + ":3", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithNumberAndOneAdditiveWithMinAndAllowedInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType2, 3); + expectedReq.AddUnitTypeRequirement(3, 2, unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3|" + typeID1 + ";" + typeID2 + ":3;2", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumber() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); + expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); + IRequirement req = factory.CreateRequirement(unitType, typeID1 + ";" + typeID2 + ":3|" + typeID2 + ":3;2", raceFactory); + Assert.That(req, Is.EqualTo(expectedReq)); + } + + [Test()] + public void TestCreatesCorrectRequirementForOneIDWithMinAndAllowedAndOneAdditiveWithNumberInOtherOrder() + { + UnitRequiresNUnitsForMUnitsRequirementFactory factory = new UnitRequiresNUnitsForMUnitsRequirementFactory(); + UnitType unitType = new UnitType("testUnit", "Test Unit", race); + RequiresNUnitsForMUnitsRequirement expectedReq = new RequiresNUnitsForMUnitsRequirement(unitType); + expectedReq.AddUnitTypeRequirement(unitType2, 3, 2); + expectedReq.AddUnitTypeRequirement(3, unitType1, unitType2); + IRequirement req = factory.CreateRequirement(unitType, typeID2 + ":3;2|" + typeID1 + ";" + typeID2 + ":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() {