changeset 44:0de5d86bc1cb

Re #268: Restructure stats for re-use * Add tests for multiple stat lines/referenced types and for overriding the stats
author IBBoard <dev@ibboard.co.uk>
date Mon, 26 Apr 2010 19:50:47 +0000
parents 00abd1c2f7d6
children 04d7cd276b1d
files API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs IBBoard.WarFoundry.API.Tests.csproj testdata/single-unit-multi-type-referencing-race-with-override.racex testdata/single-unit-multi-type-referencing-race.racex
diffstat 4 files changed, 147 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Sun Apr 25 15:10:30 2010 +0000
+++ b/API/Factories/Xml/WarFoundryXmlRaceFactoryTest.cs	Mon Apr 26 19:50:47 2010 +0000
@@ -58,13 +58,13 @@
 			FileInfo raceFile = new FileInfo("testdata/single-unit-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
-			Assert.That(unitTypes.Length == 1);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
-			Assert.That(stats.Length == 9);
+			Stat[] stats = unitType.UnitStatsArrays[0];
+			Assert.AreEqual(9, stats.Length);
 			Assert.AreEqual("M", stats[0].ParentSlotName);
 			Assert.AreEqual("4", stats[0].SlotValueString);
-			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 		
 		[Test()]
@@ -76,13 +76,54 @@
 			FileInfo raceFile = new FileInfo("testdata/single-unit-type-referencing-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
-			Assert.That(unitTypes.Length == 1);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
-			Assert.That(stats.Length == 9);
+			Stat[] stats = unitType.UnitStatsArrays[0];
+			Assert.AreEqual(9, stats.Length);
 			Assert.AreEqual("M", stats[0].ParentSlotName);
 			Assert.AreEqual("4", stats[0].SlotValueString);
-			Assert.AreEqual("General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesLoadsSuccessfully()
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Stat[][] stats = unitType.UnitStatsArrays;
+			Assert.AreEqual(2, stats.Length);
+			Assert.AreEqual("M", stats[0][0].ParentSlotName);
+			Assert.AreEqual("4", stats[0][0].SlotValueString);
+			Assert.AreEqual("General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
+			Assert.AreEqual("M", stats[1][0].ParentSlotName);
+			Assert.AreEqual("8", stats[1][0].SlotValueString);
+			Assert.AreEqual("Warhorse", unitType.UnitStatsArraysWithName[1][0].SlotValueString);
+		}
+		
+		[Test()]
+		public void TestSingleUnitArmyWithMultipleMemberTypeReferencesAndOverrideLoadsSuccessfully()
+		{
+			GameSystem system = SingleXmlObjectLoader.LoadGameSystemFromXML(WarFoundryXmlFactory.GetFactory(), new FileInfo("testdata/default.systemx"));
+			FixedGameSystemWarFoundryLoader fixedLoader = new FixedGameSystemWarFoundryLoader(system);
+			WarFoundryLoader.SetDefault(fixedLoader);
+			FileInfo raceFile = new FileInfo("testdata/single-unit-multi-type-referencing-race-with-override.racex");
+			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
+			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
+			Assert.AreEqual(1, unitTypes.Length);
+			UnitType unitType = unitTypes[0];
+			Stat[][] allStats = unitType.UnitStatsArrays;
+			Stat[] stats = allStats[0];
+			Assert.AreEqual(1, allStats.Length);
+			Assert.AreEqual(9, stats.Length);
+			Assert.AreEqual("M", stats[0].ParentSlotName);
+			Assert.AreEqual("4", stats[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 		
 		[Test()]
@@ -94,9 +135,9 @@
 			FileInfo raceFile = new FileInfo("testdata/single-unit-no-stats-race.racex");
 			Race race = SingleXmlObjectLoader.LoadRaceFromXML(WarFoundryXmlFactory.GetFactory(), raceFile);
 			UnitType[] unitTypes = race.GetUnitTypes(race.GetCategory("cat1"));
-			Assert.That(unitTypes.Length == 1);
+			Assert.AreEqual(1, unitTypes.Length);
 			UnitType unitType = unitTypes[0];
-			Stat[] stats = unitType.UnitStatsArray;
+			Stat[] stats = unitType.UnitStatsArrays[0];
 			Assert.That(stats.Length == race.GameSystem.StandardSystemStats.SlotCount);
 			
 			foreach (Stat stat in stats)
@@ -104,7 +145,7 @@
 				Assert.AreEqual("", stat.SlotValueString);
 			}
 			
-			Assert.AreEqual("Empire General", unitType.UnitStatsArrayWithName[0].SlotValueString);
+			Assert.AreEqual("Empire General", unitType.UnitStatsArraysWithName[0][0].SlotValueString);
 		}
 	}
 }
--- a/IBBoard.WarFoundry.API.Tests.csproj	Sun Apr 25 15:10:30 2010 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Mon Apr 26 19:50:47 2010 +0000
@@ -99,6 +99,12 @@
     <None Include="testdata\extended-data.armyx">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="testdata\single-unit-multi-type-referencing-race.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+    <None Include="testdata\single-unit-multi-type-referencing-race-with-override.racex">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.85.5.452, Culture=neutral, PublicKeyToken=1b03e6acf1164f73">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-multi-type-referencing-race-with-override.racex	Mon Apr 26 19:50:47 2010 +0000
@@ -0,0 +1,50 @@
+<?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">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+			<unitMembers>
+				<unitMember typeID="General"/>
+				<unitMember typeID="Warhorse"/>
+			</unitMembers>
+		</unit>
+	</units>
+	<memberTypes>
+		<memberType id="General" name="General">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+		</memberType>
+		<memberType id="Warhorse" name="Warhorse">
+			<stats>
+				<stat name="M">8</stat>
+				<stat name="WS">3</stat>
+				<stat name="BS">0</stat>
+				<stat name="S">3</stat>
+				<stat name="T">3</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">4</stat>
+			</stats>
+		</memberType>
+	</memberTypes>
+</race>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testdata/single-unit-multi-type-referencing-race.racex	Mon Apr 26 19:50:47 2010 +0000
@@ -0,0 +1,39 @@
+<?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">
+			<unitMembers>
+				<unitMember typeID="General"/>
+				<unitMember typeID="Warhorse"/>
+			</unitMembers>
+		</unit>
+	</units>
+	<memberTypes>
+		<memberType id="General" name="General">
+			<stats>
+				<stat name="M">4</stat>
+				<stat name="WS">6</stat>
+				<stat name="BS">6</stat>
+				<stat name="S">4</stat>
+				<stat name="T">4</stat>
+				<stat name="W">3</stat>
+				<stat name="I">6</stat>
+				<stat name="A">4</stat>
+				<stat name="Ld">9</stat>
+			</stats>
+		</memberType>
+		<memberType id="Warhorse" name="Warhorse">
+			<stats>
+				<stat name="M">8</stat>
+				<stat name="WS">3</stat>
+				<stat name="BS">0</stat>
+				<stat name="S">3</stat>
+				<stat name="T">3</stat>
+				<stat name="W">1</stat>
+				<stat name="I">2</stat>
+				<stat name="A">1</stat>
+				<stat name="Ld">4</stat>
+			</stats>
+		</memberType>
+	</memberTypes>
+</race>
\ No newline at end of file