changeset 112:53cfd5b3d1bd

Re #27: Define unit requirements * Copy and paste first requirement unit test that does "requirement for unit type"
author IBBoard <dev@ibboard.co.uk>
date Sat, 02 Apr 2011 20:08:08 +0000
parents f0b488c9f29b
children 87cff356079d
files API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 2 files changed, 164 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/API/Objects/Requirement/UnitRequiresAtLeastNUnitsRequirementTest.cs	Sat Apr 02 20:08:08 2011 +0000
     1.3 @@ -0,0 +1,163 @@
     1.4 +// This file (UnitRequiresAtLeastNUnitsRequirement.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2011 IBBoard
     1.5 +// 
     1.6 +// 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.
     1.7 +using System;
     1.8 +using NUnit.Framework;
     1.9 +using IBBoard.WarFoundry.API.Objects.Mock;
    1.10 +using NUnit.Framework.SyntaxHelpers;
    1.11 +
    1.12 +namespace IBBoard.WarFoundry.API.Objects.Requirement
    1.13 +{
    1.14 +	[TestFixture()]
    1.15 +	public class UnitRequiresAtLeastNUnitsRequirementTest
    1.16 +	{
    1.17 +		private MockRace mockRace;
    1.18 +		private UnitType unitType1;
    1.19 +		private UnitType unitType2;
    1.20 +		private UnitType unitType3;
    1.21 +
    1.22 +		[TestFixtureSetUp()]
    1.23 +		public void SetupRace()
    1.24 +		{
    1.25 +			mockRace = new MockRace();
    1.26 +			unitType1 = new MockUnitType("type1", "Unit Type 1");
    1.27 +			mockRace.AddUnitType(unitType1);
    1.28 +			unitType2 = new MockUnitType("type2", "Unit Type 2");
    1.29 +			mockRace.AddUnitType(unitType2);
    1.30 +			unitType3 = new MockUnitType("type3", "Unit Type 3");
    1.31 +			mockRace.AddUnitType(unitType3);
    1.32 +		}
    1.33 +
    1.34 +		[Test()]
    1.35 +		public void TestAddingUnitWithNoUnitsAndOneUnitTypeRequired()
    1.36 +		{
    1.37 +			Army army = new Army(mockRace, "Test", 1000);
    1.38 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.39 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.40 +			req.AddUnitTypeRequirement(unitType2);
    1.41 +			Assert.That(req.AllowsAdding(unit, army), Is.False);
    1.42 +		}
    1.43 +
    1.44 +		[Test()]
    1.45 +		public void TestAddingUnitWithOneUnitAndOneUnitTypeRequired()
    1.46 +		{
    1.47 +			Army army = new Army(mockRace, "Test", 1000);
    1.48 +			AddUnitOfTypeToArmy(unitType2, army);
    1.49 +			Unit unit = CreateUnitOfType(unitType1, army);
    1.50 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.51 +			req.AddUnitTypeRequirement(unitType2);
    1.52 +			Assert.That(req.AllowsAdding(unit, army), Is.True);
    1.53 +		}
    1.54 +
    1.55 +		[Test()]
    1.56 +		public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequired()
    1.57 +		{
    1.58 +			Army army = new Army(mockRace, "Test", 1000);
    1.59 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.60 +			req.AddUnitTypeRequirement(unitType2);
    1.61 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.62 +		}
    1.63 +
    1.64 +		[Test()]
    1.65 +		public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequired()
    1.66 +		{
    1.67 +			Army army = new Army(mockRace, "Test", 1000);
    1.68 +			AddUnitOfTypeToArmy(unitType2, army);
    1.69 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.70 +			req.AddUnitTypeRequirement(unitType2);
    1.71 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
    1.72 +		}
    1.73 +
    1.74 +		[Test()]
    1.75 +		public void TestAddingUnitTypeWithNoUnitsAndTwoUnitTypesRequired()
    1.76 +		{
    1.77 +			Army army = new Army(mockRace, "Test", 1000);
    1.78 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.79 +			req.AddUnitTypeRequirement(unitType2);
    1.80 +			req.AddUnitTypeRequirement(unitType3);
    1.81 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.82 +		}
    1.83 +
    1.84 +		[Test()]
    1.85 +		public void TestAddingUnitTypeWithOneUnitAndTwoUnitTypesRequired()
    1.86 +		{
    1.87 +			Army army = new Army(mockRace, "Test", 1000);
    1.88 +			AddUnitOfTypeToArmy(unitType2, army);
    1.89 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
    1.90 +			req.AddUnitTypeRequirement(unitType2);
    1.91 +			req.AddUnitTypeRequirement(unitType3);
    1.92 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
    1.93 +		}
    1.94 +
    1.95 +		[Test()]
    1.96 +		public void TestAddingUnitTypeWithBothUnitsAndTwoUnitTypesRequired()
    1.97 +		{
    1.98 +			Army army = new Army(mockRace, "Test", 1000);
    1.99 +			AddUnitOfTypeToArmy(unitType2, army);
   1.100 +			AddUnitOfTypeToArmy(unitType3, army);
   1.101 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.102 +			req.AddUnitTypeRequirement(unitType2);
   1.103 +			req.AddUnitTypeRequirement(unitType3);
   1.104 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
   1.105 +		}
   1.106 +
   1.107 +		[Test()]
   1.108 +		public void TestAddingUnitTypeWithOneUnitAndTwoOfOneUnitTypeRequired()
   1.109 +		{
   1.110 +			Army army = new Army(mockRace, "Test", 1000);
   1.111 +			AddUnitOfTypeToArmy(unitType2, army);
   1.112 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.113 +			req.AddUnitTypeRequirement(unitType2, 2);
   1.114 +			Assert.That(req.AllowsAdding(unitType1, army), Is.False);
   1.115 +		}
   1.116 +
   1.117 +		[Test()]
   1.118 +		public void TestAddingUnitTypeWithTwoUnitsAndTwoOfOneUnitTypeRequired()
   1.119 +		{
   1.120 +			Army army = new Army(mockRace, "Test", 1000);
   1.121 +			AddUnitOfTypeToArmy(unitType2, army);
   1.122 +			AddUnitOfTypeToArmy(unitType2, army);
   1.123 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.124 +			req.AddUnitTypeRequirement(unitType2, 2);
   1.125 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
   1.126 +		}
   1.127 +
   1.128 +		[Test()]
   1.129 +		public void TestAddingUnitTypeRequirementWithNoNumberDefaultsToHavingOne()
   1.130 +		{
   1.131 +			Army army = new Army(mockRace, "Test", 1000);
   1.132 +			AddUnitOfTypeToArmy(unitType2, army);
   1.133 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.134 +			req.AddUnitTypeRequirement(unitType2);
   1.135 +			Assert.That(req.AllowsAdding(unitType1, army), Is.True);
   1.136 +		}
   1.137 +
   1.138 +		[Test()]
   1.139 +		public void TestValidityOfArmyWithNoUnitsAndOneUnitTypeRequired()
   1.140 +		{
   1.141 +			Army army = new Army(mockRace, "Test", 1000);
   1.142 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.143 +			req.AddUnitTypeRequirement(unitType2);
   1.144 +			Assert.That(req.ValidatesArmy(army), Is.False);
   1.145 +		}
   1.146 +
   1.147 +		[Test()]
   1.148 +		public void TestValidityOfArmyWithOneUnitAndOneUnitTypeRequired()
   1.149 +		{
   1.150 +			Army army = new Army(mockRace, "Test", 1000);
   1.151 +			AddUnitOfTypeToArmy(unitType2, army);
   1.152 +			UnitRequiresAtLeastNUnitsRequirement req = new UnitRequiresAtLeastNUnitsRequirement(unitType1);
   1.153 +			req.AddUnitTypeRequirement(unitType2);
   1.154 +			Assert.That(req.ValidatesArmy(army), Is.True);
   1.155 +		}
   1.156 +		private static void AddUnitOfTypeToArmy(UnitType unitType, Army army)
   1.157 +		{
   1.158 +			army.AddUnit(CreateUnitOfType(unitType, army));
   1.159 +		}
   1.160 +		private static Unit CreateUnitOfType(UnitType unitType, Army army)
   1.161 +		{
   1.162 +			return new Unit(unitType, army.GetCategory(unitType.MainCategory));
   1.163 +		}
   1.164 +	}
   1.165 +}
   1.166 +
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Wed Mar 30 19:07:33 2011 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Apr 02 20:08:08 2011 +0000
     2.3 @@ -93,6 +93,7 @@
     2.4      <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" />
     2.5      <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" />
     2.6      <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" />
     2.7 +    <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirementTest.cs" />
     2.8    </ItemGroup>
     2.9    <ItemGroup>
    2.10      <None Include="app.config" />