changeset 55:7f9e1fef069e

Re #279: Create composite limit * Create separate tests for min and max limits (rename existing test data file) * Fix namespacing of limit nodes * Add test for nesting of composite limits * Add tests for empty composite causing failure
author IBBoard <dev@ibboard.co.uk>
date Sat, 05 Jun 2010 18:58:54 +0000
parents 084049c8dff4
children c6e5b8a1948d
files API/Factories/Xml/WarFoundryXmlLimitParserTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/limits/absolute-limit.xml testdata/limits/composite-limit.xml testdata/limits/composite-max-limit-nested.xml testdata/limits/composite-max-limit.xml testdata/limits/composite-min-limit.xml testdata/limits/empty-composite.xml
diffstat 8 files changed, 120 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/API/Factories/Xml/WarFoundryXmlLimitParserTest.cs	Sat Jun 05 15:37:03 2010 +0000
     1.2 +++ b/API/Factories/Xml/WarFoundryXmlLimitParserTest.cs	Sat Jun 05 18:58:54 2010 +0000
     1.3 @@ -6,15 +6,16 @@
     1.4  using NUnit.Framework;
     1.5  using IBBoard.Limits;
     1.6  using NUnit.Framework.SyntaxHelpers;
     1.7 +using IBBoard.IO;
     1.8  namespace IBBoard.WarFoundry.API.Factories.Xml
     1.9  {
    1.10  	[TestFixture()]
    1.11  	public class WarFoundryXmlLimitParserTest
    1.12  	{
    1.13  		[Test()]
    1.14 -		public void TestCompositeLimit()
    1.15 +		public void TestCompositeMaxLimit()
    1.16  		{
    1.17 -			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-limit.xml"));
    1.18 +			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit.xml"));
    1.19  			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
    1.20  			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
    1.21  			ILimit limit = parser.GetLimitFromElement(limitElem);
    1.22 @@ -26,6 +27,40 @@
    1.23  		}
    1.24  		
    1.25  		[Test()]
    1.26 +		public void TestCompositeMinLimit()
    1.27 +		{
    1.28 +			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-min-limit.xml"));
    1.29 +			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
    1.30 +			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
    1.31 +			ILimit limit = parser.GetLimitFromElement(limitElem);
    1.32 +			Assert.That(limit, Is.InstanceOfType(typeof(CompositeMinimumLimit)));
    1.33 +			Assert.That(limit.GetLimit(1), Is.EqualTo(1));
    1.34 +			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
    1.35 +			Assert.That(limit.GetLimit(10), Is.EqualTo(5));
    1.36 +			Assert.That(limit.GetLimit(20), Is.EqualTo(5));
    1.37 +		}
    1.38 +
    1.39 +		[Test()]
    1.40 +		public void TestNestedCompositeLimit()
    1.41 +		{
    1.42 +			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit-nested.xml"));
    1.43 +			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
    1.44 +			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
    1.45 +			ILimit limit = parser.GetLimitFromElement(limitElem);
    1.46 +			Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
    1.47 +			Assert.That(limit.GetLimit(1), Is.EqualTo(5));
    1.48 +			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
    1.49 +			Assert.That(limit.GetLimit(10), Is.EqualTo(5));
    1.50 +		}
    1.51 +		
    1.52 +		[Test()]
    1.53 +		[ExpectedException(typeof(InvalidFileException))]
    1.54 +		public void TestEmptyCompositeFailsValidation()
    1.55 +		{
    1.56 +			SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/empty-composite.xml"));
    1.57 +		}
    1.58 +		
    1.59 +		[Test()]
    1.60  		public void TestAbsoluteLimit()
    1.61  		{
    1.62  			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
     2.1 --- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 15:37:03 2010 +0000
     2.2 +++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 18:58:54 2010 +0000
     2.3 @@ -134,10 +134,19 @@
     2.4      <None Include="testdata\unit-in-specified-main-category.armyx">
     2.5        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     2.6      </None>
     2.7 -    <None Include="testdata\limits\composite-limit.xml">
     2.8 +    <None Include="testdata\limits\absolute-limit.xml">
     2.9        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.10      </None>
    2.11 -    <None Include="testdata\limits\absolute-limit.xml">
    2.12 +    <None Include="testdata\limits\composite-max-limit.xml">
    2.13 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.14 +    </None>
    2.15 +    <None Include="testdata\limits\composite-min-limit.xml">
    2.16 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.17 +    </None>
    2.18 +    <None Include="testdata\limits\composite-max-limit-nested.xml">
    2.19 +      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.20 +    </None>
    2.21 +    <None Include="testdata\limits\empty-composite.xml">
    2.22        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    2.23      </None>
    2.24    </ItemGroup>
     3.1 --- a/testdata/limits/absolute-limit.xml	Sat Jun 05 15:37:03 2010 +0000
     3.2 +++ b/testdata/limits/absolute-limit.xml	Sat Jun 05 18:58:54 2010 +0000
     3.3 @@ -5,7 +5,7 @@
     3.4  			<equipmentSlots>
     3.5  				<equipmentSlot name="slot">
     3.6  					<maxLimit>
     3.7 -						<absoluteLimit limit="5"/>
     3.8 +						<core:absoluteLimit limit="5"/>
     3.9  					</maxLimit>
    3.10  				</equipmentSlot>
    3.11  			</equipmentSlots>
     4.1 --- a/testdata/limits/composite-limit.xml	Sat Jun 05 15:37:03 2010 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,17 +0,0 @@
     4.4 -<?xml version="1.0" encoding="UTF-8"?>
     4.5 -<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
     4.6 -	<units>
     4.7 -		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     4.8 -			<equipmentSlots>
     4.9 -				<equipmentSlot name="slot">
    4.10 -					<maxLimit>
    4.11 -						<compositeMaxLimit>
    4.12 -							<sizeConstrainedLimit limit="10"/>
    4.13 -							<absoluteLimit limit="5"/>
    4.14 -						</compositeMaxLimit>
    4.15 -					</maxLimit>
    4.16 -				</equipmentSlot>
    4.17 -			</equipmentSlots>
    4.18 -		</unit>
    4.19 -	</units>
    4.20 -</race>
    4.21 \ No newline at end of file
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/testdata/limits/composite-max-limit-nested.xml	Sat Jun 05 18:58:54 2010 +0000
     5.3 @@ -0,0 +1,22 @@
     5.4 +<?xml version="1.0" encoding="UTF-8"?>
     5.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
     5.6 +	<units>
     5.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     5.8 +			<equipmentSlots>
     5.9 +				<equipmentSlot name="slot">
    5.10 +					<maxLimit>
    5.11 +						<core:compositeMaxLimit>
    5.12 +							<core:compositeMaxLimit>
    5.13 +								<core:compositeMaxLimit>
    5.14 +									<core:compositeMaxLimit>
    5.15 +										<core:absoluteLimit limit="5"/>
    5.16 +									</core:compositeMaxLimit>
    5.17 +								</core:compositeMaxLimit>
    5.18 +							</core:compositeMaxLimit>
    5.19 +						</core:compositeMaxLimit>
    5.20 +					</maxLimit>
    5.21 +				</equipmentSlot>
    5.22 +			</equipmentSlots>
    5.23 +		</unit>
    5.24 +	</units>
    5.25 +</race>
    5.26 \ No newline at end of file
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/testdata/limits/composite-max-limit.xml	Sat Jun 05 18:58:54 2010 +0000
     6.3 @@ -0,0 +1,17 @@
     6.4 +<?xml version="1.0" encoding="UTF-8"?>
     6.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
     6.6 +	<units>
     6.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     6.8 +			<equipmentSlots>
     6.9 +				<equipmentSlot name="slot">
    6.10 +					<maxLimit>
    6.11 +						<core:compositeMaxLimit>
    6.12 +							<core:sizeConstrainedLimit limit="10"/>
    6.13 +							<core:absoluteLimit limit="5"/>
    6.14 +						</core:compositeMaxLimit>
    6.15 +					</maxLimit>
    6.16 +				</equipmentSlot>
    6.17 +			</equipmentSlots>
    6.18 +		</unit>
    6.19 +	</units>
    6.20 +</race>
    6.21 \ No newline at end of file
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/testdata/limits/composite-min-limit.xml	Sat Jun 05 18:58:54 2010 +0000
     7.3 @@ -0,0 +1,17 @@
     7.4 +<?xml version="1.0" encoding="UTF-8"?>
     7.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
     7.6 +	<units>
     7.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     7.8 +			<equipmentSlots>
     7.9 +				<equipmentSlot name="slot">
    7.10 +					<maxLimit>
    7.11 +						<core:compositeMinLimit>
    7.12 +							<core:sizeConstrainedLimit limit="10"/>
    7.13 +							<core:absoluteLimit limit="5"/>
    7.14 +						</core:compositeMinLimit>
    7.15 +					</maxLimit>
    7.16 +				</equipmentSlot>
    7.17 +			</equipmentSlots>
    7.18 +		</unit>
    7.19 +	</units>
    7.20 +</race>
    7.21 \ No newline at end of file
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/testdata/limits/empty-composite.xml	Sat Jun 05 18:58:54 2010 +0000
     8.3 @@ -0,0 +1,15 @@
     8.4 +<?xml version="1.0" encoding="UTF-8"?>
     8.5 +<race xmlns="http://ibboard.co.uk/warfoundry/race" xmlns:core="http://ibboard.co.uk/warfoundry/core" id="EmpireAlt" name="Empire (Extended)" system="default" lang="en">
     8.6 +	<units>
     8.7 +		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
     8.8 +			<equipmentSlots>
     8.9 +				<equipmentSlot name="slot">
    8.10 +					<maxLimit>
    8.11 +						<core:compositeMaxLimit>
    8.12 +						</core:compositeMaxLimit>
    8.13 +					</maxLimit>
    8.14 +				</equipmentSlot>
    8.15 +			</equipmentSlots>
    8.16 +		</unit>
    8.17 +	</units>
    8.18 +</race>
    8.19 \ No newline at end of file