Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java: Create a Junit Test cases on a small program ArraySet. The tester must meet the followng requrirements as a demo from below. Here is

Java: Create a Junit Test cases on a small program ArraySet. The tester must meet the followng requrirements as a demo from below.

Here is an overview:

lab : | +-- ANALYSIS.txt : Add answers to this file +-- ArraySetTests.java : Add tests to this file +-- impl1/ | | | +-- ArraySet.java : Do not modify, provided | +-- impl2/ | | | +-- ArraySet.java : Do not modify, provided | +-- junit-4.12.jar 

Demo of ArraySet

Some of the methods of ArraySet demonstrated in the short demo below. These represent expected behavior and converting this demo into some test cases might be a good first step.

Welcome to DrJava. > ArraySet ss = new ArraySet(); > ss.size() 0 > ss.contains("hello") false > ss.add("hello") true > ss.size() 1 > ss.contains("hello") true > ss.toString() [hello] > ss [hello] > ss.add("goodbye") true > ss.contains("goodbye") true > ss.contains("hello") true > ss.add("ciao") true > ss.remove("hello") true > ss.size() 2 > ss.contains("hello") false > ss.contains("ciao") true > ss [goodbye, ciao] 

Structure of the ArraySet Class

The public methods of ArraySet that should be subjected to testing are described in the outline below. It eventually it will be necessary to examine the code for these implementation in the impl1/ArraySet.java and impl2/ArraySet.java to determine why the broken implementation is incorrect.

----------------Here is the task------------------Please complete the task from below---------

Writing and Running Test Cases

The goal of this lab is to create an ArraySetTests.java file which contain JUnit tests. These tests should have the following properties.

Each method of ArraySet is tested

One of the ArraySet.java implementations passes all tests

One implementation fails one or more tests

The tests help to identify an flaw in the implementation that fails which can then be described

Writing test cases is simply a matter of writing methods annotated with @Test which are then identified by a testing framework and run when requested. Below is are the beginnings of such a test set which appear in the provided template ArraySetTests.java file. You should add tests to this file.

---------------Please solve from here----------

import java.io.*; import org.junit.*; import static org.junit.Assert.*; import java.util.*; import org.junit.Test; // fixes some compile problems with annotations public class ArraySetTests{ public static void main(String args[]) { org.junit.runner.JUnitCore.main("ArraySetTests"); } @Test public void constructor1(){ ArraySet a = new ArraySet(); assertEquals(0, a.size()); assertEquals("[]", a.toString()); } @Test public void constructor2(){ ArraySet a = new ArraySet(5); assertEquals(0, a.size()); } @Test public void containsNothing2(){ ArraySet a = new ArraySet(); assertFalse(a.contains("hi")); assertFalse(a.contains("bye")); assertFalse(a.contains("Blackbird")); } // ADD ADDITIONAL TESTS HERE }

--------Additional Info---------

Assertion Functions

JUnit provides a series of assertion functions which check that the answers produced by methods produce the expected results. The most common of these are the following.

assertTrue(code): Fail the test unless code evaluates to true

assertFalse(code): Fail the test unless code evaluates to false

assertEquals(expect, actual): Fail the test unless the statement expect.equals(actual) evaluates to true. By convention, the earlier argument is the result expected by the test while the later argument is the actual result produced by the test.

Running tests on different implementations

You will need to run the tests you write in ArraySetTests.java on two different implementations contained in the impl1 and impl2directories which is a little unconventional. Here are tips on how to do so in the supported environments.

--------------Here is the java codes for ArraySet-----------

From impl 1: https://paste.ee/p/954TD

From impl2: https://paste.ee/p/2O1yg

Please help me. I would greatly appreciate your helps. Thank you

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions