public bool addGetWeapons(Unit unit, Weapon weapon, string expectedValue) { unit.addWeapon(weapon); List<Weapon> weapons = unit.Weapons; Weapon returnedWeapon = weapons[weapons.IndexOf(weapon)]; return (returnedWeapon.name == expectedValue); }
public void addWeapon(Weapon weapon) { if (Weapons == null) { Weapons = new List<Weapon>(); } Weapons.Add(weapon); }
public void runUnitTests() { _groupTestID = 1; _testID = 0; printTestGroupSetup("Unit Tests"); Unit unit; UnitTester unitTest = new UnitTester(); // Tests _testID ++; printSetup("Set/get 'type' property"); unit = new Unit(_testID); printResult(unitTest.setGetCommonProperty(unit, "infantry")); _testID ++; printSetup("Set/get unit-specific property"); unit = new Unit(_testID); printResult(unitTest.setGetUnitSpecificProperty(unit, "hit points", 25)); _testID ++; printSetup("Change existing property value"); unit = new Unit(_testID); string property = "hit points"; unit.setProperties(property, 25); printResult(unitTest.changeExistingPropertyValue(unit, property, 15)); _testID ++; printSetup("Get a non-existing property value"); unit = new Unit(_testID); printResult(unitTest.getNonExistentProperty(unit, "strength")); _testID ++; printSetup("Add an existing property."); unit = new Unit(_testID); printResult(unitTest.addExistingProperty(unit, property, 15)); _testID ++; printSetup("Get the 'id' property"); unit = new Unit(_testID); printResult(unitTest.getIDProperty(unit, _testID)); _testID ++; printSetup("Set/get 'name' property"); unit = new Unit(_testID); printResult(unitTest.setGetNameProperty(unit, "Chuck")); _testID ++; printSetup("Add/get 'weapon' property"); unit = new Unit(_testID); string weaponName = "Axe"; Weapon weapon = new Weapon(weaponName); printResult(unitTest.addGetWeapons(unit, weapon, weaponName)); Console.WriteLine(); }
static void Main(string[] args) { Unit unit; int testID; UnitTester tester = new UnitTester(); // ID 1 testID = 1; unit = new Unit(testID); printResult(tester.setGetCommonProperty(unit, "infantry"), testID); // ID 2 testID = 2; unit = new Unit(testID); printResult(tester.setGetUnitSpecificProperty(unit, "hit points", 25), testID); // ID 3 testID = 3; unit = new Unit(testID); string property = "hit points"; unit.setProperties(property, 25); printResult(tester.changeExistingPropertyValue(unit, property, 15), testID); // ID 4 testID = 4; unit = new Unit(testID); printResult(tester.getNonExistentProperty(unit, "strength"), testID); // ID 5: Add an existing item testID = 5; unit = new Unit(testID); printResult(tester.addExistingProperty(unit, property, 15), testID); // ID 6 testID = 6; unit = new Unit(testID); printResult(tester.getIDProperty(unit, testID), testID); // ID 7 testID = 7; unit = new Unit(testID); printResult(tester.setGetNameProperty(unit, "Chuck"), testID); // ID 8 testID = 8; unit = new Unit(testID); Weapon weapon = new Weapon(); printResult(tester.addGetWeapons(unit, weapon), testID); Console.ReadKey(); }
public bool addGetWeapons(Unit unit, Weapon weapon) { unit.addWeapon(weapon); return (unit.Weapons.Contains(weapon)); }