diff API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs @ 199:925c37fa4feb

Re #350: Add requirement to allow N of unit for specific other units * Add unit tests for validating army, based on adding unit tests
author IBBoard <dev@ibboard.co.uk>
date Tue, 20 Dec 2011 20:34:48 +0000
parents 6a54d1787fbe
children 49e50238c380
line wrap: on
line diff
--- a/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Thu Dec 15 21:00:37 2011 +0000
+++ b/API/Objects/Requirement/RequiresNUnitsForMUnitsRequirementTest.cs	Tue Dec 20 20:34:48 2011 +0000
@@ -524,6 +524,115 @@
 			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " for every 2 " + unitType1.Name + " (have 1 for 3)."));
 		}
 
+		[Test()]
+		public void TestValidatingArmyWithNoUnitsAndThreeForEachTwoCombinedUnitTypesRequiredIsNA()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType4, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOneTypePasses()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitsOfTypeToArmy(3, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithThreeUnitsWithThreeForEachTwoUnitTypeComboRequiredAndUnitOfOtherTypePasses()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType3, army);
+			AddUnitsOfTypeToArmy(3, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesPasses()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType3, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitsOfTypeToArmy(6, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypePasses()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitsOfTypeToArmy(2, unitType3, army);
+			AddUnitsOfTypeToArmy(6, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSixUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypePasses()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitsOfTypeToArmy(2, unitType2, army);
+			AddUnitsOfTypeToArmy(6, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+			Assert.That(req.GetValidationMessage(army), Is.Empty);
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndOneUnitOfBothTypesFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType3, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitsOfTypeToArmy(7, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOneTypeFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitsOfTypeToArmy(2, unitType3, army);
+			AddUnitsOfTypeToArmy(7, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
+		}
+
+		[Test()]
+		public void TestValidatingArmyWithSevenUnitsWithThreeForEachTwoUnitTypeComboRequiredAndTwoUnitsOfOtherTypeFails()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitsOfTypeToArmy(2, unitType2, army);
+			AddUnitsOfTypeToArmy(7, unitType1, army);
+			RequiresNUnitsForMUnitsRequirement req = new RequiresNUnitsForMUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(3, unitType2, unitType3);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			Assert.That(req.GetValidationMessage(army), Is.EqualTo("Army must contain: 1 " + unitType2.Name + " or " + unitType3.Name + " for every 3 " + unitType1.Name + " (have 2 for 7)."));
+		}
+
 		private static void AddUnitsOfTypeToArmy(int count, UnitType unitType, Army army)
 		{
 			for (int i = 0; i < count; i++)