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 wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlLimitParserTest.cs	Sat Jun 05 15:37:03 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlLimitParserTest.cs	Sat Jun 05 18:58:54 2010 +0000
@@ -6,15 +6,16 @@
 using NUnit.Framework;
 using IBBoard.Limits;
 using NUnit.Framework.SyntaxHelpers;
+using IBBoard.IO;
 namespace IBBoard.WarFoundry.API.Factories.Xml
 {
 	[TestFixture()]
 	public class WarFoundryXmlLimitParserTest
 	{
 		[Test()]
-		public void TestCompositeLimit()
+		public void TestCompositeMaxLimit()
 		{
-			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-limit.xml"));
+			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit.xml"));
 			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
 			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
 			ILimit limit = parser.GetLimitFromElement(limitElem);
@@ -26,6 +27,40 @@
 		}
 		
 		[Test()]
+		public void TestCompositeMinLimit()
+		{
+			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-min-limit.xml"));
+			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
+			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
+			ILimit limit = parser.GetLimitFromElement(limitElem);
+			Assert.That(limit, Is.InstanceOfType(typeof(CompositeMinimumLimit)));
+			Assert.That(limit.GetLimit(1), Is.EqualTo(1));
+			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(10), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(20), Is.EqualTo(5));
+		}
+
+		[Test()]
+		public void TestNestedCompositeLimit()
+		{
+			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/composite-max-limit-nested.xml"));
+			XmlElement limitElem = WarFoundryXmlFactoryUtils.SelectSingleElement(document, "//race:maxLimit/*");
+			WarFoundryXmlLimitParser parser = new WarFoundryXmlLimitParser();
+			ILimit limit = parser.GetLimitFromElement(limitElem);
+			Assert.That(limit, Is.InstanceOfType(typeof(CompositeMaximumLimit)));
+			Assert.That(limit.GetLimit(1), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(5), Is.EqualTo(5));
+			Assert.That(limit.GetLimit(10), Is.EqualTo(5));
+		}
+		
+		[Test()]
+		[ExpectedException(typeof(InvalidFileException))]
+		public void TestEmptyCompositeFailsValidation()
+		{
+			SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/empty-composite.xml"));
+		}
+		
+		[Test()]
 		public void TestAbsoluteLimit()
 		{
 			XmlElement document = SingleXmlObjectLoader.CreateDocumentElementFromFile(new FileInfo("testdata/limits/absolute-limit.xml"));
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 15:37:03 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Jun 05 18:58:54 2010 +0000
@@ -134,10 +134,19 @@
     <None Include="testdata\unit-in-specified-main-category.armyx">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="testdata\limits\composite-limit.xml">
+    <None Include="testdata\limits\absolute-limit.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\limits\composite-max-limit.xml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
-    <None Include="testdata\limits\absolute-limit.xml">
+    <None Include="testdata\limits\composite-min-limit.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\limits\composite-max-limit-nested.xml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\limits\empty-composite.xml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
   </ItemGroup>
--- a/testdata/limits/absolute-limit.xml	Sat Jun 05 15:37:03 2010 +0000
+++ b/testdata/limits/absolute-limit.xml	Sat Jun 05 18:58:54 2010 +0000
@@ -5,7 +5,7 @@
 			<equipmentSlots>
 				<equipmentSlot name="slot">
 					<maxLimit>
-						<absoluteLimit limit="5"/>
+						<core:absoluteLimit limit="5"/>
 					</maxLimit>
 				</equipmentSlot>
 			</equipmentSlots>
--- a/testdata/limits/composite-limit.xml	Sat Jun 05 15:37:03 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<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">
-	<units>
-		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
-			<equipmentSlots>
-				<equipmentSlot name="slot">
-					<maxLimit>
-						<compositeMaxLimit>
-							<sizeConstrainedLimit limit="10"/>
-							<absoluteLimit limit="5"/>
-						</compositeMaxLimit>
-					</maxLimit>
-				</equipmentSlot>
-			</equipmentSlots>
-		</unit>
-	</units>
-</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/composite-max-limit-nested.xml	Sat Jun 05 18:58:54 2010 +0000
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<core:compositeMaxLimit>
+							<core:compositeMaxLimit>
+								<core:compositeMaxLimit>
+									<core:compositeMaxLimit>
+										<core:absoluteLimit limit="5"/>
+									</core:compositeMaxLimit>
+								</core:compositeMaxLimit>
+							</core:compositeMaxLimit>
+						</core:compositeMaxLimit>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/composite-max-limit.xml	Sat Jun 05 18:58:54 2010 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<core:compositeMaxLimit>
+							<core:sizeConstrainedLimit limit="10"/>
+							<core:absoluteLimit limit="5"/>
+						</core:compositeMaxLimit>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/composite-min-limit.xml	Sat Jun 05 18:58:54 2010 +0000
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<core:compositeMinLimit>
+							<core:sizeConstrainedLimit limit="10"/>
+							<core:absoluteLimit limit="5"/>
+						</core:compositeMinLimit>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/limits/empty-composite.xml	Sat Jun 05 18:58:54 2010 +0000
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+	<units>
+		<unit id="Empire1" typeName="Empire General" cat="cat1" points="100" maxNum="1" maxSize="1">
+			<equipmentSlots>
+				<equipmentSlot name="slot">
+					<maxLimit>
+						<core:compositeMaxLimit>
+						</core:compositeMaxLimit>
+					</maxLimit>
+				</equipmentSlot>
+			</equipmentSlots>
+		</unit>
+	</units>
+</race>
\ No newline at end of file