changeset 132:8f1af48e120c

Re #27: Unit requirements * Add unit test for unit requirements in opposite order * Add unit test to make sure that requirement doesn't lock to first result, even after changes Also: * Clean up line endings to meet policy
author IBBoard <dev@ibboard.co.uk>
date Sun, 17 Apr 2011 19:34:48 +0000
parents 5ede1c0a1454
children f64742dde5f9
files API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs
diffstat 1 files changed, 236 insertions(+), 213 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Apr 16 19:49:22 2011 +0000
+++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sun Apr 17 19:34:48 2011 +0000
@@ -1,213 +1,236 @@
-// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
-// 
-// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
-using System;
-using NUnit.Framework;
-using IBBoard.WarFoundry.API.Objects.Mock;
-using NUnit.Framework.SyntaxHelpers;
-
-namespace IBBoard.WarFoundry.API.Objects.Requirement
-{
-	[TestFixture()]
-	public class UnitRequiresAtLeastNUnitsRequirementTest
-	{
-		private MockRace mockRace;
-		private UnitType unitType1;
-		private UnitType unitType2;
-		private UnitType unitType3;
-
-		[TestFixtureSetUp()]
-		public void SetupRace()
-		{
-			mockRace = new MockRace();
-			unitType1 = new MockUnitType("type1", "Unit Type 1");
-			mockRace.AddUnitType(unitType1);
-			unitType2 = new MockUnitType("type2", "Unit Type 2");
-			mockRace.AddUnitType(unitType2);
-			unitType3 = new MockUnitType("type3", "Unit Type 3");
-			mockRace.AddUnitType(unitType3);
-		}
-
-		[Test()]
-		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			Unit unit = CreateUnitOfType(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			Unit unit = CreateUnitOfType(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType3, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			req.AddUnitTypeRequirement(unitType3);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
-		}
-
-		[Test()]
-		public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			AddUnitOfTypeToArmy(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test()]
-		public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType2, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
-		}
-
-		[Test]
-		public void TestSatisfyingRequirementChangesResult()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
-			AddUnitOfTypeToArmy(unitType2, army);
-			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
-		}
-
-		[Test]
-		public void TestAddingMinNumberUnitTypePassesRequirement()
-		{
-			Army army = new Army(mockRace, "Test", 1000);
-			AddUnitOfTypeToArmy(unitType1, army);
-			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			req.AddUnitTypeRequirement(unitType2, 2);
-			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
-			AddUnitOfTypeToArmy(unitType2, army);
-			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
-		}
-
-
-		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
-		{
-			army.AddUnit(CreateUnitOfType(unitType, army));
-		}
-
-
-		private static Unit CreateUnitOfType(UnitType unitType, Army army)
-		{
-			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
-		}
-	}
-}
-
+// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
+// 
+// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
+using System;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Objects.Mock;
+using NUnit.Framework.SyntaxHelpers;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	[TestFixture()]
+	public class UnitRequiresAtLeastNUnitsRequirementTest
+	{
+		private MockRace mockRace;
+		private UnitType unitType1;
+		private UnitType unitType2;
+		private UnitType unitType3;
+
+		[TestFixtureSetUp()]
+		public void SetupRace()
+		{
+			mockRace = new MockRace();
+			unitType1 = new MockUnitType("type1", "Unit Type 1");
+			mockRace.AddUnitType(unitType1);
+			unitType2 = new MockUnitType("type2", "Unit Type 2");
+			mockRace.AddUnitType(unitType2);
+			unitType3 = new MockUnitType("type3", "Unit Type 3");
+			mockRace.AddUnitType(unitType3);
+		}
+
+		[Test()]
+		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			Unit unit = CreateUnitOfType(unitType1, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOtherOneUnitAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType3, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType3, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			req.AddUnitTypeRequirement(unitType3);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestAddingUnrelatedUnitTypeIsAllowedWhenRequirementsNotMet()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType3, army), Is.EqualTo(Validation.NotApplicable));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestAddingUnitTypeMakesRequirementPass()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed));
+			AddUnitOfTypeToArmy(unitType2, army);
+			Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+		}
+
+		[Test()]
+		public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			AddUnitOfTypeToArmy(unitType1, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test()]
+		public void TestValidityOfArmyWhenNoRequireeAndRequirementNotMet()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType2, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.NotApplicable));
+		}
+
+		[Test]
+		public void TestSatisfyingRequirementChangesResult()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Failed));
+			AddUnitOfTypeToArmy(unitType2, army);
+			Assert.That(req.ValidatesArmy(army), Is.EqualTo(Validation.Passed));
+		}
+
+		[Test]
+		public void TestAddingMinNumberUnitTypePassesRequirement()
+		{
+			Army army = new Army(mockRace, "Test", 1000);
+			AddUnitOfTypeToArmy(unitType1, army);
+			RequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			req.AddUnitTypeRequirement(unitType2, 2);
+			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Failed));
+			AddUnitOfTypeToArmy(unitType2, army);
+			Assert.That(req.AllowsAdding(unitType2, army), Is.EqualTo(Validation.Passed));
+		}
+
+
+		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
+		{
+			army.AddUnit(CreateUnitOfType(unitType, army));
+		}
+
+
+		private static Unit CreateUnitOfType(UnitType unitType, Army army)
+		{
+			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
+		}
+	}
+}
+