Example #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);
 }
 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);
 }
        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);
        }
Example #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();
        }
Example #5
0
 public bool getNonExistentProperty(Unit unit, string property)
 {
     try
     {
         return (unit.getProperties(property) == null);
     }
     catch (Exception)
     {
         return false;
     }
 }
Example #6
0
 public void addUnit(Unit unit)
 {
     if (_units.Keys.Contains(unit.ID))
     {
         _units[unit.ID] = unit;
     }
     else
     {
         _units.Add(unit.ID, unit);
     }
 }
Example #7
0
 public bool getNonExistentProperty(Unit unit, string property)
 {
     try
     {
         return (unit.getProperties(property) == null);
     }
     catch (NullReferenceException ex)
     {
         Console.WriteLine(ex.Message);
         return true;
     }
 }
Example #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;
     }
 }
Example #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();
            }
        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;
            }
        }
Example #11
0
 public void removeUnit(Unit unit)
 {
     _units.Remove(unit.ID);
 }
Example #12
0
 public bool addGetWeapons(Unit unit, Weapon weapon)
 {
     unit.addWeapon(weapon);
     return (unit.Weapons.Contains(weapon));
 }
Example #13
0
 internal protected void RemoveUnit(Unit unit)
 {
     units.Remove(unit);
 }
Example #14
0
 internal protected void AddUnit(Unit unit)
 {
     units.Add(unit);
 }
Example #15
0
 public bool setGetCommonProperty(Unit unit, string type)
 {
     unit.Type = type;
     return (unit.Type == type);
 }
Example #16
0
 public bool getIDProperty(Unit unit, int id)
 {
     return (unit.ID == id);
 }
 public bool addUnit(UnitGroup unitGroup, Unit inputUnit, Unit expectedOutputUnit)
 {
     unitGroup.addUnit(inputUnit);
     Unit returnedUnit = unitGroup.getUnit(inputUnit.ID);
     return (expectedOutputUnit.ID == returnedUnit.ID);
 }
Example #18
0
 public bool setGetUnitSpecificProperty(Unit unit, string property, object value)
 {
     unit.setProperties(property, value);
     return (unit.getProperties(property) == value);
 }
Example #19
0
 public void AddUnit(Unit unit, int xPosition, int yPosition)
 {
     GetTile(xPosition, yPosition).AddUnit(unit);
 }
Example #20
0
 public bool setGetNameProperty(Unit unit, string name)
 {
     unit.Name = name;
     return (unit.Name == name);
 }
Example #21
0
 public bool changeExistingPropertyValue(Unit unit, string property, object newValue)
 {
     unit.setProperties(property, newValue);
     return (unit.getProperties(property) == newValue);
 }
Example #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();
        }
 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);
 }
Example #24
0
 public void RemoveUnit(Unit unit, int xPosition, int yPosition)
 {
     GetTile(xPosition, yPosition).RemoveUnit(unit);
 }
        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;
        }