CS 211, 004/006
Lab Exercise-10
due Thursday, November 15th at noon


Testing is an important part of program design, because not only does it make it easier to track down flaws in our code, but it also allows us to anticipate and avoid problems in code. Fortunately, we have tools available to us which allow us to write test cases which can be run in conjunction with our code. This exercise will involve designing test cases which will be used to debug sample code in order to identify which parts of the code work and which part don't.

Overview:

  1. Download the existing code for the SetPartition class. The functionality of the class is described below. Two versions of the class are provided: a version which works correctly and a version which doesn't.
  2. Create the JUnit tester E10tester.java which tests each of the methods in the class.
  3. Compile and run the tester with both versions of the sample class; one version should pass the tests while the other version should fail at least some of them. Your code, if correctly written, should identify which one.
This is a lab exercise on which collaboration (including discussing the solution on Piazza or searching online sources) is explicitly permitted. It is still in your interest to understand and prepare your final submission yourself.

Background:

Suppose we are given a set of distinct elements. A partition of the set is a way of dividing up the elements into distinct subsets, so that each element belongs to exactly one subset. For example, suppose we have the set {1, 2, 3, 4, 5, 6, 7, 8, 9 10} Then the following are all examples of partitions of the set:

// example 1: individual subsets
{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}

// example 2: one big subset
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

// example 3: several contiguous subsets
{1, 2, 3}, {4, 5}, {6, 7, 8, 9, 10}

// example 4: odd/even
{1, 3, 5, 7, 9}, {2, 4, 6, 8, 10}

A set partition has several of applications, for example detecting connected components in a graph. Typically, when it is used, numbers first added to the set begin by themselves in their own singleton subset. However, there would be a method to merge two subsets to combine them into a larger subset. Operations on the set would include merging two subsets; adding new elements to the set; checking whether two elements are part of the same subset already; and determining the size of an element's subset.

SetPartition:
public class SetPartition<T>

SetPartition implements the following methods. Note that you are not expected to write this class itself. Rather, it is implemented for you, and your goal is to write a tester which will tell you whether it succeeds or fails, and if it fails, then how?

You are given two implementations of this class. One is found in versionA/SetPartition.java while the other is found in versionB/SetPartition.java. One of them is a correct implementation while the other one is not. You are not responsible for knowing how they are implemented, but you are certainly welcome to look!

Task:

You have been provided with a template tester file, E10tester.java. You must first update this template so that it actually runs tests. Once that is working, you should add more tests to properly evaluate whether the implementation works or not. The setup of the tests is up to you, but the general guidelines are that all of the methods listed above should be incorporated into the tests somehow. It's a good idea to make tests which include all of the following:

Note that since the sample implementations are in subdirectories, you should include those subdirectories in the classpath if you want to be able to compile and run. This would look like the following (on Mac/Unix):
javac -cp .:versionA:junit-cs211.jar versionA/SetPartition.java
javac -cp .:versionA:junit-cs211.jar E10tester.java
java -cp .:versionA:junit-cs211.jar E10tester

javac -cp .:versionB:junit-cs211.jar versionB/SetPartition.java
javac -cp .:versionB:junit-cs211.jar E10tester.java
java -cp .:versionB:junit-cs211.jar E10tester

or on Windows:

javac -cp .;versionA;junit-cs211.jar versionA/SetPartition.java
javac -cp .;versionA;junit-cs211.jar E10tester.java
java -cp .;versionA;junit-cs211.jar E10tester

javac -cp .;versionB;junit-cs211.jar versionB/SetPartition.java
javac -cp .;versionB;junit-cs211.jar E10tester.java
java -cp .;versionB;junit-cs211.jar E10tester

For convenience, the build code above is provided as a script as a part of the lab 10 download (see the files e10build.sh for Mac/Unix or e10build.cmd for Windows).

Grading:

Since you are the one responsible for writing the tester this time around, there is no tester program provided. Instead, you will be graded based on the following criteria:

the tester compiles:1
the tester performs unit testing:1
all SetPartition methods are tested:4
the correct sample implementation passes all tests:1
the broken sample implementation fails at least one test:1
one of the implementations passes, the other one fails:1
submission format:1

The sample classes for this project can be found in the following compressed file:

Submission:

Submission instructions are as follows.

  1. Let xxx be your lab section number (one of 213-220), and let yyyyyyyy be your GMU userid. Your userid is your patriot pass login name, not your G number. Create the directory xxx_yyyyyyyy_E10/
  2. Place the tester file you have written, E10tester.java, into the directory that you've created. Be sure to submit the tester rather than the SetPartition code!
  3. Create the file ID.txt in the format shown below, containing your name, userid, G#, lecture section and lab section, and add it to the directory.

    Full Name: Donald Knuth
    userID: dknuth
    G#: 00123456
    Lecture section: 004
    Lab section: 213

  4. compress the folder and its contents into a .zip file, and upload the file to Blackboard.