Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public bool updateUnit(UnitGroup unitGroup, Unit inputUnit, Unit expectedOutputUnit)
 {
     unitGroup.addUnit(inputUnit);
     unitGroup.addUnit(expectedOutputUnit);
     Unit returnedUnit = unitGroup.getUnit(inputUnit.ID);
     return (expectedOutputUnit.ID == returnedUnit.ID &&
             expectedOutputUnit.Name == returnedUnit.Name);
 }
Exemplo n.º 3
0
        public bool getUnitByID(UnitGroup unitGroup, int inputID, Unit expectedOutputUnit)
        {
            Unit startingUnit = new Unit(inputID);
            unitGroup = new UnitGroup(new List<Unit>() { startingUnit });

            Unit returnedUnit = unitGroup.getUnit(inputID);
            return (expectedOutputUnit.ID == returnedUnit.ID);
        }
Exemplo n.º 4
0
        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();
        }
Exemplo n.º 5
0
 public bool getNonExistentProperty(Unit unit, string property)
 {
     try
     {
         return (unit.getProperties(property) == null);
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemplo n.º 6
0
 public void addUnit(Unit unit)
 {
     if (_units.Keys.Contains(unit.ID))
     {
         _units[unit.ID] = unit;
     }
     else
     {
         _units.Add(unit.ID, unit);
     }
 }
Exemplo n.º 7
0
 public bool getNonExistentProperty(Unit unit, string property)
 {
     try
     {
         return (unit.getProperties(property) == null);
     }
     catch (NullReferenceException ex)
     {
         Console.WriteLine(ex.Message);
         return true;
     }
 }
Exemplo n.º 8
0
 public bool addExistingProperty(Unit unit, string property, object newValue)
 {
     try
     {
         unit.setProperties(property, newValue);
         unit.setProperties(property, newValue);
         return (unit.getProperties(property) == newValue);
     }
     catch (Exception)
     {
         return false;
     }
 }
Exemplo n.º 9
0
        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();
            }
Exemplo n.º 10
0
        public bool getUnitByNonExistingID(UnitGroup unitGroup, int inputID)
        {
            Unit startingUnit = new Unit(inputID);
            unitGroup = new UnitGroup(new List<Unit>() { startingUnit });

            int nonExistingID = inputID + 1;

            try
            {
                Unit returnedUnit = unitGroup.getUnit(nonExistingID);
                return false;
            }
            catch (KeyNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return true;
            }
        }
Exemplo n.º 11
0
 public void removeUnit(Unit unit)
 {
     _units.Remove(unit.ID);
 }
Exemplo n.º 12
0
 public bool addGetWeapons(Unit unit, Weapon weapon)
 {
     unit.addWeapon(weapon);
     return (unit.Weapons.Contains(weapon));
 }
Exemplo n.º 13
0
 internal protected void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
 }
Exemplo n.º 14
0
 internal protected void AddUnit(Unit unit)
 {
     units.Add(unit);
 }
Exemplo n.º 15
0
 public bool setGetCommonProperty(Unit unit, string type)
 {
     unit.Type = type;
     return (unit.Type == type);
 }
Exemplo n.º 16
0
 public bool getIDProperty(Unit unit, int id)
 {
     return (unit.ID == id);
 }
Exemplo n.º 17
0
 public bool addUnit(UnitGroup unitGroup, Unit inputUnit, Unit expectedOutputUnit)
 {
     unitGroup.addUnit(inputUnit);
     Unit returnedUnit = unitGroup.getUnit(inputUnit.ID);
     return (expectedOutputUnit.ID == returnedUnit.ID);
 }
Exemplo n.º 18
0
 public bool setGetUnitSpecificProperty(Unit unit, string property, object value)
 {
     unit.setProperties(property, value);
     return (unit.getProperties(property) == value);
 }
Exemplo n.º 19
0
 public void AddUnit(Unit unit, int xPosition, int yPosition)
 {
     GetTile(xPosition, yPosition).AddUnit(unit);
 }
Exemplo n.º 20
0
 public bool setGetNameProperty(Unit unit, string name)
 {
     unit.Name = name;
     return (unit.Name == name);
 }
Exemplo n.º 21
0
 public bool changeExistingPropertyValue(Unit unit, string property, object newValue)
 {
     unit.setProperties(property, newValue);
     return (unit.getProperties(property) == newValue);
 }
Exemplo n.º 22
0
        public void runGroupTests()
        {
            _groupTestID = 2;
            _testID = 0;
            printTestGroupSetup("Group Tests");
            Unit unit;
            
            UnitGroup unitGroup; 
            UnitGroupTester groupTest = new UnitGroupTester();

            // Tests
            _testID ++;
            printSetup("Initializing class with list of units");
            List<Unit> units = new List<Unit>() { new Unit(1000), new Unit(2000), new Unit(3000), new Unit(4000) };
            printResult(groupTest.initializeClass(units, units));

            _testID ++;
            printSetup("Adding a unit");
            unit = new Unit(_testID);
            unitGroup = new UnitGroup(new List<Unit>());
            printResult(groupTest.addUnit(unitGroup, unit, unit));

            _testID ++;
            printSetup("Adding a unit that already has been added");
            unit = new Unit(_testID);
            unit.Name = "Old Unit";
            Unit unitUpdated = new Unit(_testID);
            unitUpdated.Name = "New Unit";    
            unitGroup = new UnitGroup(new List<Unit>());
            printResult(groupTest.updateUnit(unitGroup, unit, unitUpdated));

            _testID ++;
            printSetup("Getting a unit by ID that exists");
            unitGroup = new UnitGroup(new List<Unit>());
            unit = new Unit(_testID);
            printResult(groupTest.getUnitByID(unitGroup, _testID, unit));

            _testID ++;
            printSetup("Getting a unit by ID that doesn't exist");
            unitGroup = new UnitGroup(new List<Unit>());
            unit = new Unit(_testID);
            printResult(groupTest.getUnitByNonExistingID(unitGroup, _testID));

            _testID ++;
            printSetup("Getting all units");
            units = new List<Unit>() { new Unit(1000), new Unit(2000), new Unit(3000), new Unit(4000) };
            unitGroup = new UnitGroup(units);
            printResult(groupTest.getAllUnits(unitGroup, units));

            _testID ++;
            printSetup("Removing a unit by ID that exists");
            unitGroup = new UnitGroup(new List<Unit>());
            // Units list that contains a unit with the supplied unit ID
            units = new List<Unit>() { new Unit(_testID), new Unit(_testID + 1), new Unit(_testID + 2), new Unit(_testID + 3), new Unit(_testID + 4) };
            printResult(groupTest.removeUnitByID(unitGroup, _testID, units));

            _testID ++;
            printSetup("Removing a unit by ID that doesn't exist");
            unitGroup = new UnitGroup(new List<Unit>());
            // Units list that doesn't contain any units with the supplied unit ID
            units = new List<Unit>() { new Unit(_testID+1), new Unit(_testID + 2), new Unit(_testID + 3), new Unit(_testID + 4) };
            printResult(groupTest.removeUnitByIDNonExisting(unitGroup, _testID, units));

            _testID ++;
            printSetup("Removing a unit that exists by the unit instance");
            unit = new Unit(_testID);
            unitGroup = new UnitGroup(new List<Unit>());
            // Units list that contains a unit with the supplied unit ID
            units = new List<Unit>() { new Unit(_testID), new Unit(_testID + 1), new Unit(_testID + 2), new Unit(_testID + 3), new Unit(_testID + 4) };
            printResult(groupTest.removeUnitByObjectInstance(unitGroup, unit, units));

            _testID ++;
            printSetup("Removing a unit that doesn't exist by the unit instance");
            unit = new Unit(_testID);
            unitGroup = new UnitGroup(new List<Unit>());
            // Units list that doesn't contain any units with the supplied unit ID
            units = new List<Unit>() { new Unit(_testID + 1), new Unit(_testID + 2), new Unit(_testID + 3), new Unit(_testID + 4) };
            printResult(groupTest.removeUnitByNonExistingObjectInstance(unitGroup, unit, units));

            Console.WriteLine();
        }
Exemplo n.º 23
0
 public bool removeUnitByObjectInstance(UnitGroup unitGroup, Unit inputUnit, List<Unit> expectedOutputUnits)
 {
     unitGroup = new UnitGroup(expectedOutputUnits);
     unitGroup.removeUnit(inputUnit);
     List<Unit> units = unitGroup.getUnits();
     return !validateUnitInList(units, inputUnit.ID);
 }
Exemplo n.º 24
0
 public void RemoveUnit(Unit unit, int xPosition, int yPosition)
 {
     GetTile(xPosition, yPosition).RemoveUnit(unit);
 }
Exemplo n.º 25
0
        public bool removeUnitByNonExistingObjectInstance(UnitGroup unitGroup, Unit inputUnit, List<Unit> expectedOutputUnits)
        {
            unitGroup = new UnitGroup(expectedOutputUnits);
            unitGroup.removeUnit(inputUnit);

            List<Unit> units = unitGroup.getUnits();

            // Check that unit no longer exists
            if (validateUnitInList(units, inputUnit.ID)) { return false; }

            // Check that the list is unaltered
            if (!validateUnitsListUnaltered(units, expectedOutputUnits)) { return false; }

            return true;
        }