forked from NoaAmsalem/ex3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueExampleTests.cpp
More file actions
124 lines (99 loc) · 2.34 KB
/
Copy pathQueueExampleTests.cpp
File metadata and controls
124 lines (99 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "Queue.h"
#include "iostream"
#define AGREGATE_TEST_RESULT(res, cond) (res) = ((res) && (cond))
static bool isEven(int n)
{
return (n % 2) == 0;
}
static void setFortyTwo(int& n)
{
n = 42;
}
namespace QueueTests {
bool testQueueMethods()
{
bool testResult = true;
Queue<int> queue1;
queue1.pushBack(1);
queue1.pushBack(2);
int front1 = queue1.front();
AGREGATE_TEST_RESULT(testResult, front1 == 1);
queue1.front() = 3;
front1 = queue1.front();
AGREGATE_TEST_RESULT(testResult, front1 == 3);
queue1.popFront();
front1 = queue1.front();
AGREGATE_TEST_RESULT(testResult, front1 == 2);
int size1 = queue1.size();
AGREGATE_TEST_RESULT(testResult, size1 == 1);
return testResult;
}
bool testModuleFunctions()
{
bool testResult = true;
Queue<int> queue3;
for (int i = 1; i <= 10; i++) {
queue3.pushBack(i);
}
Queue<int> queue4 = filter(queue3, isEven);
for (int i = 2; i <= 10; i+=2) {
int front4 = queue4.front();
AGREGATE_TEST_RESULT(testResult, front4 == i);
queue4.popFront();
}
Queue<int> queue5;
for (int i = 1; i <= 5; i++) {
queue5.pushBack(i);
}
transform(queue5, setFortyTwo);
for (Queue<int>::Iterator i = queue5.begin(); i != queue5.end(); ++i) {
AGREGATE_TEST_RESULT(testResult,(*i == 42));
}
return testResult;
}
bool testExceptions()
{
bool testResult = true;
bool exceptionThrown = false;
Queue<int> queue6;
try {
queue6.front() = 5;
}
catch (Queue<int>::EmptyQueue& e) {
exceptionThrown = true;
}
AGREGATE_TEST_RESULT(testResult, exceptionThrown);
exceptionThrown = false;
Queue<int>::Iterator endIterator = queue6.end();
try {
++endIterator;
}
catch (Queue<int>::Iterator::InvalidOperation& e) {
exceptionThrown = true;
}
AGREGATE_TEST_RESULT(testResult, exceptionThrown);
return testResult;
}
bool testConstQueue()
{
bool testResult = true;
Queue<int> queue5;
for (int i = 1; i <= 5; i++) {
queue5.pushBack(42);
}
const Queue<int> constQueue = queue5;
for (Queue<int>::ConstIterator i = constQueue.begin(); i != constQueue.end(); ++i) {
AGREGATE_TEST_RESULT(testResult, (*i == 42));
}
bool exceptionThrown = false;
Queue<int>::ConstIterator endConstIterator = constQueue.end();
try {
++endConstIterator;
}
catch (Queue<int>::ConstIterator::InvalidOperation& e) {
exceptionThrown = true;
}
AGREGATE_TEST_RESULT(testResult, exceptionThrown);
return testResult;
}
}