Question: How to build a JUnit tester for setPartition class based on a given template in JAVA This is the setPartition class import java.util.*; public class

How to build a JUnit tester for setPartition class based on a given template in JAVA

This is the setPartition class

import java.util.*;

public class SetPartition { ArrayList list = new ArrayList<>(); ArrayList reps = new ArrayList<>(); public SetPartition() {} public int size() { return list.size(); } // optional method public int size(T elem) { int i = list.indexOf(elem); if (i < 0) return 0; T rep = reps.get(i); int count = 0; for (T subset : reps) { if (rep.equals(subset)) count++; } return count; } public boolean sameSubSet(T elem1, T elem2) { int i = list.indexOf(elem1); int j = list.indexOf(elem2); if (i < 0 || j < 0) return false; return reps.get(i).equals(reps.get(j)); } public void merge(T elem1, T elem2) { int i1 = list.indexOf(elem1); int i2 = list.indexOf(elem2); if (i1 < 0 || i2 < 0) return; T r1 = reps.get(i1); T r2 = reps.get(i2); for (int j = 0; j < reps.size(); j++) { if (reps.get(j) == r2) reps.set(j, r1); } }

public void add(T elem) { list.add(elem); reps.add(elem); } public void remove(T elem) { // option method int i = list.indexOf(elem); if (i < 0) return; if (reps.get(i) == list.get(i)) { T subset = null; for (int j = 0; j < list.size(); j++) { if (reps.get(j) == reps.get(i) && list.get(i) != list.get(j)) { subset = list.get(j); break; } } if (subset != null) { for (int j = 0; j < list.size(); j++) { if (reps.get(j) == reps.get(i)) reps.set(j, subset); } }

} list.remove(i); reps.remove(i); } public String subsetString(T subset) { // optional method String result = "{"; int count = 0; for (int i = 0; i < reps.size(); i++) { if (reps.get(i) != subset) continue; if (count++ > 0) result += ", "; result += list.get(i).toString(); } return result + "}"; } public String toString() { // optional method ArrayList seen = new ArrayList<>(); String result = ""; for (T subset : reps) { if (seen.contains(subset)) continue; if (seen.size() > 0) result += ", "; seen.add(subset); result += subsetString(subset); } return result; } }

This is the template for the tester:

import org.junit.*; import static org.junit.Assert.*;

public class E10tester { public static void main(String[] args) { // what goes here to run the tests? } @Test public void check_constructor() { SetPartition set = new SetPartition<>(); assertEquals(0, set.size()); } // include more tests below }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!