コード例 #1
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;
     }
 }
コード例 #2
0
ファイル: Tester.cs プロジェクト: MarkPThomas/HeadFirst-OOAD
        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();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: MarkPThomas/HeadFirst-OOAD
        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();
            }
コード例 #4
0
 public bool changeExistingPropertyValue(Unit unit, string property, object newValue)
 {
     unit.setProperties(property, newValue);
     return (unit.getProperties(property) == newValue);
 }
コード例 #5
0
 public bool setGetUnitSpecificProperty(Unit unit, string property, object value)
 {
     unit.setProperties(property, value);
     return (unit.getProperties(property) == value);
 }