CSE 373 Winter 2005

Homework #4

Testing LinkedList and BinarySearchTree

Due:

electronically Wednesday, March 9, 8:00 pm; paperwork at beginning of class Friday.  Turn-In Form.

Objectives

JCoverage tool setup

Description

1. In the class, we have learned how to test some methods of LinkedList. In this exercise, you will test a LinkedList. This class contains the following public methods:

Constructor:
public LinkedList(){ ... }

Methods with void returns:
public void addFirst(Object item) { ... }
public void removeFirst() { ... } 
public void reverse() { ... }

Methods with non-void returns:
public boolean contains(Object item) { ... }
public Object getFirst() { ... }
public int size() { ... }
public boolean equals(Object other) { ... }
public String toString() { ... }

We have prepared a a JUnit test class called LinkedListTest.java for you. In this class, we simply add a test method to test the constructor method. In this test class, you need to add test methods to fulfill the following testing tasks. You need to create meaningful names for your test methods, such as "testContainsWithEmptyList". You also need to document some statements within your test methods with comments if their test purposes are not easy to understand by just reading the code, such as "//boundary value 1 for the test condition s.size()" or "//cover statement: throw new NoSuchElementException();".  They not only help others read your test code but only help yourself check whether you have generated enough tests to cover the program under test. But note that don't write unnecessary comments for those statements that are simple or whose behavior can be easily understood. For example, it is unnecessary to write "//construct a LinkedList object" for the statement of "LinkedList t = new LinkedList();". 

2. In this exercise, you will test a BinarySearchTree (note that we deliberately comment out the remove method so that you don't need to test it in this exercise). This class contains the following public methods:

Constructor:
public BinarySearchTree(){ ... }

Methods with void returns:
public void add(Integer info) { ... }

Methods with non-void returns:
public int size() { ... }
public boolean equals(Object other) { ... }
public String toString() { ... }

We have prepared a a JUnit test class called BinarySearchTreeTest.java for you. In this class, we simply add a test method to test the constructor method. In this test class, you need to add test methods to fulfill the following testing tasks. Similar to testing LinkedList, you need to create meaningful names for your test methods. You also need to document your test methods with comments.

Note: Reorganize your code so that the classes are all in a package called "hw4"  (the provided LinkedList.java, LinkedListTest.java, BinarySearchTree.java, and BinarySearchTreeTest.java already contain the correct package declaration).  You will need to move the files into a directory with the name of "hw4".

Turn in:

Electronically, the .java files, by 8:00 p.m. XXXXXX.
On paper, at beginning of class XXXXXXX: printouts of the programs (the preferred way to do this is to print the "receipt" you get back from the turn-in form), plus a short report which includes:
Please staple everything together.  There might not be a stapler in the classroom, so please do this in advance.  Make sure your name is on everything you turn in!  Your student ID is not needed unless we specifically request it.

Grading

Most of the grading points will come from
Correct structuring of the packaging
Good luck and have fun!


Notes
If you have questions along the way, either about the assignment or how to do things, feel free to discuss it on the Message Board.  Just don't give away code, or any crucial aspects of the solution.

Where applicable, write your code to be reusable and modifiable.  In a later homework, you might in fact have an opportunity to reuse or modify code from this one...