Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
view API/Objects/RaceTests.cs @ 139:3e4864e206ea
Re #140: Equality methods
* Add equality testing to RequiresNoMoreThanN requirement
* Add extra different races for testing more of equality method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 26 Apr 2011 19:47:36 +0000 |
parents | 081b48413f6d |
children | 2ae80631ec9c |
line wrap: on
line source
// 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 IBBoard.NUnit; using System.Reflection; using IBBoard.WarFoundry.API.Factories; namespace IBBoard.WarFoundry.API.Objects { [TestFixture()] 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 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)); } public override Race GetObject () { DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); GameSystem gameSystem = new GameSystem("system", "system", factory); return new Race("race", "race", gameSystem, factory); } public override Race GetSameObject () { 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); } public Race GetOtherDifferentObjectWithSubID() { DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); GameSystem gameSystem = new GameSystem("system", "system", factory); return new Race("race", "subid", "race", gameSystem, factory); } public Race GetOtherDifferentObjectWithGameSystem() { DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); GameSystem gameSystem = new GameSystem("system2", "system", factory); return new Race("race", "race", gameSystem, factory); } } }