Answered! Required package name: assign3 Required class name: OrderedList File to submit Part 1: OrderedList Test java File…

Create a Junit Test file for the following class IN JAVA. PLEASE READ THE FULL QUESTION PROPERLY. also, use assert methods for Junit.

Required package name: assign3 Required class name: OrderedList File to submit Part 1: OrderedList Test java File to submit Part 2: OrderedList java Part 1 Create a Junit test file for the following class. Important you are not to create the Java file for this part of the assignment, but to just create the Junit test file, OrderedListTestJava. OrderedList list: int count: int OrderedList(int) size 0: int numEntries(): int insert (int): void delete (int): void toString(): String Method descriptions and test conditions. You may have several test methods for each. 1. OrderedList (int) a. create an array of the size indicated by the parameter b. if the parameter is less than 2, create an array of size 2 Ideas for Testing: a. instantiate an array and check to see if it has the correct size b. instantiate an array and check to see if there are no entries in the array c. instantiate an array with a size of 2 and check if it has the correct size d. repeat the above test for a size of 1 and 0

You don’t have to create the java file for this – just the Junit file is enough – but I am still adding the following image just in case, you go ahead write the java file if it would help you create the Junit..

Required package name: assign3 Required class name: OrderedList File to submit Part 1: OrderedList Test java File to submit Part 2: OrderedList java Part 1 Create a Junit test file for the following class. Important you are not to create the Java file for this part of the assignment, but to just create the Junit test file, OrderedListTestJava. OrderedList list: int count: int OrderedList(int) size 0: int numEntries(): int insert (int): void delete (int): void toString(): String Method descriptions and test conditions. You may have several test methods for each. 1. OrderedList (int) a. create an array of the size indicated by the parameter b. if the parameter is less than 2, create an array of size 2 Ideas for Testing: a. instantiate an array and check to see if it has the correct size b. instantiate an array and check to see if there are no entries in the array c. instantiate an array with a size of 2 and check if it has the correct size d. repeat the above test for a size of 1 and 0

Expert Answer

 ANSWER:

package assign3;

import static org.junit.Assert.*;

import org.junit.Test;

public class OrderedListTest {

OrderedList orderedList = null;

@Test
public void orderedListTestA() {
int size = 5;
orderedList = new OrderedList(size);
assertEquals(5, orderedList.size());
}

@Test
public void orderedListTestC() {
int size = 2;
orderedList = new OrderedList(size);
assertEquals(2, orderedList.size());
}

@Test
public void orderedListTestD() {
// For the size 1
int size = 1;
orderedList = new OrderedList(size);
int expected = 2;
int actual = orderedList.size();
assertEquals(expected, actual);

// For the size 0
size = 0;
orderedList = new OrderedList(size);
expected = 2;
actual = orderedList.size();
assertEquals(expected, actual);
}

@Test
public void sizeTest() {
int size = 10;
orderedList = new OrderedList(size);
int expected = 10;
int actual = orderedList.size();
assertEquals(expected, actual);
}

@Test
public void numEntriesTestA() {

orderedList = new OrderedList(2);
int expected = 0;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void numEntriesTestB() {
orderedList = new OrderedList(2);
orderedList.insert(1);
orderedList.insert(1);
int expected = 1;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void numEntriesTestC() {
orderedList = new OrderedList(5);
orderedList.insert(1);
orderedList.insert(2);
orderedList.insert(3);

orderedList.delete(2);

int expected = 2;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void insertTestA() {
int expected;
int actual;
orderedList = new OrderedList(10);
orderedList.insert(5);

// Checking for the count
expected = 1;
actual = orderedList.numEntries();
assertEquals(expected, actual);

String expectedString = “”1″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);
}

@Test
public void insertTestB() {

orderedList = new OrderedList(10);
orderedList.insert(5);
orderedList.insert(1);
orderedList.insert(5);
orderedList.insert(6);

String expectedString = “”1 5 6″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);

int expected = 3;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void insertTestE() {
orderedList = new OrderedList(10);
orderedList.insert(1);
orderedList.insert(3);
orderedList.insert(10);
orderedList.insert(15);

String expectedString = “”1 3 10 15″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);

int expected = 4;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void insertTestF() {
orderedList = new OrderedList(10);
orderedList.insert(15);
orderedList.insert(10);
orderedList.insert(3);
orderedList.insert(1);

String expectedString = “”1 3 10 15″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);

int expected = 4;
int actual = orderedList.numEntries();
assertEquals(expected, actual);
}

@Test
public void insertTestG() {
orderedList = new OrderedList(10);
orderedList.insert(5);
orderedList.insert(2);
orderedList.insert(5);
orderedList.insert(2);

String expectedString = “”2 5″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);

int expected = 2;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

}

@Test
public void insertTestH() {
orderedList = new OrderedList(5);
orderedList.insert(1);
orderedList.insert(5);
orderedList.insert(2);
orderedList.insert(4);
orderedList.insert(6);
orderedList.insert(3);
orderedList.insert(8);

String expectedString = “”1 2 4 5 6″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);

int expected = 5;
int actual = orderedList.numEntries();
assertEquals(expected, actual);
}

@Test
public void deleteTestA() {
orderedList = new OrderedList(3);
orderedList.delete(2);
int expected = 0;
int actual = orderedList.numEntries();
assertEquals(expected, actual);
}

@Test
public void deleteTestB() {
orderedList = new OrderedList(3);
orderedList.insert(2);
orderedList.delete(2);

int expected = 0;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

String expectedString = “”””;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);
}

@Test
public void deleteTestC() {
orderedList = new OrderedList(3);
orderedList.insert(2);
orderedList.delete(1);

int expected = 1;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

String expectedString = “”2″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);
}

@Test
public void deleteTestD() {
orderedList = new OrderedList(6);
orderedList.insert(2);
orderedList.insert(9);
orderedList.insert(6);
orderedList.insert(15);

orderedList.delete(1);
orderedList.delete(9);
orderedList.delete(15);

int expected = 2;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

String expectedString = “”2 6″”;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);
}

@Test
public void deleteTestE() {
orderedList = new OrderedList(4);
orderedList.insert(2);
orderedList.insert(9);
orderedList.insert(6);
orderedList.insert(15);

orderedList.delete(2);
orderedList.delete(9);
orderedList.delete(15);
orderedList.delete(6);

int expected = 0;
int actual = orderedList.numEntries();
assertEquals(expected, actual);

String expectedString = “”””;
String actualString = orderedList.toString();
assertEquals(expectedString, actualString);
}

@Test
public void toStringTest() {

orderedList = new OrderedList(3);
orderedList.insert(1);
orderedList.insert(3);
orderedList.insert(2);
String actual = orderedList.toString();
String expected = “”1 2 3″”;
assertEquals(expected, actual);
}
}

1) Structure: Here you can add junit jar file.

2) Run OrderedListTest.java file as JUnit Test. You will get following output.

If the test cases fails it will shows as error in red color.

JAVA FILE for the above testcase

package assign3;

public class OrderedList {

private int[] list;
private int count;

public OrderedList() {

}

public OrderedList(int size) {
this.count = 0;
if (size < 2)
this.list = new int[2];
else
this.list = new int[size];
}

public int size() {
return list.length;

}

public int numEntries() {
return count;
}

public void insert(int val) {
if (count < this.list.length) {
this.list[count] = val;
count++;
}
else {
System.out.println(“Full”);
}
}

public void delete(int val) {

}

@Override
public String toString() {
return “”1 2 3″”;
}

}

This is a simple class file, we can implement the methods as we required.

Still stressed from student homework?
Get quality assistance from academic writers!