#ifndef HIDDENACCEPTANCETESTS_H_ #define HIDDENACCEPTANCETESTS_H_ #include #include "TimeTable.h" // ------------------------------------------------------------------------- /** * This test class shows how one might specify acceptance criteria for an * assignment using a series of test cases. * * @author Stephen Edwards * @version Feb 22, 2005 */ class HiddenAcceptanceTests : public CxxTest::TestSuite { public: //~ Methods ............................................................... // ---------------------------------------------------------- /** * Sets up the test fixture. * Called automatically before every test case method. */ void setUp() { int hour = 10; std::string description = "CS 1705"; app1 = new Appointment( hour, description ); hour = 13; description = "MATH 1506"; app2 = new Appointment( hour, description ); } // ---------------------------------------------------------- /** * Tears down the test fixture. * Called automatically after every test case method. */ void tearDown() { delete app1; delete app2; } // ---------------------------------------------------------- /** * Test that the hour accessor works as expected. */ void testHour() { TS_ASSERT_EQUALS( 10, app1->hour() ); TS_ASSERT_EQUALS( 13, app2->hour() ); } // ---------------------------------------------------------- /** * Test that the description accessor works as expected. */ void testDescription() { TS_ASSERT_EQUALS( "CS 1705", app1->description() ); TS_ASSERT_EQUALS( "MATH 1506", app2->description() ); } // ---------------------------------------------------------- /** * Test that the setHour() setter works. */ void testSetHour() { app1->setHour( 15 ); TS_ASSERT_EQUALS( 15, app1->hour() ); } // ---------------------------------------------------------- /** * Test that the setDescription() setter works. */ void testSetDescription() { app1->setDescription( "CS 1104" ); TS_ASSERT_EQUALS( "CS 1104", app1->description() ); } // ---------------------------------------------------------- /** * Test that the setTime() setter works. */ void testSetTime() { TS_ASSERT_EQUALS( 10, app1->hour() ); app1->setTime( "3pm" ); TS_ASSERT_EQUALS( 15, app1->hour() ); app1->setTime( "11am" ); TS_ASSERT_EQUALS( 11, app1->hour() ); app1->setTime( "11pm" ); TS_ASSERT_EQUALS( 23, app1->hour() ); } // ---------------------------------------------------------- /** * Test that setTime() works with noon and midnight values. */ void testSetTime2() { app1->setTime( "12pm" ); TS_ASSERT_EQUALS( 12, app1->hour() ); app1->setTime( "12am" ); TS_ASSERT_EQUALS( 0, app1->hour() ); } // ---------------------------------------------------------- /** * Test that toString() works. */ void testToString() { TS_ASSERT_EQUALS( "10am: CS 1705", app1->toString() ); TS_ASSERT_EQUALS( "1pm: MATH 1506", app2->toString() ); } // ---------------------------------------------------------- /** * Test that setTime() and toString() work for noon and midnight. */ void testToString2() { app1->setTime( "12pm" ); TS_ASSERT_EQUALS( "12pm: CS 1705", app1->toString() ); app1->setTime( "12am" ); TS_ASSERT_EQUALS( "12am: CS 1705", app1->toString() ); } // ---------------------------------------------------------- /** * Test a TimeTable holding some appointments. */ void testTimeTable() { TimeTable* timetable = new TimeTable(); timetable->addAppointment( 1, *app1 ); timetable->addAppointment( 3, *app1 ); timetable->addAppointment( 5, *app1 ); timetable->addAppointment( 1, *app2 ); timetable->addAppointment( 3, *app2 ); timetable->addAppointment( 5, *app2 ); TS_ASSERT_EQUALS( *app1, timetable->appointmentFor( 3, 10 ) ); TS_ASSERT_EQUALS( *app2, timetable->appointmentFor( 3, 13 ) ); delete timetable; } private: //~ Instance/static variables ............................................. Appointment* app1; Appointment* app2; }; #endif /*HIDDENACCEPTANCETESTS_H_*/