SWE 619 Assignment 4
Fall 2023


Goal: Rep-Invariants, contracts, tests.
Consider Bloch's array-based, generic, mutable Stack example. Here's the code: Stack.java If you wish, you can ignore the pushAll() and popAll() methods in this assignment. You can also ignore the suppression of compiler warnings.

  1. Develop a decent rep-invariant. Hint: Your rep-invariant should definitely consider what values are allowed in various parts of the array.
  2. Implement repOk().
  3. Introduce a fault (i.e. "bug") that breaks the rep-invariant. Try to do this with a small (conceptual) change to the code. Show that the rep-invariant is broken with a JUnit test.
  4. Analyzed your bug with respect to the contracts of other methods in the Stack class. Does your invariant-breaking bug affect the correctness argument for any of these methods?
  5. Do you think your fault is realistic? Why or why not?

As in assignment 3, your deliverable is a story, with exactly the same rationale. Take screenshots (e.g. of failing JUnit tests) as necessary to make your case.

Grading: