SlideShare a Scribd company logo
1 of 9
Download to read offline
I need help creating a parametized JUnit test case for the following class.
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import static java.lang.Integer.valueOf;
public class IntegerSet {
/**
* The only instance variable in the class. No other variables allowed.
*/
private List list;
public int size() {
return list.size();
}
public boolean isEmpty() {
return list.isEmpty();
}
/**
* Initializes the empty set.
*/
public IntegerSet() {
list = new LinkedList();
}
/**
* Initializes a set with the numbers in the argument.
*/
public IntegerSet(Integer[] integers) {
this();
if (integers == null) {
throw new NullPointerException("The argument cannot be null");
} else {
for (Integer i : integers) {
if (!exists(i)) {
this.insertElement(i);
}
}
}
Collections.sort(list);
}
/**
* Inserts an integer to the set if the integer does not exist in the set
*/
public void insertElement(int i) {
if (!list.contains(i)) {
list.add(i);
}
}
/**
* Inserts to the set all the integers in the argument which do not exist in
* the set.
*/
public void insertAll(Integer[] data) {
if (data == null) {
throw new NullPointerException("The argument cannot be null");
// throw new
// IllegalArgumentException("The argument cannot be null");
} else {
Arrays.sort(data);
for (Integer num : data) {
if (!exists(num)) {
insertElement(num);
}
}
}
}
/**
* Deletes an integer from the set if it exists in the set.
*/
public void deleteElement(int i) {
list.remove(i);
}
/**
* Deletes all the elements in the set.
*/
public void deleteAll() {
list.clear();
}
/**
* Returns true if the argument exists in the set, false otherwise.
*/
public boolean exists(int i) {
return list.contains(i);
}
public String toString() {
char delimiter = ' ';
String str = "[";
for (Integer i : list) {
str += i;
str += delimiter;
}
return str + "]";
}
/**
* Finds the union of two sets. A null pointer is considered an empty set.
*
* Return "new IntegerSet()" when the result is an empty set.
*/
public static IntegerSet union(IntegerSet set1, IntegerSet set2) {
IntegerSet union = new IntegerSet();
if (set1.isEmpty() && set2.isEmpty()) {
return union;
}
if (!set1.list.isEmpty()) {
for (Integer num : set1.list) {
if (!union.list.contains(num)) {
union.list.add(num);
}
}
}
if (!set2.isEmpty()) {
for (Integer num : set2.list) {
if (!union.list.contains(num)) {
union.list.add(num);
}
}
}
return union;
}
/**
* Finds the intersection of two sets. A null pointer is considered an empty
* set.
*
* Return "new IntegerSet()" when the result is an empty set.
*/
public static IntegerSet intersection(IntegerSet set1, IntegerSet set2) {
IntegerSet intersection = new IntegerSet();
// check for null pointers
if (set1.list.isEmpty() || set2.list.isEmpty()) {
return intersection;
}
for (Integer num : set1.list) {
if ((!intersection.list.contains(num)) && set2.list.contains(num)) {
intersection.list.add(num);
}
}
return intersection;
}
/**
* Builds an array with the elements in the set.
*/
public Integer[] toArray() {
Integer[] alist;
Object[] s = list.toArray();
alist = new Integer[s.length];
for (int i = 0; i < s.length; i++) {
alist[i] = valueOf((Integer) s[i]);
}
Arrays.sort(alist);
return alist;
}
}
I'm not very good with JUnit. Could I get some help with how I'm supposed to set up a test case
like this?
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class IntegerSetTest {
public IntegerSetTest() {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() {
fail("Not yet implemented");
}
@Parameters
public void testIntersectionWithNullInput() {
}
@Parameters
public void testExists() {
}
@Parameters
public void testIsEmpty() {
}
@Parameters
public void testUnion() {
}
@Parameters
public void testCreateSetFromArray() {
}
@Parameters
public void testCreateSetFromNull() {
}
@Parameters
public void testDeleteAll() {
}
@Parameters
public void testDeleteEntry(){
}
@Parameters
public void testINsertAll(){
}
@Parameters
public void testAllNull(){
}
@Parameters
public void testIntersection(){
}
@Parameters
public void testUnionWithNullInput(){
}
}
Solution
package com.game;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.Parameterized.Parameters;
@FixMethodOrder
public class IntegerSetTest {
public IntegerSetTest() {
}
@Test
public void testUnion() {
Integer[] int1 = {1,2};
IntegerSet set1 = new IntegerSet(int1);
Integer[] int2 = {3,4};
IntegerSet set2 = new IntegerSet(int2);
IntegerSet unionResult = new IntegerSet();
IntegerSet set = unionResult.union(set1, set2);
Assert.assertEquals("Union of two integer sets are equal",4, set.size());
}
@Test
public void testCreateSetFromArray() {
Integer[] int1 = {1,2};
IntegerSet set1 = new IntegerSet(int1);
Assert.assertEquals("Successfully created a set from Array",2,set1.size());
}
@Test
public void testCreateSetFromNull() {
try{
IntegerSet set1 = new IntegerSet(null);
}catch(Exception e){
Assert.assertEquals("Successfully got exception error needed","The argument cannot be
null",e.getMessage());
}
}
@Test
public void testDeleteAll() {
Integer[] int1 = {1,2};
IntegerSet set1 = new IntegerSet(int1);
set1.deleteAll();
Assert.assertEquals("Successfully deletes all entries from Set",0,set1.size());
}
@Parameters
public void testDeleteEntry(){
}
@Parameters
public void testINsertAll(){
Integer[] int1 = {1,2};
IntegerSet set1 = new IntegerSet();
set1.insertAll(int1);
Assert.assertEquals("Successfully inserts all entries from Set",2,set1.size());
}
}

More Related Content

Similar to Create Parametized JUnit Tests for IntegerSet Class

New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfabbecindia
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfarpaqindia
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfapoorvikamobileworld
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfaksahnan
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfarihantpatna
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxStewartt0kJohnstonh
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfakritigallery
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdfgudduraza28
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfinfo430661
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdfaryan9007
 

Similar to Create Parametized JUnit Tests for IntegerSet Class (20)

New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Complete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdfComplete the class ArraySet1java which implements the SetA.pdf
Complete the class ArraySet1java which implements the SetA.pdf
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Tdd
TddTdd
Tdd
 
import java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdfimport java.util.;public class FirstChars {    public static vo.pdf
import java.util.;public class FirstChars {    public static vo.pdf
 
Hi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdfHi,I have added the methods and main class as per your requirement.pdf
Hi,I have added the methods and main class as per your requirement.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
 
Array list
Array listArray list
Array list
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
Java generics
Java genericsJava generics
Java generics
 
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdfSorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 ReverseList.javaimport java.util.ArrayList;public class Rever.pdf ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
ReverseList.javaimport java.util.ArrayList;public class Rever.pdf
 

More from fonecomp

write a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdfwrite a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdffonecomp
 
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdfwrite 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdffonecomp
 
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdfWhy do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdffonecomp
 
What was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdfWhat was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdffonecomp
 
Who are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdfWho are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdffonecomp
 
What sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdfWhat sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdffonecomp
 
What are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdfWhat are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdffonecomp
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdffonecomp
 
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdfSharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdffonecomp
 
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdfQuantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdffonecomp
 
Neeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdfNeeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdffonecomp
 
Describe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdfDescribe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdffonecomp
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdffonecomp
 
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdfHarrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdffonecomp
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdffonecomp
 
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdfHow do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdffonecomp
 
General question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdfGeneral question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdffonecomp
 
Describe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdfDescribe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdffonecomp
 
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdffonecomp
 
A single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdfA single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdffonecomp
 

More from fonecomp (20)

write a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdfwrite a program that prompts the user to enter the center of a recta.pdf
write a program that prompts the user to enter the center of a recta.pdf
 
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdfwrite 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
write 3 3 slide on China and Germany. Individual work (1) Choose a c.pdf
 
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdfWhy do negotiations fail O Conflicts are boring O Conflicts are co.pdf
Why do negotiations fail O Conflicts are boring O Conflicts are co.pdf
 
What was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdfWhat was the court-packing plan, and why is it sig- nificant to a.pdf
What was the court-packing plan, and why is it sig- nificant to a.pdf
 
Who are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdfWho are the major stakeholders that Sony must consider when developi.pdf
Who are the major stakeholders that Sony must consider when developi.pdf
 
What sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdfWhat sort of prevention techniques would be useful when dealing with.pdf
What sort of prevention techniques would be useful when dealing with.pdf
 
What are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdfWhat are the main three types of organizational buyers How are they.pdf
What are the main three types of organizational buyers How are they.pdf
 
The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdfSharks are able to maintain their fluids hypertonic to the ocean env.pdf
Sharks are able to maintain their fluids hypertonic to the ocean env.pdf
 
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdfQuantum Bank Inc. is a regional bank with branches throughout the so.pdf
Quantum Bank Inc. is a regional bank with branches throughout the so.pdf
 
Neeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdfNeeb Corporation manufactures and sells a single product. The com.pdf
Neeb Corporation manufactures and sells a single product. The com.pdf
 
Describe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdfDescribe the primary, secondary, and tertiary structure of DNASo.pdf
Describe the primary, secondary, and tertiary structure of DNASo.pdf
 
I need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdfI need help with this program for java.The program you are given t.pdf
I need help with this program for java.The program you are given t.pdf
 
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdfHarrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
Harrison works in a cubicle at a window next to Karen Ravenwoods cu.pdf
 
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdfHi there I am having difficulty in finalizing my Tetris game , below.pdf
Hi there I am having difficulty in finalizing my Tetris game , below.pdf
 
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdfHow do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
How do the genomes of Archaea and Bacteria compare Drag and drop th.pdf
 
General question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdfGeneral question How would the technology affect who lives and who .pdf
General question How would the technology affect who lives and who .pdf
 
Describe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdfDescribe how partial diploids can be produced in E. coli.Solutio.pdf
Describe how partial diploids can be produced in E. coli.Solutio.pdf
 
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf4.2Why is there waiting in an infinite-source queuing systemmul.pdf
4.2Why is there waiting in an infinite-source queuing systemmul.pdf
 
A single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdfA single layer of gold atoms lies on a table. The radius of each gol.pdf
A single layer of gold atoms lies on a table. The radius of each gol.pdf
 

Recently uploaded

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 

Recently uploaded (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 

Create Parametized JUnit Tests for IntegerSet Class

  • 1. I need help creating a parametized JUnit test case for the following class. import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; import static java.lang.Integer.valueOf; public class IntegerSet { /** * The only instance variable in the class. No other variables allowed. */ private List list; public int size() { return list.size(); } public boolean isEmpty() { return list.isEmpty(); } /** * Initializes the empty set. */ public IntegerSet() { list = new LinkedList(); } /** * Initializes a set with the numbers in the argument. */ public IntegerSet(Integer[] integers) { this(); if (integers == null) { throw new NullPointerException("The argument cannot be null"); } else { for (Integer i : integers) { if (!exists(i)) { this.insertElement(i); }
  • 2. } } Collections.sort(list); } /** * Inserts an integer to the set if the integer does not exist in the set */ public void insertElement(int i) { if (!list.contains(i)) { list.add(i); } } /** * Inserts to the set all the integers in the argument which do not exist in * the set. */ public void insertAll(Integer[] data) { if (data == null) { throw new NullPointerException("The argument cannot be null"); // throw new // IllegalArgumentException("The argument cannot be null"); } else { Arrays.sort(data); for (Integer num : data) { if (!exists(num)) { insertElement(num); } } } } /** * Deletes an integer from the set if it exists in the set. */ public void deleteElement(int i) { list.remove(i); }
  • 3. /** * Deletes all the elements in the set. */ public void deleteAll() { list.clear(); } /** * Returns true if the argument exists in the set, false otherwise. */ public boolean exists(int i) { return list.contains(i); } public String toString() { char delimiter = ' '; String str = "["; for (Integer i : list) { str += i; str += delimiter; } return str + "]"; } /** * Finds the union of two sets. A null pointer is considered an empty set. * * Return "new IntegerSet()" when the result is an empty set. */ public static IntegerSet union(IntegerSet set1, IntegerSet set2) { IntegerSet union = new IntegerSet(); if (set1.isEmpty() && set2.isEmpty()) { return union; } if (!set1.list.isEmpty()) { for (Integer num : set1.list) { if (!union.list.contains(num)) { union.list.add(num);
  • 4. } } } if (!set2.isEmpty()) { for (Integer num : set2.list) { if (!union.list.contains(num)) { union.list.add(num); } } } return union; } /** * Finds the intersection of two sets. A null pointer is considered an empty * set. * * Return "new IntegerSet()" when the result is an empty set. */ public static IntegerSet intersection(IntegerSet set1, IntegerSet set2) { IntegerSet intersection = new IntegerSet(); // check for null pointers if (set1.list.isEmpty() || set2.list.isEmpty()) { return intersection; } for (Integer num : set1.list) { if ((!intersection.list.contains(num)) && set2.list.contains(num)) { intersection.list.add(num); } } return intersection; } /** * Builds an array with the elements in the set. */ public Integer[] toArray() {
  • 5. Integer[] alist; Object[] s = list.toArray(); alist = new Integer[s.length]; for (int i = 0; i < s.length; i++) { alist[i] = valueOf((Integer) s[i]); } Arrays.sort(alist); return alist; } } I'm not very good with JUnit. Could I get some help with how I'm supposed to set up a test case like this? import static org.junit.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) public class IntegerSetTest { public IntegerSetTest() { } @Before public void setUp() throws Exception { } @After public void tearDown() throws Exception { } @Test public void test() { fail("Not yet implemented"); } @Parameters
  • 6. public void testIntersectionWithNullInput() { } @Parameters public void testExists() { } @Parameters public void testIsEmpty() { } @Parameters public void testUnion() { } @Parameters public void testCreateSetFromArray() { } @Parameters public void testCreateSetFromNull() { } @Parameters public void testDeleteAll() { } @Parameters public void testDeleteEntry(){ } @Parameters public void testINsertAll(){ } @Parameters public void testAllNull(){
  • 7. } @Parameters public void testIntersection(){ } @Parameters public void testUnionWithNullInput(){ } } Solution package com.game; import org.junit.Assert; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.Parameterized.Parameters; @FixMethodOrder public class IntegerSetTest { public IntegerSetTest() { } @Test public void testUnion() { Integer[] int1 = {1,2}; IntegerSet set1 = new IntegerSet(int1); Integer[] int2 = {3,4};
  • 8. IntegerSet set2 = new IntegerSet(int2); IntegerSet unionResult = new IntegerSet(); IntegerSet set = unionResult.union(set1, set2); Assert.assertEquals("Union of two integer sets are equal",4, set.size()); } @Test public void testCreateSetFromArray() { Integer[] int1 = {1,2}; IntegerSet set1 = new IntegerSet(int1); Assert.assertEquals("Successfully created a set from Array",2,set1.size()); } @Test public void testCreateSetFromNull() { try{ IntegerSet set1 = new IntegerSet(null); }catch(Exception e){ Assert.assertEquals("Successfully got exception error needed","The argument cannot be null",e.getMessage()); } } @Test public void testDeleteAll() { Integer[] int1 = {1,2}; IntegerSet set1 = new IntegerSet(int1); set1.deleteAll(); Assert.assertEquals("Successfully deletes all entries from Set",0,set1.size()); } @Parameters
  • 9. public void testDeleteEntry(){ } @Parameters public void testINsertAll(){ Integer[] int1 = {1,2}; IntegerSet set1 = new IntegerSet(); set1.insertAll(int1); Assert.assertEquals("Successfully inserts all entries from Set",2,set1.size()); } }