changeset 15:1119b6f48e8e

Re #198: Add slots with counts to units * Add extra tests to equipment adding * Separate out mock percentage and numeric equipment items * Add MockUnit so that we don't have to initialise translations (overrides DefaultName() method)
author IBBoard <dev@ibboard.co.uk>
date Sat, 24 Oct 2009 13:26:37 +0000
parents 19fc7a733064
children 74346d5c17fe
files API/Objects/Mock/MockNumericAmountUnitEquipmentItem.cs API/Objects/Mock/MockPercentageAmountUnitEquipmentItem.cs API/Objects/Mock/MockUnit.cs API/Objects/Mock/MockUnitEquipmentItem.cs API/Objects/UnitTest.cs IBBoard.WarFoundry.API.Tests.csproj
diffstat 6 files changed, 119 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockNumericAmountUnitEquipmentItem.cs	Sat Oct 24 13:26:37 2009 +0000
@@ -0,0 +1,18 @@
+// This file (MockUnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockNumericAmountUnitEquipmentItem : UnitEquipmentItem
+	{
+
+		public MockNumericAmountUnitEquipmentItem () : base(new MockEquipmentItem(), new MockUnitType())
+		{
+			MaxPercentage = 100; //TODO: This seems odd - maybe IsRatio should be "!=0"
+			MaxNumber = WarFoundryCore.INFINITY;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockPercentageAmountUnitEquipmentItem.cs	Sat Oct 24 13:26:37 2009 +0000
@@ -0,0 +1,17 @@
+// This file (MockUnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 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;
+
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockPercentageAmountUnitEquipmentItem : UnitEquipmentItem
+	{
+
+		public MockPercentageAmountUnitEquipmentItem () : base(new MockEquipmentItem(), new MockUnitType())
+		{
+			MaxPercentage = 50;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/API/Objects/Mock/MockUnit.cs	Sat Oct 24 13:26:37 2009 +0000
@@ -0,0 +1,21 @@
+// This file (MockUnit.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 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 IBBoard.WarFoundry.API.Objects;
+
+namespace IBBoard.WarFoundry.API.Objects.Mock
+{
+	public class MockUnit : Unit
+	{
+		public MockUnit (UnitType unitType, ArmyCategory parentCat) : base(unitType, parentCat)
+		{
+		}
+		
+		protected override string DefaultName ()
+		{
+			return "Default Name";
+		}
+	}
+}
--- a/API/Objects/Mock/MockUnitEquipmentItem.cs	Fri Oct 23 19:57:03 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-// This file (MockUnitEquipmentItem.cs) is a part of the IBBoard.WarFoundry.API.Tests project and is copyright 2009 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;
-
-namespace IBBoard.WarFoundry.API.Objects.Mock
-{
-	public class MockUnitEquipmentItem : UnitEquipmentItem
-	{
-
-		public MockUnitEquipmentItem () : base(new MockEquipmentItem(), new MockUnitType())
-		{
-			MaxPercentage = 100; //TODO: This seems odd - maybe IsRatio should be "!=0"
-			MaxNumber = WarFoundryCore.INFINITY;
-		}
-	}
-}
--- a/API/Objects/UnitTest.cs	Fri Oct 23 19:57:03 2009 +0000
+++ b/API/Objects/UnitTest.cs	Sat Oct 24 13:26:37 2009 +0000
@@ -10,16 +10,73 @@
 {
 	[TestFixture()]
 	public class UnitTest
-	{
+	{		
 		[Test()]
-		public void TestAddSlotEquipmentAddsEquipmentSelection()
+		public void TestAddNumericAmountEquipmentAddsEquipmentSelection()
 		{
-			UnitEquipmentItem equip = new MockUnitEquipmentItem();
+			UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
 			UnitType unitType = equip.EquipmentForUnit;
 			Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory));
 			unit.SetEquipmentAmount(equip, WarFoundryCore.INFINITY);
 			Assert.AreEqual(WarFoundryCore.INFINITY, unit.GetEquipmentAmount(equip));
 			Assert.IsFalse(unit.GetEquipmentAmountIsRatio(equip));
 		}
+		
+		[Test()]
+		public void TestRemoveNumericAmountEquipmentRemovesEquipmentSelection()
+		{
+			UnitEquipmentItem equip = new MockNumericAmountUnitEquipmentItem();
+			UnitType unitType = equip.EquipmentForUnit;
+			Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory));
+			unit.SetEquipmentAmount(equip, WarFoundryCore.INFINITY);
+			unit.SetEquipmentAmount(equip, 0);
+			Assert.AreEqual(0, unit.GetEquipmentAmount(equip));
+		}
+		
+		[Test()]
+		public void TestAddPercentageAmountEquipmentAddsEquipmentSelection()
+		{
+			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
+			UnitType unitType = equip.EquipmentForUnit;
+			Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory));
+			unit.SetEquipmentRatio(equip, 50);
+			Assert.AreEqual(50, unit.GetEquipmentAmount(equip));
+			Assert.IsTrue(unit.GetEquipmentAmountIsRatio(equip));
+		}
+		
+		[Test()]
+		public void TestRemovePercentageAmountEquipmentRemovesEquipmentSelection()
+		{
+			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
+			UnitType unitType = equip.EquipmentForUnit;
+			Unit unit = new Unit(unitType, new MockArmyCategory(unitType.MainCategory));
+			unit.SetEquipmentRatio(equip, 50);
+			unit.SetEquipmentRatio(equip, 0);
+			Assert.AreEqual(0, unit.GetEquipmentAmount(equip));
+		}
+		
+		[Test()]
+		public void TestAddNumericAmountOfPercentageAmountEquipmentAddsEquipmentSelection()
+		{
+			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
+			UnitType unitType = equip.EquipmentForUnit;
+			Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory));
+			unit.Size = 5;
+			unit.SetEquipmentAmount(equip, 2);
+			Assert.AreEqual(2, unit.GetEquipmentAmount(equip));
+			Assert.IsFalse(unit.GetEquipmentAmountIsRatio(equip));
+		}
+		
+		[Test()]
+		public void TestRemoveNumericAmountOfPercentageAmountEquipmentRemovesEquipmentSelection()
+		{
+			UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem();
+			UnitType unitType = equip.EquipmentForUnit;
+			Unit unit = new MockUnit(unitType, new MockArmyCategory(unitType.MainCategory));
+			unit.Size = 5;
+			unit.SetEquipmentAmount(equip, 2);
+			unit.SetEquipmentAmount(equip, 0);
+			Assert.AreEqual(0, unit.GetEquipmentAmount(equip));
+		}
 	}
 }
--- a/IBBoard.WarFoundry.API.Tests.csproj	Fri Oct 23 19:57:03 2009 +0000
+++ b/IBBoard.WarFoundry.API.Tests.csproj	Sat Oct 24 13:26:37 2009 +0000
@@ -53,7 +53,9 @@
     <Compile Include="API\Objects\Mock\MockArmyCategory.cs" />
     <Compile Include="API\Objects\Mock\MockArmy.cs" />
     <Compile Include="API\Objects\Mock\MockCategory.cs" />
-    <Compile Include="API\Objects\Mock\MockUnitEquipmentItem.cs" />
+    <Compile Include="API\Objects\Mock\MockNumericAmountUnitEquipmentItem.cs" />
+    <Compile Include="API\Objects\Mock\MockPercentageAmountUnitEquipmentItem.cs" />
+    <Compile Include="API\Objects\Mock\MockUnit.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="testdata\Test.race">