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);
        }
        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;
            }
        }
        public bool getAllUnits(UnitGroup unitGroup, List<Unit> expectedOutputUnits)
        {
            bool matchingID = false;
            List<Unit> outputUnits = unitGroup.getUnits();
            foreach (Unit unitOutput in outputUnits)
            {
                matchingID = false;
                foreach (Unit unitExpected in expectedOutputUnits)
                {
                    if (unitExpected.ID == unitOutput.ID)
                    {
                        matchingID = true;
                        break;
                    }
                }
                if (!matchingID) { break; }
            }

            return matchingID;
        }
        public bool initializeClass(List<Unit> inputUnits, List<Unit> expectedOutputUnits)
        {
            bool matchingID = false;
            UnitGroup unitGroup = new UnitGroup(inputUnits);
            List<Unit> outputUnits = unitGroup.getUnits();
            foreach (Unit unitOutput in outputUnits)
            {
                matchingID = false;
                foreach (Unit unitExpected in expectedOutputUnits)
                {
                    if (unitExpected.ID == unitOutput.ID)
                    {
                        matchingID = true;
                        break;
                    }
                }
                if (!matchingID) { break; }
            }

            return matchingID;
        }
示例#6
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 addUnit(UnitGroup unitGroup, Unit inputUnit, Unit expectedOutputUnit)
 {
     unitGroup.addUnit(inputUnit);
     Unit returnedUnit = unitGroup.getUnit(inputUnit.ID);
     return (expectedOutputUnit.ID == returnedUnit.ID);
 }
        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;
        }
 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);
 }
 public bool removeUnitByID(UnitGroup unitGroup, int inputID, List<Unit> expectedOutputUnits)
 {
     unitGroup = new UnitGroup(expectedOutputUnits);
     unitGroup.removeUnit(inputID);
     List<Unit> units = unitGroup.getUnits();
     return !validateUnitInList(units, inputID);
 }