Mercurial > repos > IBDev-IBBoard.WarFoundry.API.Tests
changeset 183:bd38c32fb1a9
Re #366: Rewrite equipment handling and limits
* Remove comment added during #356 - now resolved
* Add test for behaviour of percentages
* Add test for new "calculate number taken" util method
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Sat, 12 Nov 2011 20:36:58 +0000 |
parents | e9be63d72b3c |
children | 00ea622313be |
files | API/Objects/UnitEquipmentLimitTests.cs API/Objects/UnitEquipmentRatioSelectionTests.cs API/Util/UnitEquipmentUtilTest.cs IBBoard.WarFoundry.API.Tests.csproj |
diffstat | 4 files changed, 67 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/API/Objects/UnitEquipmentLimitTests.cs Sun Nov 06 21:02:00 2011 +0000 +++ b/API/Objects/UnitEquipmentLimitTests.cs Sat Nov 12 20:36:58 2011 +0000 @@ -48,8 +48,6 @@ Assert.That(UnitEquipmentUtil.GetMaxEquipmentCount(unit, unitEquip2), Is.EqualTo(0)); Assert.That(unit.Points, Is.EqualTo(33)); unit.SetEquipmentRatio(unitEquip2, 0.7); - //FIXME: Current values based on pre-Ticket 366 expectations (adding equipment that rounds up - // adds to amount, even if it goes over the limit) Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2)); Assert.That(unit.Points, Is.EqualTo(35)); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/API/Objects/UnitEquipmentRatioSelectionTests.cs Sat Nov 12 20:36:58 2011 +0000 @@ -0,0 +1,51 @@ +// This file (UnitEquipmentRatioSelectionTests.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.Util; +using IBBoard.WarFoundry.API.Factories; +using IBBoard.Limits; +using NUnit.Framework.SyntaxHelpers; + +namespace IBBoard.WarFoundry.API.Objects +{ + [TestFixture()] + public class UnitEquipmentRatioSelectionTests + { + [Test()] + public void Bug366TestAmountIsNotLimitedByAbsoluteAmount() + { + DummyWarFoundryFactory factory = new DummyWarFoundryFactory(); + Race race = new Race("race", "Race", new GameSystem("gs", "System", factory), factory); + Category cat = new Category("cat1", "Category"); + race.AddCategory(cat); + EquipmentItem equip1 = new EquipmentItem("equip1", "Equipment 1", race); + race.AddEquipmentItem(equip1); + EquipmentItem equip2 = new EquipmentItem("equip2", "Equipment 2", race); + race.AddEquipmentItem(equip2); + UnitType unitType = new UnitType("type1", "UnitType", race); + unitType.AddEquipmentSlot("slot", new SimpleRoundedPercentageLimit(33, true)); + UnitEquipmentItem unitEquip1 = new UnitEquipmentItem(equip1, unitType); + unitEquip1.SlotName = "slot"; + unitEquip1.RoundNumberUp = true; + unitEquip1.MinLimit = new SimpleRoundedPercentageLimit(0); + unitEquip1.MaxLimit = new SimpleRoundedPercentageLimit(33, true); + UnitEquipmentItem unitEquip2 = new UnitEquipmentItem(equip2, unitType); + unitEquip2.SlotName = "slot"; + unitEquip2.RoundNumberUp = true; + unitEquip2.MinLimit = new SimpleRoundedPercentageLimit(0); + unitEquip2.MaxLimit = new SimpleRoundedPercentageLimit(33, true); + race.AddUnitType(unitType); + Army army = new Army(race, "army", 1000); + Unit unit = new Unit(unitType, army.GetCategory(cat)); + unit.Size = 3; + unit.SetEquipmentAmount(unitEquip1, 1); + unit.SetEquipmentRatio(unitEquip2, 33); + Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(33)); + Assert.That(UnitEquipmentUtil.GetEquipmentAmountTaken(unit, unitEquip2), Is.EqualTo(1)); + Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2)); + } + } +} +
--- a/API/Util/UnitEquipmentUtilTest.cs Sun Nov 06 21:02:00 2011 +0000 +++ b/API/Util/UnitEquipmentUtilTest.cs Sat Nov 12 20:36:58 2011 +0000 @@ -8,6 +8,7 @@ using IBBoard.Limits; using IBBoard.WarFoundry.API.Objects; using IBBoard.WarFoundry.API.Objects.Mock; +using NUnit.Framework.SyntaxHelpers; namespace IBBoard.WarFoundry.API.Util { @@ -427,6 +428,20 @@ Unit unit = GetUnit(unitType); Assert.IsFalse(UnitEquipmentUtil.IsEquipmentRatioLimited(unit, equip)); } + + [Test()] + public void TestCalculateEquipmentAmountTakenFromRatio() + { + UnitEquipmentItem equip = new MockPercentageAmountUnitEquipmentItem(); + UnitType unitType = equip.EquipmentForUnit; + Unit unit = GetUnit(unitType); + Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 33.4), Is.EqualTo(5)); + Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 50), Is.EqualTo(7)); + equip.RoundNumberUp = true; + Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 33.4), Is.EqualTo(6)); + Assert.That(UnitEquipmentUtil.CalculateEquipmentAmountTakenFromRatio(unit, equip, 50), Is.EqualTo(8)); + + } private Unit GetUnit (UnitType unitType) {
--- a/IBBoard.WarFoundry.API.Tests.csproj Sun Nov 06 21:02:00 2011 +0000 +++ b/IBBoard.WarFoundry.API.Tests.csproj Sat Nov 12 20:36:58 2011 +0000 @@ -110,6 +110,7 @@ <Compile Include="API\Factories\AbstractNativeWarFoundryFactoryTest.cs" /> <Compile Include="API\Factories\Mock\MockNativeWarFoundryFactory.cs" /> <Compile Include="API\Objects\UnitEquipmentLimitTests.cs" /> + <Compile Include="API\Objects\UnitEquipmentRatioSelectionTests.cs" /> </ItemGroup> <ItemGroup> <None Include="app.config" />