Mercurial > repos > IBBoard.WarFoundry.API.Tests
changeset 120:d186d46f0bae
Re #27: Unit requirements
* Quick first draft of unit tests for "unit requires no more than X"
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Wed, 06 Apr 2011 20:05:04 +0000 |
parents | 5f389466e8a8 |
children | 6f46fa3c47e5 |
files | API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 2 files changed, 115 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/Requirement/UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs Wed Apr 06 20:05:04 2011 +0000 @@ -0,0 +1,113 @@ +// This file (RequiresNoMoreThanNOfUnitTypeRequirementTest.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 UnitRequiresNoMoreThanNOfUnitTypeRequirementTest + { + 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 TestAddingUnitWithNoUnitsAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + Unit unit = CreateUnitOfType(unitType1, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestAddingUnitWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + Unit unit = CreateUnitOfType(unitType1, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unit, army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestAddingUnitTypeWithNoUnitsAndOneUnitTypeRequiredIsAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestAddingUnitTypeWithOneUnitAndOneUnitTypeRequiredIsNotAllowed() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestAddingUnitTypeSetsLimit() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Passed)); + } + + [Test()] + public void TestAddingUnitTypeSetsLimitForFailure() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2, 1); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + } + + [Test()] + public void TestAddingUnitTypeDefaultsToNoMoreThanZero() + { + Army army = new Army(mockRace, "Test", 1000); + AddUnitOfTypeToArmy(unitType2, army); + RequiresNoMoreThanNOfUnitTypeRequirement req = new UnitRequiresNoMoreThanNOfUnitTypeRequirement(unitType1); + req.AddUnitTypeRequirement(unitType2); + Assert.That(req.AllowsAdding(unitType1, army), Is.EqualTo(Validation.Failed)); + } + + 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)); + } + } +} +
--- a/IBBoard.WarFoundry.API.Tests.csproj Wed Apr 06 19:44:31 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Wed Apr 06 20:05:04 2011 +0000 @@ -17,7 +17,6 @@ <OldToolsVersion>2.0</OldToolsVersion> <TargetFrameworkSubset> </TargetFrameworkSubset> - <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <IsWebBootstrapper>false</IsWebBootstrapper> <PublishUrl>publish\</PublishUrl> <Install>true</Install> @@ -92,9 +91,10 @@ <Compile Include="API\EventListeningWarFoundryLoader.cs" /> <Compile Include="API\Savers\IWarFoundryFileSaverTests.cs" /> <Compile Include="API\Objects\Requirement\RequiresAtLeastNUnitsRequirementTest.cs" /> - <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\UnitRequiresAtLeastNUnitsRequirementTest.cs" /> <Compile Include="API\Objects\Requirement\ValidationTests.cs" /> + <Compile Include="API\Objects\Requirement\UnitRequiresNoMoreThanNOfUnitTypeRequirementTest.cs" /> + <Compile Include="API\Objects\Requirement\RequiresNoMoreThanNOfUnitTypeRequirementTest.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />