view API/Objects/UnitEquipmentNumericSelectionTests.cs @ 230:d6883a522c70

Re #419: Remove assumptions of a file-based install * Make sure Race files aren't identified as GameSystem files
author IBBoard <dev@ibboard.co.uk>
date Wed, 11 Jul 2012 20:54:12 +0100
parents 00ea622313be
children
line wrap: on
line source

// 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 UnitEquipmentNumericSelectionTests
	{
		[Test()]
		public void Bug366TestAmountIsNotLimitedByRatioAmount()
		{
			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(unitEquip2, 1);
			unit.SetEquipmentRatio(unitEquip1, 33);
			Assert.That(UnitEquipmentUtil.GetEquipmentAmount(unit, unitEquip2), Is.EqualTo(1));
			Assert.That(UnitEquipmentUtil.GetEquipmentAmountTaken(unit, unitEquip2), Is.EqualTo(1));
			Assert.That(unit.GetEquipmentAmountInSlot("slot"), Is.EqualTo(2));
		}
	}
}