changeset 192:f25cb069f700

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests for having requirements on more than one unit type
author IBBoard <dev@ibboard.co.uk>
date Sat, 03 Dec 2011 16:41:54 +0000
parents 2b19d6f18f3a
children cf1c0a91eaa9
files API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs
diffstat 1 files changed, 56 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 16:13:38 2011 +0000
+++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Sat Dec 03 16:41:54 2011 +0000
@@ -63,6 +63,19 @@
 		}
 
 		[Test()]
+		public void TestAddingOneUnitWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 0 for 1)."));
+		}
+
+		[Test()]
 		public void TestAddingTwoUnitsWithOneUnitTypeRequiredAndOneUnitOfTypeFails()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
@@ -88,6 +101,21 @@
 		}
 
 		[Test()]
+		public void TestAddingTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType3, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 1, 2);
+			req.AddUnitTypeRequirement(unitType3, 1, 1);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetAllowsAddingMessage(unit.UnitType, army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (would have 1 for 2)."));
+		}
+
+		[Test()]
 		public void TestAddingThreeUnitsWithTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
@@ -132,6 +160,19 @@
 		}
 
 		[Test()]
+		public void TestValidatingArmyWithTwoDifferentUnitTypesRequiredAndNoUnitOfOneTypeFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 0 for 1)."));
+		}
+
+		[Test()]
 		public void TestValidatingArmyWithTwoUnitsAndOneUnitTypeRequiredAndOneUnitOfTypeFails()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
@@ -157,6 +198,21 @@
 		}
 
 		[Test()]
+		public void TestValidatingArmyWithTwoUnitsWithTwoAllowedAndOneAllowedForDifferentTypesFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType3, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 1, 2);
+			req.AddUnitTypeRequirement(unitType3, 1, 1);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType3.Name + " for every 1 " + unitType1.Name + " (have 1 for 2)."));
+		}
+
+		[Test()]
 		public void TestValidatingArmyWithThreeUnitsAndTwoOfUnitTypeAllowedForOneUnitTypeRequiredAndOneUnitOfTypeFails()
 		{
 			Army army = new Army(mockRace, "Test", 1000);