Chapter 18 Exercise Set 0: Chapter ReviewΒΆ
Using what you did in Chapter 17 Exercise Set 0: Chapter Review as a model, set up automated unit tests for stacks, including a
Makefile
, asrc
subdirectory,Stack.h
, andtest_stacks.cpp
files.Add the following tests to
test_stacks.cpp
:TEST_CASE("Test basic stack operations on stack of ints") { Stack<int> stack; stack.push(9); CHECK(stack.top() == 9); stack.push(11); CHECK(stack.top() == 11); stack.push(42); CHECK(stack.top() == 42); CHECK(stack.pop() == 42); CHECK(stack.top() == 11); CHECK(stack.empty() == false); stack.pop(); CHECK(stack.pop() == 9); CHECK(stack.empty() == true); }
Add the following tests to
test_stacks.cpp
:TEST_CASE("Test basic stack operations on stack of strings") { Stack<string> stack; stack.push("cheese"); CHECK(stack.top() == "cheese"); stack.push("anchovies"); CHECK(stack.top() == "anchovies"); stack.push("onions"); CHECK(stack.top() == "onions"); CHECK(stack.pop() == "onions"); CHECK(stack.top() == "anchovies"); CHECK(stack.empty() == false); stack.pop(); CHECK(stack.pop() == "cheese"); CHECK(stack.empty() == true); }
Write your own tests for a stack of user defined objects (
Card
perhaps?).Run your test suite with all three implementations of the Stack ADT that were introduced in the chapter.