SlideShare una empresa de Scribd logo
1 de 4
Descargar para leer sin conexión
Please create the appropriate JUnit test cases to thoroughly unit test the following
program:
IntegerSet.java
import java.util.*;
public class IntegerSet{
private ArrayList<Integer> list= new ArrayList<>();
public IntegerSet(ArrayList list) {
this.list=list;
}
// clears the all representation of class
public void clear() {
list.clear();
}
// returns the length of set
public int length() {
return list.size();
}
// return true if 2 lists are equal
public boolean equals(IntegerSet b) {
ArrayList<Integer> list2=b.list;
if(list.size()!=list2.size()) {
return false;
}
ArrayList<Integer> temp1=list;
ArrayList<Integer> temp2=list2;
Collections.sort(temp1);
Collections.sort(temp2);
for(int i=0;i<temp1.size();i++) {
if(temp1.get(i)!=temp2.get(i)) {
return false;
}
}
return true;
}
// returns a largest item and throw exception if list is empty
public int largest() throws IntegerSetException {
if(list.size()==0) {
IntegerSetException e= new IntegerSetException();
throw e;
}
int max=0;
for(int i=0;i<list.size();i++) {
if(list.get(i)>max) {
max=list.get(i);
}
}
return max;
}
// returns a largest item and throw exception if list is empty
public int smallest() throws IntegerSetException {
if(list.size()==0) {
IntegerSetException e= new IntegerSetException();
throw e;
}
int min=Integer.MAX_VALUE;
for(int i=0;i<list.size();i++) {
if(list.get(i)<min) {
min=list.get(i);
}
}
return min;
}
// add item if already not exist in list
public void addItem(int item ) {
boolean exist=false;
for(int i=0;i<list.size();i++) {
if(list.get(i)==item) {
exist=true;
}
}
if(exist==false) {
list.add(item);
}
}
// remove item if already not exist in list
public void removeItem(int item ) {
for(int i=0;i<list.size();i++) {
if(list.get(i)==item) {
list.remove(i);
}
}
}
// return union of of 2 sets
public IntegerSet union(IntegerSet list2) {
ArrayList<Integer> temp=list2.getlist();
Set<Integer> set = new HashSet<>();
set.addAll(list);
set.addAll(temp);
ArrayList<Integer> list3= new ArrayList<>(set);
IntegerSet list4= new IntegerSet(list3);
return list4;
}
// return intersection of of 2 sets
public IntegerSet intersection(IntegerSet list2) {
ArrayList<Integer> temp=list2.getlist();
list.retainAll(temp);
IntegerSet list4= new IntegerSet(list);
return list4;
}
// returns difference of 2 sets
public IntegerSet difference (IntegerSet list2) {
ArrayList<Integer> temp=list2.getlist();
// Remove all elements in list2 from list
list.removeAll(temp);
IntegerSet list4= new IntegerSet(list);
return list4;
}
public ArrayList<Integer> getlist(){
return list;
}
}
IntegerSetException.java
class IntegerSetException extends Exception {
Driver.java
import java.util.*;
public class Driver {
public static void main(String[] args) throws IntegerSetException {
ArrayList<Integer> list1= new ArrayList<>();
ArrayList<Integer> list2= new ArrayList<>();
// make 2 instance of integerset class for implementation
IntegerSet set1= new IntegerSet(list1);
IntegerSet set2= new IntegerSet(list2);
set1.addItem(1);
set1.addItem(3);
set1.addItem(4);
set1.addItem(6);
set1.addItem(3);
set1.addItem(8);
set1.addItem(7);
set2.addItem(1);
set2.addItem(2);
set2.addItem(3);
set2.addItem(4);
set2.addItem(5);
set2.addItem(6);
set2.addItem(7);
System.out.println("Set 1 : "+set1.getlist());
System.out.println("Set 2 : "+set2.getlist());
System.out.println("Is equal : "+set1.equals(set2));
System.out.println("Largest element in set1 : "+set1.largestelement());
System.out.println("Smallest element in set2 : "+set2.smallestelement());
IntegerSet setu= set1.union(set2);
System.out.println("Unoin : "+setu.getlist() );
IntegerSet seti= set1.intersection(set2);
System.out.println("Intersection : "+seti.getlist() );
}
}
The JUnit test class should be named IntegerSetTest to be consistent with standard Java
naming conventions. In addition, each method should be named in the format of testXXXX. For
example, if testing the equals(Boolean) method it would look like
public class IntegerSetTest {
@Test
@DisplayName("Test case for equals")
public void testEquals() {
// JUnit test case(s) for equal
}
}
Sufficiently test each public method, you will be graded on how robust your JUnit test cases
are. Note that methods largest() and smallest() potentially throw an exception if invoked and your
IntegerSet is empty. You are to add to add exception handling to these methods and write
JUnit test cases to test the exceptions.

Más contenido relacionado

Similar a Please create the appropriate JUnit test cases to thoroughly.pdf

2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdfarshin9
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
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
 
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
 
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
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...davidwarner122
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
 
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
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfbabitasingh698417
 
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
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfxlynettalampleyxc
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
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
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdfakkhan101
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. StreamsDEVTYPE
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
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
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docxajoy21
 

Similar a Please create the appropriate JUnit test cases to thoroughly.pdf (20)

2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.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
 
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
 
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
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.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
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.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
 
Array list
Array listArray list
Array list
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
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
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
6. Generics. Collections. Streams
6. Generics. Collections. Streams6. Generics. Collections. Streams
6. Generics. Collections. Streams
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
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
 
Write a program that will test a name) method no sorting routine from.docx
 Write a program that will test a name) method no sorting routine from.docx Write a program that will test a name) method no sorting routine from.docx
Write a program that will test a name) method no sorting routine from.docx
 

Más de kitty811

please fix this code so that the tests pass css Selec.pdf
please fix this code so that the tests pass        css Selec.pdfplease fix this code so that the tests pass        css Selec.pdf
please fix this code so that the tests pass css Selec.pdfkitty811
 
please help Below are the ages at which US presidents bega.pdf
please help Below are the ages at which US presidents bega.pdfplease help Below are the ages at which US presidents bega.pdf
please help Below are the ages at which US presidents bega.pdfkitty811
 
please fill in the blanks below the proc structure .pdf
please fill in the blanks below    the proc structure  .pdfplease fill in the blanks below    the proc structure  .pdf
please fill in the blanks below the proc structure .pdfkitty811
 
Please explain these steps Not sure how to go from first li.pdf
Please explain these steps Not sure how to go from first li.pdfPlease explain these steps Not sure how to go from first li.pdf
Please explain these steps Not sure how to go from first li.pdfkitty811
 
Please help Edgar Given the following API for a mutable Em.pdf
Please help Edgar Given the following API for a mutable Em.pdfPlease help Edgar Given the following API for a mutable Em.pdf
Please help Edgar Given the following API for a mutable Em.pdfkitty811
 
Please help 1 Use any data structures or control flows as a.pdf
Please help 1 Use any data structures or control flows as a.pdfPlease help 1 Use any data structures or control flows as a.pdf
Please help 1 Use any data structures or control flows as a.pdfkitty811
 
Please graph the spectrum using only MATLAB and provide the .pdf
Please graph the spectrum using only MATLAB and provide the .pdfPlease graph the spectrum using only MATLAB and provide the .pdf
Please graph the spectrum using only MATLAB and provide the .pdfkitty811
 
please help Let X and Y be random variables with joint dens.pdf
please help  Let X and Y be random variables with joint dens.pdfplease help  Let X and Y be random variables with joint dens.pdf
please help Let X and Y be random variables with joint dens.pdfkitty811
 
Please go through the Review Article and submit a summary of.pdf
Please go through the Review Article and submit a summary of.pdfPlease go through the Review Article and submit a summary of.pdf
Please go through the Review Article and submit a summary of.pdfkitty811
 
Please give me a new topic not the one already on cheggQU.pdf
Please give me a new topic not the one already on cheggQU.pdfPlease give me a new topic not the one already on cheggQU.pdf
Please give me a new topic not the one already on cheggQU.pdfkitty811
 
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdf
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdfplease give ANY inswer in 30 min The CONTROL pyloric rhythm .pdf
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdfkitty811
 
please full it please full it 2 Genie and Dan have just ha.pdf
please full it please full it 2 Genie and Dan have just ha.pdfplease full it please full it 2 Genie and Dan have just ha.pdf
please full it please full it 2 Genie and Dan have just ha.pdfkitty811
 
Please find the Below YAML code whihc is meant to achieve th.pdf
Please find the Below YAML code whihc is meant to achieve th.pdfPlease find the Below YAML code whihc is meant to achieve th.pdf
Please find the Below YAML code whihc is meant to achieve th.pdfkitty811
 
Please fix my errors class Iterator public Construc.pdf
Please fix my errors   class Iterator  public  Construc.pdfPlease fix my errors   class Iterator  public  Construc.pdf
Please fix my errors class Iterator public Construc.pdfkitty811
 
Please fill in the blanks of the 5 questions Required inform.pdf
Please fill in the blanks of the 5 questions Required inform.pdfPlease fill in the blanks of the 5 questions Required inform.pdf
Please fill in the blanks of the 5 questions Required inform.pdfkitty811
 
please fast answer Suppose that XU nif 01 You draw a sa.pdf
please fast answer  Suppose that XU nif 01 You draw a sa.pdfplease fast answer  Suppose that XU nif 01 You draw a sa.pdf
please fast answer Suppose that XU nif 01 You draw a sa.pdfkitty811
 
Please explain in steps so I may be able to follow and learn.pdf
Please explain in steps so I may be able to follow and learn.pdfPlease explain in steps so I may be able to follow and learn.pdf
Please explain in steps so I may be able to follow and learn.pdfkitty811
 
Please explain why c is correct Why does this return and e.pdf
Please explain why c is correct  Why does this return and e.pdfPlease explain why c is correct  Why does this return and e.pdf
Please explain why c is correct Why does this return and e.pdfkitty811
 
Please code in C in Visual Studio Thank you 1 Create a C.pdf
Please code in C in Visual Studio Thank you 1 Create a C.pdfPlease code in C in Visual Studio Thank you 1 Create a C.pdf
Please code in C in Visual Studio Thank you 1 Create a C.pdfkitty811
 
Please explain step by step Current Attempt in Progress As .pdf
Please explain step by step Current Attempt in Progress As .pdfPlease explain step by step Current Attempt in Progress As .pdf
Please explain step by step Current Attempt in Progress As .pdfkitty811
 

Más de kitty811 (20)

please fix this code so that the tests pass css Selec.pdf
please fix this code so that the tests pass        css Selec.pdfplease fix this code so that the tests pass        css Selec.pdf
please fix this code so that the tests pass css Selec.pdf
 
please help Below are the ages at which US presidents bega.pdf
please help Below are the ages at which US presidents bega.pdfplease help Below are the ages at which US presidents bega.pdf
please help Below are the ages at which US presidents bega.pdf
 
please fill in the blanks below the proc structure .pdf
please fill in the blanks below    the proc structure  .pdfplease fill in the blanks below    the proc structure  .pdf
please fill in the blanks below the proc structure .pdf
 
Please explain these steps Not sure how to go from first li.pdf
Please explain these steps Not sure how to go from first li.pdfPlease explain these steps Not sure how to go from first li.pdf
Please explain these steps Not sure how to go from first li.pdf
 
Please help Edgar Given the following API for a mutable Em.pdf
Please help Edgar Given the following API for a mutable Em.pdfPlease help Edgar Given the following API for a mutable Em.pdf
Please help Edgar Given the following API for a mutable Em.pdf
 
Please help 1 Use any data structures or control flows as a.pdf
Please help 1 Use any data structures or control flows as a.pdfPlease help 1 Use any data structures or control flows as a.pdf
Please help 1 Use any data structures or control flows as a.pdf
 
Please graph the spectrum using only MATLAB and provide the .pdf
Please graph the spectrum using only MATLAB and provide the .pdfPlease graph the spectrum using only MATLAB and provide the .pdf
Please graph the spectrum using only MATLAB and provide the .pdf
 
please help Let X and Y be random variables with joint dens.pdf
please help  Let X and Y be random variables with joint dens.pdfplease help  Let X and Y be random variables with joint dens.pdf
please help Let X and Y be random variables with joint dens.pdf
 
Please go through the Review Article and submit a summary of.pdf
Please go through the Review Article and submit a summary of.pdfPlease go through the Review Article and submit a summary of.pdf
Please go through the Review Article and submit a summary of.pdf
 
Please give me a new topic not the one already on cheggQU.pdf
Please give me a new topic not the one already on cheggQU.pdfPlease give me a new topic not the one already on cheggQU.pdf
Please give me a new topic not the one already on cheggQU.pdf
 
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdf
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdfplease give ANY inswer in 30 min The CONTROL pyloric rhythm .pdf
please give ANY inswer in 30 min The CONTROL pyloric rhythm .pdf
 
please full it please full it 2 Genie and Dan have just ha.pdf
please full it please full it 2 Genie and Dan have just ha.pdfplease full it please full it 2 Genie and Dan have just ha.pdf
please full it please full it 2 Genie and Dan have just ha.pdf
 
Please find the Below YAML code whihc is meant to achieve th.pdf
Please find the Below YAML code whihc is meant to achieve th.pdfPlease find the Below YAML code whihc is meant to achieve th.pdf
Please find the Below YAML code whihc is meant to achieve th.pdf
 
Please fix my errors class Iterator public Construc.pdf
Please fix my errors   class Iterator  public  Construc.pdfPlease fix my errors   class Iterator  public  Construc.pdf
Please fix my errors class Iterator public Construc.pdf
 
Please fill in the blanks of the 5 questions Required inform.pdf
Please fill in the blanks of the 5 questions Required inform.pdfPlease fill in the blanks of the 5 questions Required inform.pdf
Please fill in the blanks of the 5 questions Required inform.pdf
 
please fast answer Suppose that XU nif 01 You draw a sa.pdf
please fast answer  Suppose that XU nif 01 You draw a sa.pdfplease fast answer  Suppose that XU nif 01 You draw a sa.pdf
please fast answer Suppose that XU nif 01 You draw a sa.pdf
 
Please explain in steps so I may be able to follow and learn.pdf
Please explain in steps so I may be able to follow and learn.pdfPlease explain in steps so I may be able to follow and learn.pdf
Please explain in steps so I may be able to follow and learn.pdf
 
Please explain why c is correct Why does this return and e.pdf
Please explain why c is correct  Why does this return and e.pdfPlease explain why c is correct  Why does this return and e.pdf
Please explain why c is correct Why does this return and e.pdf
 
Please code in C in Visual Studio Thank you 1 Create a C.pdf
Please code in C in Visual Studio Thank you 1 Create a C.pdfPlease code in C in Visual Studio Thank you 1 Create a C.pdf
Please code in C in Visual Studio Thank you 1 Create a C.pdf
 
Please explain step by step Current Attempt in Progress As .pdf
Please explain step by step Current Attempt in Progress As .pdfPlease explain step by step Current Attempt in Progress As .pdf
Please explain step by step Current Attempt in Progress As .pdf
 

Último

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
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
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 

Último (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
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
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
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
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
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 ...
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

Please create the appropriate JUnit test cases to thoroughly.pdf

  • 1. Please create the appropriate JUnit test cases to thoroughly unit test the following program: IntegerSet.java import java.util.*; public class IntegerSet{ private ArrayList<Integer> list= new ArrayList<>(); public IntegerSet(ArrayList list) { this.list=list; } // clears the all representation of class public void clear() { list.clear(); } // returns the length of set public int length() { return list.size(); } // return true if 2 lists are equal public boolean equals(IntegerSet b) { ArrayList<Integer> list2=b.list; if(list.size()!=list2.size()) { return false; } ArrayList<Integer> temp1=list; ArrayList<Integer> temp2=list2; Collections.sort(temp1); Collections.sort(temp2); for(int i=0;i<temp1.size();i++) { if(temp1.get(i)!=temp2.get(i)) { return false; } } return true; } // returns a largest item and throw exception if list is empty public int largest() throws IntegerSetException { if(list.size()==0) { IntegerSetException e= new IntegerSetException(); throw e; } int max=0; for(int i=0;i<list.size();i++) {
  • 2. if(list.get(i)>max) { max=list.get(i); } } return max; } // returns a largest item and throw exception if list is empty public int smallest() throws IntegerSetException { if(list.size()==0) { IntegerSetException e= new IntegerSetException(); throw e; } int min=Integer.MAX_VALUE; for(int i=0;i<list.size();i++) { if(list.get(i)<min) { min=list.get(i); } } return min; } // add item if already not exist in list public void addItem(int item ) { boolean exist=false; for(int i=0;i<list.size();i++) { if(list.get(i)==item) { exist=true; } } if(exist==false) { list.add(item); } } // remove item if already not exist in list public void removeItem(int item ) { for(int i=0;i<list.size();i++) { if(list.get(i)==item) { list.remove(i); } } } // return union of of 2 sets public IntegerSet union(IntegerSet list2) {
  • 3. ArrayList<Integer> temp=list2.getlist(); Set<Integer> set = new HashSet<>(); set.addAll(list); set.addAll(temp); ArrayList<Integer> list3= new ArrayList<>(set); IntegerSet list4= new IntegerSet(list3); return list4; } // return intersection of of 2 sets public IntegerSet intersection(IntegerSet list2) { ArrayList<Integer> temp=list2.getlist(); list.retainAll(temp); IntegerSet list4= new IntegerSet(list); return list4; } // returns difference of 2 sets public IntegerSet difference (IntegerSet list2) { ArrayList<Integer> temp=list2.getlist(); // Remove all elements in list2 from list list.removeAll(temp); IntegerSet list4= new IntegerSet(list); return list4; } public ArrayList<Integer> getlist(){ return list; } } IntegerSetException.java class IntegerSetException extends Exception { Driver.java import java.util.*; public class Driver { public static void main(String[] args) throws IntegerSetException { ArrayList<Integer> list1= new ArrayList<>(); ArrayList<Integer> list2= new ArrayList<>(); // make 2 instance of integerset class for implementation IntegerSet set1= new IntegerSet(list1); IntegerSet set2= new IntegerSet(list2); set1.addItem(1); set1.addItem(3); set1.addItem(4); set1.addItem(6);
  • 4. set1.addItem(3); set1.addItem(8); set1.addItem(7); set2.addItem(1); set2.addItem(2); set2.addItem(3); set2.addItem(4); set2.addItem(5); set2.addItem(6); set2.addItem(7); System.out.println("Set 1 : "+set1.getlist()); System.out.println("Set 2 : "+set2.getlist()); System.out.println("Is equal : "+set1.equals(set2)); System.out.println("Largest element in set1 : "+set1.largestelement()); System.out.println("Smallest element in set2 : "+set2.smallestelement()); IntegerSet setu= set1.union(set2); System.out.println("Unoin : "+setu.getlist() ); IntegerSet seti= set1.intersection(set2); System.out.println("Intersection : "+seti.getlist() ); } } The JUnit test class should be named IntegerSetTest to be consistent with standard Java naming conventions. In addition, each method should be named in the format of testXXXX. For example, if testing the equals(Boolean) method it would look like public class IntegerSetTest { @Test @DisplayName("Test case for equals") public void testEquals() { // JUnit test case(s) for equal } } Sufficiently test each public method, you will be graded on how robust your JUnit test cases are. Note that methods largest() and smallest() potentially throw an exception if invoked and your IntegerSet is empty. You are to add to add exception handling to these methods and write JUnit test cases to test the exceptions.