changeset 137:081b48413f6d

Re #140: Add equality methods to WarFoundry objects * Add equality to Race, GameSystem and UnitType tests * Create equality test for UnitCountRequirementData Not all tests pass yet
author IBBoard <dev@ibboard.co.uk>
date Tue, 26 Apr 2011 15:03:46 +0000
parents d28c3c1ec1ec
children 11faab6c712a
files API/Objects/GameSystemTest.cs API/Objects/RaceTests.cs API/Objects/Requirement/UnitCountRequirementDataTest.cs API/Objects/UnitTypeTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 5 files changed, 330 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/API/Objects/GameSystemTest.cs	Mon Apr 25 15:09:54 2011 +0000
+++ b/API/Objects/GameSystemTest.cs	Tue Apr 26 15:03:46 2011 +0000
@@ -2,12 +2,59 @@
 using NUnit.Framework;
 using IBBoard.WarFoundry.API.Factories;
 using NUnit.Framework.SyntaxHelpers;
+using System.Reflection;
+using IBBoard.NUnit;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
 	[TestFixture()]
-	public class GameSystemTest
+	public class GameSystemTest : AbstractEqualityTest<GameSystem>
 	{
+		//FIXME We shouldn't duplicate these tests, but it is broken at the moment
+		[Test]
+		public void TestEquality()
+		{
+			Assert.AreEqual(GetObject(), GetSameObject());
+			Assert.AreEqual(GetSameObject(), GetObject());
+		}
+
+		[Test]
+		public void TestInequality()
+		{
+			Assert.AreNotEqual(GetObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetSameObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetSameObject());
+		}
+
+		[Test]
+		public void TestReflexiveEquality()
+		{
+			Assert.AreEqual(GetObject(), GetObject());
+			Assert.AreEqual(GetSameObject(), GetSameObject());
+			Assert.AreEqual(GetDifferentObject(), GetDifferentObject());
+		}
+
+		[Test]
+		public void TestOtherInequality()
+		{
+			MethodInfo[] methodInfo = GetType().GetMethods();
+			GameSystem obj = GetObject();
+
+			foreach (MethodInfo method in methodInfo)
+			{
+				if (method.Name.StartsWith("GetOtherDifferent"))
+				{
+					GameSystem otherObj = (GameSystem)method.Invoke(this, new object[0]);
+					Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name);
+					Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name);
+				}
+			}
+		}
+
+
+
+
 		[Test()]
 		public void TestPointsSingularAbbreviation ()
 		{
@@ -121,6 +168,24 @@
 			system.SystemPtsAbbrevSingle = "pt";
 			Assert.That(system.GetPointsAbbrev(0), Is.EqualTo("pt"));
 		}
+
+		public override GameSystem GetObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			return new GameSystem("system", "system", factory);
+		}
+
+		public override GameSystem GetSameObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			return new GameSystem("system", "system", factory);
+		}
+
+		public override GameSystem GetDifferentObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			return new GameSystem("system2", "another system", factory);
+		}
 	}
 }
 
--- a/API/Objects/RaceTests.cs	Mon Apr 25 15:09:54 2011 +0000
+++ b/API/Objects/RaceTests.cs	Tue Apr 26 15:03:46 2011 +0000
@@ -1,64 +1,133 @@
-// This file (RaceTests.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
+// This file (RaceTests.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;
-using IBBoard.WarFoundry.API.Objects.Requirement;
-using System.Collections.Generic;
+using NUnit.Framework;
+using IBBoard.WarFoundry.API.Objects.Mock;
+using NUnit.Framework.SyntaxHelpers;
+using IBBoard.WarFoundry.API.Objects.Requirement;
+using System.Collections.Generic;
+using IBBoard.NUnit;
+using System.Reflection;
+using IBBoard.WarFoundry.API.Factories;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
 	[TestFixture()]
-	public class RaceTests
+	public class RaceTests : AbstractEqualityTest<Race>
 	{
+		//FIXME We shouldn't duplicate these tests, but it is broken at the moment
+		[Test]
+		public void TestEquality()
+		{
+			Assert.AreEqual(GetObject(), GetSameObject());
+			Assert.AreEqual(GetSameObject(), GetObject());
+		}
+
+		[Test]
+		public void TestInequality()
+		{
+			Assert.AreNotEqual(GetObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetSameObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetSameObject());
+		}
+
+		[Test]
+		public void TestReflexiveEquality()
+		{
+			Assert.AreEqual(GetObject(), GetObject());
+			Assert.AreEqual(GetSameObject(), GetSameObject());
+			Assert.AreEqual(GetDifferentObject(), GetDifferentObject());
+		}
+
+		[Test]
+		public void TestOtherInequality()
+		{
+			MethodInfo[] methodInfo = GetType().GetMethods();
+			Race obj = GetObject();
+
+			foreach (MethodInfo method in methodInfo)
+			{
+				if (method.Name.StartsWith("GetOtherDifferent"))
+				{
+					Race otherObj = (Race)method.Invoke(this, new object[0]);
+					Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name);
+					Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name);
+				}
+			}
+		}
+
+
+
+
 		[Test()]
 		public void TestRaceWithNoUnitTypesHasNoRequirements()
-		{
+		{
 			Assert.That(new MockRace().GetRequirements(), Has.Count(0));
-		}
-
-		[Test()]
-		public void TestRaceWithOneUnitTypeHasNoRequirements()
-		{
-			MockRace race = new MockRace();
-			race.AddUnitType(new MockUnitType());
-			Assert.That(race.GetRequirements(), Has.Count(0));
+		}
+
+		[Test()]
+		public void TestRaceWithOneUnitTypeHasNoRequirements()
+		{
+			MockRace race = new MockRace();
+			race.AddUnitType(new MockUnitType());
+			Assert.That(race.GetRequirements(), Has.Count(0));
+		}
+
+		[Test()]
+		public void TestRaceWithOneUnitTypeWithOneRequirementHasOneRequirement()
+		{
+			MockRace race = new MockRace();
+			MockUnitType unitType = new MockUnitType();
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement = new UnitRequiresAtLeastNUnitsRequirement(unitType);
+			unitType.AddRequirement(unitRequirement);
+			race.AddUnitType(unitType);
+			ICollection<IRequirement> raceRequirements = race.GetRequirements();
+			Assert.That(raceRequirements, Has.Count(1));
+			Assert.That(raceRequirements, Has.All.EqualTo(unitRequirement));
+		}
+
+		[Test()]
+		public void TestRaceWithTwoUnitTypesWithMultipleRequirementsHasMultipleRequirements()
+		{
+			MockRace race = new MockRace();
+			MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement1 = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
+			unitType1.AddRequirement(unitRequirement1);
+			UnitRequiresNoMoreThanNOfUnitTypeRequirement unitRequirement2 = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
+			unitType1.AddRequirement(unitRequirement2);
+			race.AddUnitType(unitType1);
+			MockUnitType unitType2 = new MockUnitType("type2", "Type 2");
+			UnitRequiresAtLeastNUnitsRequirement unitRequirement3 = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
+			unitType2.AddRequirement(unitRequirement3);
+			race.AddUnitType(unitType2);
+			ICollection<IRequirement> raceRequirements = race.GetRequirements();
+			Assert.That(raceRequirements, Has.Count(3));
+			Assert.That(raceRequirements, Has.Member(unitRequirement1));
+			Assert.That(raceRequirements, Has.Member(unitRequirement2));
+			Assert.That(raceRequirements, Has.Member(unitRequirement3));
 		}
 
-		[Test()]
-		public void TestRaceWithOneUnitTypeWithOneRequirementHasOneRequirement()
+		public override Race GetObject ()
 		{
-			MockRace race = new MockRace();
-			MockUnitType unitType = new MockUnitType();
-			UnitRequiresAtLeastNUnitsRequirement unitRequirement = new UnitRequiresAtLeastNUnitsRequirement(unitType);
-			unitType.AddRequirement(unitRequirement);
-			race.AddUnitType(unitType);
-			ICollection<IRequirement> raceRequirements = race.GetRequirements();
-			Assert.That(raceRequirements, Has.Count(1));
-			Assert.That(raceRequirements, Has.All.EqualTo(unitRequirement));
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			GameSystem gameSystem = new GameSystem("system", "system", factory);
+			return new Race("race", "race", gameSystem, factory);
 		}
 
-		[Test()]
-		public void TestRaceWithTwoUnitTypesWithMultipleRequirementsHasMultipleRequirements()
+		public override Race GetSameObject ()
 		{
-			MockRace race = new MockRace();
-			MockUnitType unitType1 = new MockUnitType("type1", "Type 1");
-			UnitRequiresAtLeastNUnitsRequirement unitRequirement1 = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
-			unitType1.AddRequirement(unitRequirement1);
-			UnitRequiresNoMoreThanNOfUnitTypeRequirement unitRequirement2 = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1);
-			unitType1.AddRequirement(unitRequirement2);
-			race.AddUnitType(unitType1);
-			MockUnitType unitType2 = new MockUnitType("type2", "Type 2");
-			UnitRequiresAtLeastNUnitsRequirement unitRequirement3 = new UnitRequiresAtLeastNUnitsRequirement(unitType2);
-			unitType2.AddRequirement(unitRequirement3);
-			race.AddUnitType(unitType2);
-			ICollection<IRequirement> raceRequirements = race.GetRequirements();
-			Assert.That(raceRequirements, Has.Count(3));
-			Assert.That(raceRequirements, Has.Member(unitRequirement1));
-			Assert.That(raceRequirements, Has.Member(unitRequirement2));
-			Assert.That(raceRequirements, Has.Member(unitRequirement3));
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			GameSystem gameSystem = new GameSystem("system", "system", factory);
+			return new Race("race", "race", gameSystem, factory);
+		}
+
+		public override Race GetDifferentObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			GameSystem gameSystem = new GameSystem("system2", "another system", factory);
+			return new Race("race2", "other race", gameSystem, factory);
 		}
 	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Requirement/UnitCountRequirementDataTest.cs	Tue Apr 26 15:03:46 2011 +0000
@@ -0,0 +1,79 @@
+// This file (UnitCountRequirementDataTest.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.NUnit;
+using IBBoard.WarFoundry.API.Objects.Mock;
+using IBBoard.WarFoundry.API.Factories;
+using System.Reflection;
+
+namespace IBBoard.WarFoundry.API.Objects.Requirement
+{
+	[TestFixture()]
+	public class UnitCountRequirementDataTest : AbstractEqualityTest<UnitCountRequirementData>
+	{
+		//FIXME We shouldn't duplicate these tests, but it is broken at the moment
+		[Test]
+		public void TestEquality()
+		{
+			Assert.AreEqual(GetObject(), GetSameObject());
+			Assert.AreEqual(GetSameObject(), GetObject());
+		}
+
+		[Test]
+		public void TestInequality()
+		{
+			Assert.AreNotEqual(GetObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetSameObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetSameObject());
+		}
+
+		[Test]
+		public void TestReflexiveEquality()
+		{
+			Assert.AreEqual(GetObject(), GetObject());
+			Assert.AreEqual(GetSameObject(), GetSameObject());
+			Assert.AreEqual(GetDifferentObject(), GetDifferentObject());
+		}
+
+		[Test]
+		public void TestOtherInequality()
+		{
+			MethodInfo[] methodInfo = GetType().GetMethods();
+			UnitCountRequirementData obj = GetObject();
+
+			foreach (MethodInfo method in methodInfo)
+			{
+				if (method.Name.StartsWith("GetOtherDifferent"))
+				{
+					UnitCountRequirementData otherObj = (UnitCountRequirementData)method.Invoke(this, new object[0]);
+					Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name);
+					Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name);
+				}
+			}
+		}
+
+
+
+		public override UnitCountRequirementData GetObject ()
+		{
+			return new UnitCountRequirementData(new MockUnitType(), 1);
+		}
+
+		public override UnitCountRequirementData GetSameObject ()
+		{
+			return new UnitCountRequirementData(new MockUnitType(), 1);
+		}
+
+		public override UnitCountRequirementData GetDifferentObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			GameSystem gameSystem = new GameSystem("system", "system", factory);
+			Race race = new Race("race", "race", gameSystem, factory);
+			return new UnitCountRequirementData(new UnitType("id9", "some name", race), 2);
+		}
+	}
+}
+
--- a/API/Objects/UnitTypeTest.cs	Mon Apr 25 15:09:54 2011 +0000
+++ b/API/Objects/UnitTypeTest.cs	Tue Apr 26 15:03:46 2011 +0000
@@ -6,12 +6,60 @@
 using NUnit.Framework.Constraints;
 using NUnit.Framework.SyntaxHelpers;
 using IBBoard.WarFoundry.API.Objects.Requirement;
+using System.Reflection;
+using IBBoard.NUnit;
+using IBBoard.WarFoundry.API.Factories;
 
 namespace IBBoard.WarFoundry.API.Objects
 {
 	[TestFixture()]
-	public class UnitTypeTest
+	public class UnitTypeTest : AbstractEqualityTest<UnitType>
 	{
+		//FIXME We shouldn't duplicate these tests, but it is broken at the moment
+		[Test]
+		public void TestEquality()
+		{
+			Assert.AreEqual(GetObject(), GetSameObject());
+			Assert.AreEqual(GetSameObject(), GetObject());
+		}
+
+		[Test]
+		public void TestInequality()
+		{
+			Assert.AreNotEqual(GetObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetSameObject(), GetDifferentObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetObject());
+			Assert.AreNotEqual(GetDifferentObject(), GetSameObject());
+		}
+
+		[Test]
+		public void TestReflexiveEquality()
+		{
+			Assert.AreEqual(GetObject(), GetObject());
+			Assert.AreEqual(GetSameObject(), GetSameObject());
+			Assert.AreEqual(GetDifferentObject(), GetDifferentObject());
+		}
+
+		[Test]
+		public void TestOtherInequality()
+		{
+			MethodInfo[] methodInfo = GetType().GetMethods();
+			UnitType obj = GetObject();
+
+			foreach (MethodInfo method in methodInfo)
+			{
+				if (method.Name.StartsWith("GetOtherDifferent"))
+				{
+					UnitType otherObj = (UnitType)method.Invoke(this, new object[0]);
+					Assert.AreNotEqual(obj, otherObj, "Objects equal for "+method.Name);
+					Assert.AreNotEqual(otherObj, obj, "Objects equal for "+method.Name);
+				}
+			}
+		}
+
+
+
+
 		[Test()]
 		public void TestSettingMainCategorySetsCategoriesCollection()
 		{
@@ -70,6 +118,24 @@
 			minLimit.AddUnitTypeRequirement(unitType, 1);
 			Assert.That(unitType.GetRequirements(), Has.Member(minLimit));
 		}
+
+		public override UnitType GetObject ()
+		{
+			return new UnitType("id1", "Type 1", new MockRace());
+		}
+
+		public override UnitType GetSameObject ()
+		{
+			return new UnitType("id1", "Type 1", new MockRace());
+		}
+
+		public override UnitType GetDifferentObject ()
+		{
+			DummyWarFoundryFactory factory = new DummyWarFoundryFactory();
+			GameSystem gameSystem = new GameSystem("system", "system", factory);
+			Race race = new Race("race", "race", gameSystem, factory);
+			return new UnitType("id2", "Type 2", race);
+		}
 	}
 }
 
--- a/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 25 15:09:54 2011 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Tue Apr 26 15:03:46 2011 +0000
@@ -102,6 +102,7 @@
     <Compile Include="API\Objects\Requirement\Mock\AbstractFixedRequirement.cs" />
     <Compile Include="API\Objects\Requirement\Mock\PassingRequirement.cs" />
     <Compile Include="API\Objects\Requirement\Mock\NotApplicableRequirement.cs" />
+    <Compile Include="API\Objects\Requirement\UnitCountRequirementDataTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="app.config" />
@@ -305,6 +306,10 @@
       <Project>{0E7413FF-EB9E-4714-ACF2-BE3A6A7B2FFD}</Project>
       <Name>ICSharpCode.SharpZLib</Name>
     </ProjectReference>
+    <ProjectReference Include="..\IBBoard.NUnit\IBBoard.NUnit.csproj">
+      <Project>{C52AFD32-B869-4E14-AACE-2846AD2CC742}</Project>
+      <Name>IBBoard.NUnit</Name>
+    </ProjectReference>
   </ItemGroup>
   <ProjectExtensions>
     <MonoDevelop>