SWE 637 Homework 3
Fall 2017
TDD & Subsumption

Due 25-September, beginning of class


Never test for a bug you don't know how to fix.
— Mike McCracken

Answer the following questions. Bring hardcopies of your answers to class; either hand written or printouts. All homeworks are due before class on the due date. You may use one of the collaborative options as specified on the syllabus, but any help not allowed by that policy will be an honor code violation.

  1. (15 pts.) This question is based on Ammann & Offutt, edition 2, Exercises chapter 4, Number 1. Instead of Calc.java, as the question in the book uses, we will implement a Stack class. You can choose your own internal representation for your Stack, but I suggest keeping it simple. Thus, you can use an array structure, linked list of nodes, or something else. You can also have the stack store any type of element you wish; below I use <TYPE> to indiciate that you should use the type of your stack.

    Use test driven design to add the following functionalities, in this order.

    1. push (<TYPE> X) // Place X on the top of the stack
    2. <TYPE> top () // Return the element on the top of the stack
    3. <TYPE> pop () // Remove the element on the top of the stack and return it
    4. int sizeOf () // Returns the current number of elements on the stack

    First create a failing test for the next functionality, modify the class until the test passes, then perform any refactoring needed. Repeat until all of the required functionality has been added to your stack and all tests pass. Remember that in TDD, the tests determine the requirements. This means you must encode decisions about the functions (for example, exception handling) in automated tests before modifying the software. Submit printouts of all tests, your final version of the stack, and a screen shot showing that all tests pass.

    Most importantly, include a narrative describing each TDD test created, the changes needed to make it pass, rnd any refactoring that was necessary.

  2. (5 pts.) Ammann & Offutt, edition 2, Exercises chapter 5, Number 2.