SWE/CS 332 In Class Exercise # 4


Name(s):

Goals: (A) (more) converting preconditions into postconditions, and (B) Basic JUnit tests.

A: Consider the following three excerpts from the java collection classes documentation:

  1. Why are all three of these constraints preconditions?


  2. HashSet implements both the Set and Iterator interface (the former directly, and the latter through the iterator() method). Have either of the first two preconditions above been converted into postconditions via the exception handling mechanism?


  3. How do you know?


  4. Can you guess at the likely reason that these two cases are handled differently?





B: Consider the contract for the min method from slide 15 of today's PPT.
  1. Generate tests, both inputs and expected outputs, from this contract.


  2. How many tests do you think you need?


  3. What does this exercise have to do with contract quality?