Stack and Queue: A Unit Testing Exercise
Due: June 12, 2019 @ 11:59PM
Grab the handout tarfile from here: http://cs.millersville.edu/~wkillian/2019/summer/files/csci362/lab4-stack-and-queue.tar
std::stack and std::queue are useful container adapters in the C++ Standard Library. You are tasked with implementing the majority of these classes!
Additionally, I want you to gain exposure with writing tests in C++ using a nice unit testing library called Catch.
There are four deliverables:
Queue.hpp)Stack.hpp)TestQueue.hpp)TestStack.hpp)The first two deliverables are the only ones "autograded", but I am not giving you the autograder! Why? I want you to write you own tests! If you see my tests you might get some crazy ideas.
template <typename T>
class Stack {
    reference       top();
    const_reference top() const;
    bool      empty() const;
    size_type size()  const;
    void push (value_type const&);
    void push (value_type&&);
    void pop();
};
template <typename T>
class Queue {
    reference       front();
    const_reference front() const;
    reference       back();
    const_reference back() const;
    bool      empty() const;
    size_type size()  const;
    void push (value_type const&);
    void push (value_type&&);
    void pop();
};
NOTE: only 16 points of the 75 will be autograded
Catch provides a pretty nice interface for writing tests. I give you a little bit of an example for starters. You are welcome to reference other autograders I've written as well. For this assignment, we will be adopting principles of behavior-driven development (BDD for short). When writing tests in a BDD-way, we always following the same pattern:
SCENARIO("This is what I'm testing", "[stack]") // or queue if testing queue
{
  GIVEN("A state")
  {
    Stack<int> s;
    // set the state of s to what you want
    REQUIRE (precondition1);
    REQUIRE (precondition2);
    ...
    REQUIRE (preconditionN);
    // Note: you may want to preserve information here
    WHEN("I apply an operation")
    {
      s.someCoolOperation();
      THEN("Everything should still work")
      {
        REQUIRE (postcondition1);
        REQUIRE (postcondition2);
        ...
        REQUIRE (postconditionN);
      }
    }
  }
}
YOU SHOULD UNIT TEST EVERY FUNCTION YOU WRITE
Additionally, you should make sure you handle different states (when the stack/queue is empty vs. when it's not).
Use good programming style:
You can generate a tarfile that contains your four modified files (Stack.hpp, Queue.hpp, TestStack.hpp, and TestQueue.hpp) by stating:
make handinor alternatively,
tar cvf handin.tar Stack.hpp Queue.hpp TestStack.hpp TestQueue.hppPlease submit handin.tar to autolab
This lab is graded out of 75 points.