CS/SWE 332 Assignment 2
Fall 2020
Goal:
Contracts
For the second assignment, you'll build a very small piece of Java
for a contract with preconditions,
transform the contract so that all preconditions become postconditions,
and then re-implement appropriately.
Here's the initial contract:
public static int findDup (int[] a, int[] b)
// Precondition: a not null;
// b not null
// There is some index i such that a[i] == b[i]
//
// Postcondition: return the first index i at which a[i] == b[i]
// E.g. findDup ([7, 13, 5], [5, 13, 5]) = 1
-
Implement the
FindDup
method.
Remember that checking for violated preconditions
is not necessary in the contract model.
To emphasize this point, your solution must be minimal.
This means that it should not be possible to delete
any code and still have your implementation satisfy the contract.
You should test your implementation;
this is an obvious task
for the part of your group responsible for checking your solution.
-
Transform the preconditions into postconditions
as discussed in class.
-
Re-implement.
Grading:
- Statement of who completed the exercise.
- Statement of who checked the exercise.
- Minimal implementation for contract with preconditions.
- Correctly transformed contract.
- Appropriate implementation for transformed contract.
- A reasonable set of JUnit tests for each implementation.
- A reasonable explanation of why the solutions are correct.