Question: JAVA Overview: Download the existing code for the SetPartition class. The functionality of the class is described below. Two versions of the class are provided:
JAVA
Overview:
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.
Create the JUnit tester E10tester.java which tests each of the methods in the class.
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
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?
A
SetPartition
implements the following:
the constructor, 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.
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:
ordinary valid inputs work.
ordinary invalid inputs fail.
edge cases (exceptional or boundary cases) are checked.
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:
https://mason.gmu.edu/~iavramo2/classes/cs211/labs/E10files.zip
Submission:
Submission instructions are as follows.
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/
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!
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
compress the folder and its contents into a .zip file, and upload the file to Blackboard.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
