Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

array file : import static org.junit.Assert.assertEquals; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; public class ArrayIntListTest { @Test(expected = IllegalStateException.class) public void testIllegalStateExceptionIsThrown() { ArrayIntList tester

image text in transcribed

array file :

import static org.junit.Assert.assertEquals; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; public class ArrayIntListTest { @Test(expected = IllegalStateException.class) public void testIllegalStateExceptionIsThrown() { ArrayIntList tester = new ArrayIntList(); for (int x = 0; x

tester.add(600); assertEquals("after adding 7 elements the size should be", 7, tester.size()); } @Test public void testRemoveElementAtPositionAndGet() { ArrayIntList tester = new ArrayIntList(); tester.add(888); tester.add(100); tester.add(200); tester.add(300); tester.add(400); tester.add(500); int x = tester.get(3); tester.remove(3); // assertEquals("after removing the 3rd element the 3rd element should be", 400, tester.get(3)); assertEquals("after remove value at index 3 no longer exist in array", -1, tester.indexOf(x)); } @Test public void testIndexOf() { ArrayIntList tester = new ArrayIntList(); tester.add(888); tester.add(100); tester.add(200); tester.add(300); tester.add(400); tester.add(500); tester.remove(3); assertEquals("after index of 200 should be", 2, tester.indexOf(200)); } @Test public void testToString() { ArrayIntList tester = new ArrayIntList(); tester.add(888); tester.add(100); tester.add(200); tester.add(300); assertEquals("after toString shoule be", "[888, 100, 200, 300]", tester+""); } @Test public void testEquals() { // check if two lists are equal ArrayIntList testList1 = new ArrayIntList(); testList1.add(0); testList1.add(100); testList1.add(200); testList1.add(300); testList1.add(400); testList1.add(500); ArrayIntList testList2 = new ArrayIntList(); testList2.add(0);

testList2.add(100); testList2.add(200); testList2.add(300); testList2.add(400); testList2.add(500); assertEquals("list 1 should be eqaul to list 2", true, testList1.equals(testList2)); // check if two lists are not equal ArrayIntList testList3 = new ArrayIntList(); testList3.add(0); testList3.add(100); testList3.add(200); testList3.add(305); testList3.add(400); testList3.add(500); assertEquals("list 1 should not be eqaul to list 3", false, testList1.equals(testList3)); // check if two empty lists are equal ArrayIntList testList4 = new ArrayIntList(); ArrayIntList testList5 = new ArrayIntList(); assertEquals("empty list 4 should eqaul to empty list 5", true, testList4.equals(testList5)); } } testList2.add(100); testList2.add(200); testList2.add(300); testList2.add(400); testList2.add(500);

In this assignment we are going to write a method equals for the ArrayIntList class you created previously. The equals method accepts an Object as a parameter and determines if the object passed in is equal to the ArraylntList doing the comparison. For example, if two variables of type ArraylntList that are named list1 and list2 have been initialized, then the method call of list1.equals(list2) will return true if the lists are equal and false if otherwise. Two lists are considered equal if they contain exactly the same the same int values in exactly the same order. Two empty lists are considered equal to each other. The other half of this assignment is to become familiar with the concept of Unit testing and the JGrasp ability to integrate the Unit testing framework called junit. Unit testing is a very useful software development practice. What unit tests does is speed up your development cycle by automating the part where you spend time checking the methods you create with various values of test data. Manual testing of your methods can take a lot of time because it is a good idea to test your method every time you make even a small change to a method. Unit testing with Junit is a way of automating testing that you have previously done manually. It is the same thing you have been doing manually when you created a main method for the ExploringArrayList class and then manually ran and reran the main method over and over as you developed your ArrayIntList code to try out the various methods your were writing. This week you will copy a junit file that I wrote to use to test out your ArraylntList code. Download the file ArraylntListTest.java file and place it in the directory where your ArraylntList.java file is. This file contains junit tests that when run will exercise all of your ArraylntList methods including the new equals method you will write as you watch the video and junit will inform you if your ArraylntList code works as expected. This is what you need to do: 1. Read about JUnit on jGrasp https://www.jgrasp.org/tutorials200/jGRASP 11 JUnit.pdf G. Junit is likely already setup and ready to run if you installed the version of JGrasp that comes bundled with Junit, that was recommended in our earlier assignment on setting up JGrasp. 2. Download the file ArraylntListTest.java to be used for unit testing your ArraylntList class file. 3. Follow along with the video above to setup your Junit project on JGrasp for ArraylntList, implement the equals method, and make sure all the unit tests pass successfully for you. 4. If you had trouble with our previous ArraylntList assignment implementation or are unable to follow along in the video above you may work from this implementation ArraylntList.java

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

You have

Answered: 1 week ago