1- #include " ../include/Queue.h"
1+ #include " ../include/Queue.h"
2+ #include < cassert>
3+ #include < iostream>
4+
5+ int main (int argc, char * argv[]){
6+ Queue<int > que;
7+ assert (que.empty () == true );
8+ assert (que.size () == 0 );
9+ std::cout << " Initial test PASSED!" << std::endl;
10+ try {
11+ que.pop ();
12+ std::cerr << " pop() throw exception FAILED!" << std::endl;
13+ } catch (const std::underflow_error &e){
14+ std::cout << " pop() throw an exception PASSED! " << e.what () << std::endl;
15+ }
16+ que.push (37 );
17+ assert (que.empty () == false );
18+ assert (que.size () == 1 );
19+ assert (que.front () == que.back ());
20+ que.pop ();
21+ assert (que.empty () == true );
22+ assert (que.size () == 0 );
23+ try {
24+ que.front ();
25+ std::cerr << " front() throw exception FAILED!" << std::endl;
26+ } catch (const std::underflow_error &e){
27+ std::cout << " front() throw an exception PASSED! " << e.what () << std::endl;
28+ }
29+ try {
30+ que.back ();
31+ std::cerr << " back() throw exception FAILED!" << std::endl;
32+ } catch (const std::underflow_error &e){
33+ std::cout << " back() throw an exception PASSED! " << e.what () << std::endl;
34+ }
35+ que.push (13 );
36+ que.push (23 );
37+ que.push (31 );
38+ que.push (7 ); // 13 23 31 7
39+ assert (que.back () == 7 );
40+ assert (que.front () == 13 );
41+ assert (que.size () == 4 );
42+ assert (que.empty () == false );
43+ que.pop ();
44+ que.push (19 );
45+ que.pop (); // 31 7 19
46+ assert (que.back () == 19 );
47+ assert (que.front () == 31 );
48+ std::cout << " ALL TEST PASSED!" << std::endl;
49+ return 0 ;
50+ }
0 commit comments