forked from HEI-SYND-226-SDi/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
110 lines (100 loc) · 2.46 KB
/
main.cpp
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
#include <functional>
#include <iostream>
#include "stack.hpp"
#include "utils/test.hpp"
int main() {
std::cout << "\n\n"
<< "*************************\n"
<< "* Running unit tests... *\n"
<< "*************************\n";
test(" -> Stack functionality", []() {
Stack<int> stack(3);
try {
stack.push(1);
stack.push(2);
stack.push(3);
} catch (std::out_of_range) {
return false;
}
if (stack.pop() != 3) {
return false;
}
if (stack.pop() != 2) {
return false;
}
if (stack.pop() != 1) {
return false;
}
return true;
});
test(" -> Push to full stack with move semantics", []() {
Stack<int> stack(3);
try {
stack.push(0);
stack.push(0);
stack.push(0);
} catch (std::out_of_range) {
return false;
}
try {
stack.push(0);
} catch (std::out_of_range) {
return true;
}
return false;
});
test(" -> Push to full stack with copy semantics", []() {
int a = 0;
Stack<int> stack(3);
try {
stack.push(a);
stack.push(a);
stack.push(a);
} catch (std::out_of_range) {
return false;
}
try {
stack.push(a);
} catch (std::out_of_range) {
return true;
}
return false;
});
test(" -> Pop from empty stack", []() {
Stack<int> stack(3);
try {
stack.push(0);
stack.push(0);
stack.pop();
stack.pop();
} catch (std::out_of_range) {
return false;
}
try {
stack.pop();
} catch (std::out_of_range) {
return true;
}
return false;
});
test(" -> Push to stack with 0 capacity", []() {
Stack<int> stack(0);
try {
stack.push(0);
} catch (std::out_of_range) {
return true;
}
return false;
});
test(" -> Pop from stack with 0 capacity", []() {
Stack<int> stack(0);
try {
stack.pop();
} catch (std::out_of_range) {
return true;
}
return false;
});
std::cout << "** \033[32mALL TESTS PASSED, congrats!\033[0m **";
return 0;
}