changeset 121:6f46fa3c47e5

Re #27: Unit requirements * Test threshold * Test that default setting is 0 * Test that "No more than" requirement gives "N/A" when appropriate
author IBBoard <dev@ibboard.co.uk>
date Sat, 09 Apr 2011 10:18:27 +0000
parents d186d46f0bae
children aa37b31976e6
files API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Wed Apr 06 20:05:04 2011 +0000
+++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs	Sat Apr 09 10:18:27 2011 +0000
@@ -90,15 +90,38 @@
 		}
 
 		[Test()]
+		public void TestAddingUnitTriggersFailure()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 1);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+			AddUnitOfTypeToArmy(unitType2, army);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
 		public void TestAddingUnitTypeDefaultsToNoMoreThanZero()
 		{
 			Army army = new Army(mockRace, "Test", 1000);
 			AddUnitOfTypeToArmy(unitType2, army);
 			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
 			req.AddUnitTypeRequirement(unitType2);
 			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
 		}
 
+		[Test]
+		public void TestRequirementNotApplicableWhenLimitedUnitNotIncluded()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
+			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.NotApplicable));
+		}
+
 		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
 		{
 			army.AddUnit(CreateUnitOfType(unitType, army));