# ESOF 422: HW 8
Sam Behrens
## 1. Exercises section 6.1 pg. 85, Question 3, all parts (12 pts, 4 pts each)
Answer the following questions for the method search() below:
```
public static int search (List list, Object element)
// Effects: if list or element is null throw NullPointerException
// else if element is in the list, return an index
// of element in the list; else return -1
// for example, search ([3,3,1], 3) = either 0 or 1
// search([1,7,5], 2) = -1
```
Base your answer on the following characteristic partitioning:
```
Characteristic: Location of element in list
Block 1: element is first entry in list
Block 2: element is last entry in list
Block 3: element is in some position other than first or last
```
(a) “Location of element in list” fails the disjointness property. Give an example that illustrates this.
`search([1], 1)` fails because element 1 is the first entry in the list and the last entry in the list.
(b) “Location of element in list” fails the completeness property. Give an example that illustrates this.
`search([1, 2], 3)` fails because element 3 is not in the list at all.
\(c\) Supply one or more new partitions that capture the intent of “Location of element in list” but do not suffer from completeness or disjointness problems.
```
Characteristic: Location of element in list
Block 1: element is first entry in list
Block 2: element is in some position other than first
Block 3: element is not in list
```
## 2. Exercises section 6.2 pg. 90, Question 4, all parts (12 pts, 2 pts each)
Derive input space partitioning test inputs for the GenericStack class assuming the following method signatures:
- public GenericStack ();
- public void push (Object X);
- public Object pop ();
- public boolean isEmpty ();
Assume the usual semantics for the GenericStack. Try to keep
your partitioning simple and choose a small number of partitions and
blocks.
(a) List all of the input variables, including the state variables.
`X` and the items in the stack
(b) Define characteristics of the input variables. Make sure you cover all input variables.
Number of objects in the stack
Wether `X` is null
\(c\) Define characteristics of inputs.
```
Characteristic 1: Number of objects in stack
```
```
Characteristic 2: Whether X is null
```
(d) Partition the characteristics into blocks.
```
Characteristic 1: Number of objects in stack
Block 1: Stack has 1 object
Block 2: Stack has more than one object
Block 3: Stack is empty
```
```
Characteristic 2: Whether X is null
Block 1: X is null
Block 2: X is not null
```
(e) Define values for each block.
```
Characteristic 1: Number of objects in stack
Block 1: Stack has 1 object
Input: A GenericStack with the string "A".
Block 2: Stack has more than one object
Input: A GenericStack with the string "A" and teh string "B".
Block 3: Stack is empty
Input: A GenericStack with nothing in it.
```
```
Characteristic 2: Whether X is null
Block 1: X is null
Input: X = null
Block 2: X is not null
Input: X = "A"
```