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.
E10tester.java
which tests each of the methods in the class.
{1, 2, 3, 4, 5, 6, 7, 8, 9 10}
Then the following are all examples of partitions of the set:
{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}
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?
SetPartition
implements the following:
SetPartition
, takes no parameters and initializes an empty set.
public int size(T elem)
returns the total number of elements which are in the same subset as elem
. So for examle, suppose the set is {1, 2, 3, 4, 5}
while the subsets are {1, 2, 4}
and {3, 5}
. Then size(2)
would return 3 because there are three elements in the subset {1, 2, 4}
.
public boolean sameSubSet(T elem1, T elem2)
check whether elements elem1
and elem2
are part of the same subset.
public void merge(T elem1, T elem2)
takes the subset which elem1
belongs to, and combine it with the subset which elem2
belongs to, to form one big subset. If they are already part of the same subset, then it has no effect. For example, for the set {1, 2, 3, 4, 5}
, suppose the subsets are {1, 3}
, {2}
, and {4, 5}
. Then merge(2,5)
would result in a partition containing two subsets, {1, 3}
and {2, 4, 5}
.
public void add(T elem)
adds the given element to the set.
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:
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
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
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 |
Submission instructions are as follows.
xxx_yyyyyyyy_E10/
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!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