CITS5501 lab 3 (week 4) – ISP

Consider the Javadoc documentation and signature for the following Java method, which searches inside an array of chars for a particular value.

(Adapted from the Android version of the Java standard library.)

/**
 * Performs a binary search for @code value in the ascending sorted
 * array @code array, in the range specified by fromIndex (inclusive)
 * and toIndex (exclusive).  Searching in an unsorted array has an
 * undefined result. It's also undefined which element is found if there
 * are multiple occurrences of the same element.
 *
 * @param array the sorted array to search.
 * @param startIndex the inclusive start index.
 * @param endIndex the exclusive start index.
 * @param value the element to find.
 * @return the non-negative index of the element, or a negative index
 *         which is <code>-index - 1</code> where the element would be
 *         inserted.
 * @throws IllegalArgumentException if <code>startIndex > endIndex</code>
 * @throws ArrayIndexOutOfBoundsException if
 *         <code>startIndex < 0 || endIndex > array.length</code>
 * @since 1.6
 */
public static int binarySearch(char[] array, int startIndex, int endIndex, char value)

Based on what you have seen in lectures and the prescribed reading, discuss how you would go about creating tests using Input Space Partitioning.

  1. What steps are involved in doing ISP?
  2. What is the input domain here?
  3. What are some characteristics you could use? Check with a partner (or small group), and make sure each characteristic does give you a partitioning.

2. Stack class

Suppose we have a Stack class that stores ints, with the following method signatures:

Assume the object state consists of an int array.

  1. If we wanted to model push as a function, what sort of function would we use? How about pop?
  2. Identify all the parameters for the pop method, and suggest some characteristics that can be used to partition the input space.

3. Discussion questions

Discuss the following questions about ISP in pairs or a small group, and come up with answers:

  1. Suppose we need to test some method (let’s suppose it is a static method myMethod that takes one int for the sake of argument, and that it’s sensible to partition it into positive, negative and 0-valued ints. i.e. the signature is static myMethod(int i)).

    Suppose you’ve already written three tests for the function; each of your 3 tests uses a test value from one partition.

    Your supervisor says three tests is not enough, and you should write more. What do you think? Would more tests be better? Could more tests be worse?

  2. Research suggests that the later in the development life cycle a fault is discovered, the more expensive it is to fix. Why do you think this is so?