-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
49 lines (38 loc) · 1.15 KB
/
test.cpp
File metadata and controls
49 lines (38 loc) · 1.15 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
#define BOOST_TEST_MAIN
#ifdef BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#else
#include <boost/test/included/unit_test.hpp>
#endif
#include <algorithm>
#include <iterator>
#include <stdexcept>
#include "stack.h"
struct StackFixture {
constexpr static int maxSize{100};
Stack<double, maxSize> stack{};
double testValues[3]{1., 2., 3.};
};
BOOST_FIXTURE_TEST_CASE(testEmptyStack, StackFixture) {
BOOST_CHECK(stack.size() == 0);
BOOST_CHECK_THROW(stack.pop(), std::out_of_range);
}
BOOST_FIXTURE_TEST_CASE(testPushPop, StackFixture) {
auto stackSize = 0;
const auto pushFunctor = [&](auto value) {
stack.push(value);
BOOST_CHECK(stack.size() == ++stackSize);
};
std::for_each(std::cbegin(testValues), std::cend(testValues), pushFunctor);
const auto popFunctor = [&](auto value) {
BOOST_CHECK(stack.pop() == value);
BOOST_CHECK(stack.size() == --stackSize);
};
std::for_each(std::crbegin(testValues), std::crend(testValues), popFunctor);
}
BOOST_FIXTURE_TEST_CASE(testOverflow, StackFixture) {
for (auto i = 0; i < maxSize; ++i) {
stack.push(0.);
}
BOOST_CHECK_THROW(stack.push(0.), std::out_of_range);
}