void unittest () { cout << "\nSTARTING UNIT TEST\n\n"; Spaceship enterprise; enterprise.setName("USS Enterprise"); try { btassert<bool>(enterprise.getName() == "USS Enterprise"); cout << "Passed TEST 1: setName/getName\n"; } catch (bool b) { cout << "# FAILED TEST 1 setName/getName #\n"; } enterprise.setTopSpeed(9.6); try { btassert<bool>(enterprise.getTopSpeed() >= 9.59 && enterprise.getTopSpeed() <= 9.61); cout << "Passed TEST 2: setTopSpeed/getTopSpeed\n"; } catch (bool b) { cout << "# FAILED TEST 2 setTopSpeed/getTopSpeed #\n"; } enterprise.setFuelSource("plasma"); try { btassert<bool>(enterprise.getFuelSource() == "plasma"); cout << "Passed TEST 3: setFuelSource/getFuelSource\n"; } catch (bool b) { cout << "# FAILED TEST 3 setFuelSource/getFuelSource #\n"; } enterprise.setCrewCapacity(5000); try { btassert<bool>(enterprise.getCrewCapacity() == 5000); cout << "Passed TEST 4: setCrewCapacity/getCrewCapacity\n"; } catch (bool b) { cout << "# FAILED TEST 4 setCrewCapacity/getCrewCapacity #\n"; } try { btassert<bool>(enterprise.toString() == "USS Enterprise, top speed: warp 9.60, fuel source: plasma, crew capacity: 5000"); cout << "Passed TEST 5: toString\n"; } catch (bool b) { cout << "# FAILED TEST 5 toString #\n"; } cout << "\nUNIT TEST COMPLETE\n\n"; }
void SpaceshipValidator::validate(const Spaceship & s) { string errors; if (s.getName().size() < 3) errors += string("The spaceship name cannot be less than 2 characters!\n"); if (!isupper(s.getCaptain()[0])) errors += string("The captain's name must start with a capital letter!\n"); if (s.getType().size() < 3) errors += string("The spaceship type cannot be less than 2 characters!\n"); if (errors.size() > 0) throw ValidationException(errors); /*if (errors.size() > 0) throw ValidationExceptionInherited(errors);*/ }