view API/Objects/Requirement/RaceRequiresAtLeastNUnitsRequirementTest.cs @ 239:370bec16a364 default tip

Add initial testing for equipment with type (incomplete)
author IBBoard <dev@ibboard.co.uk>
date Sun, 16 Oct 2016 20:29:35 +0100
parents e173c5512067
children
line wrap: on
line source

// This file (RaceRequiresAtLeastNUnitsRequirementTest.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;

namespace IBBoard.WarFoundry.API.Objects.Requirement
{
	[TestFixture()]
	public class RaceRequiresAtLeastNUnitsRequirementTest : AbstractRaceUnitRequirementTest<Race, RaceRequiresAtLeastNUnitsRequirement>
	{
		[Test()]
		public void TestAddingUnitTypeWithNoUnitAndOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequiredFails()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__FailsAdding(req, unitType2, army, "Army must contain: 1 × " + unitType3.Name + " (would have 0).");
			Assert_That__FailsAdding(req, unitType3, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0).");
		}

		[Test()]
		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__FailsAdding(req, unitType2, army, "Army must contain: 1 × " + unitType3.Name + " (would have 0).");
		}

		[Test()]
		public void TestAddingUnitTypeWithOtherOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingOtherUnitTypeWithOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__PassesAdding(req, unitType3, army);
		}

		[Test()]
		public void TestAddingOtherUnitTypeWithOtherOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__FailsAdding(req, unitType3, army, "Army must contain: 1 × " + unitType2.Name + " (would have 0).");
		}

		[Test()]
		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__PassesAdding(req, unitType2, army);
			Assert_That__PassesAdding(req, unitType3, army);
		}

		[Test()]
		public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicable()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__AddingNotApplicable(req, unitType1, army);
		}

		[Test()]
		public void TestAddingUnrelatedUnitTypeValidatesAsNotApplicableWhenRequirementsNotMet()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__AddingNotApplicable(req, unitType1, army);
		}

		[Test()]
		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestAddingUnitTypeMakesRequirementPass()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__FailsAdding(req, unitType2, army, "Army must contain: 2 × " + unitType2.Name + " (would have 1).");
			AddUnitOfTypeToArmy(unitType2, army);
			Assert_That__PassesAdding(req, unitType2, army);
		}

		[Test()]
		public void TestValidatingWithNoUnitsAndOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0).");
		}

		[Test()]
		public void TestValidatingWithOneUnitAndOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__ValidationPasses(req, army);
		}

		[Test()]
		public void TestValidatingWithNoUnitsAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0); 1 × " + unitType3.Name + " (have 0).");
		}

		[Test()]
		public void TestValidatingWithOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType3.Name + " (have 0).");
		}

		[Test()]
		public void TestValidatingWithOtherOneUnitAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			AddUnitOfTypeToArmy(unitType1, army);
			Assert_That__ValidationFails(req, army, "Army must contain: 1 × " + unitType2.Name + " (have 0).");
		}

		[Test()]
		public void TestValidatingWithBothUnitsAndTwoUnitTypesRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			req.AddUnitTypeRequirement(unitType3);
			Assert_That__ValidationPasses(req, army);
		}

		[Test()]
		public void TestValidatingWithOneUnitAndTwoOfOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1).");
		}

		[Test()]
		public void TestValidatingWithUnrelatedUnitTypeValidatesAsFailed()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType3, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 0).");
		}

		[Test()]
		public void TestValidatingWithTwoUnitsAndTwoOfOneUnitTypeRequired()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__ValidationPasses(req, army);
		}

		[Test()]
		public void TestValidatingRequirementWithNoNumberDefaultsToHavingOne()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2);
			Assert_That__ValidationPasses(req, army);
		}

		[Test()]
		public void TestAddingUnitTypeMakesRequirementPassValidating()
		{
			Army army = new Army(mockRace, "Test", 1000);
			AddUnitOfTypeToArmy(unitType2, army);
			RaceRequiresAtLeastNUnitsRequirement req = new RaceRequiresAtLeastNUnitsRequirement(mockRace);
			req.AddUnitTypeRequirement(unitType2, 2);
			Assert_That__ValidationFails(req, army, "Army must contain: 2 × " + unitType2.Name + " (have 1).");
			AddUnitOfTypeToArmy(unitType2, army);
			Assert_That__ValidationPasses(req, army);
		}

		protected override RaceRequiresAtLeastNUnitsRequirement CreateRequirement(Race requirementOn)
		{
			return new RaceRequiresAtLeastNUnitsRequirement(requirementOn);
		}
	}
}