-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_spec_catch.cpp
59 lines (46 loc) · 1.22 KB
/
stack_spec_catch.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
//#define BOOST_TEST_ALTERNATIVE_INIT_API
//#include <boost/test/included/unit_test.hpp>
//#include <boost/algorithm/string.hpp>
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
//==============================================================================
#include <stack>
template <typename T>
class Stack {
public:
void push(const T &t) { m_stack.push(t); }
void pop()
{
if (!m_stack.empty())
m_stack.pop();
}
bool empty() const { return m_stack.empty(); }
std::size_t size() const { return m_stack.size(); }
private:
std::stack<T> m_stack;
};
//==============================================================================
SCENARIO("a stack", "[stack]") {
Stack<int> stack;
SECTION("when initialised") {
SECTION("should be empty") {
REQUIRE(stack.empty());
}
}
SECTION("pop") {
SECTION("on an empty stack") {
SECTION("should have no effect") {
stack.pop();
REQUIRE(stack.empty());
}
}
SECTION("on a stack with a single member") {
stack.push(1);
SECTION("should reduce the stack size by one") {
std::size_t orig_size = stack.size();
stack.pop();
REQUIRE(stack.size() == orig_size - 1);
}
}
}
}