Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provided classes: package week8; import java.util.List; import org.junit.runner.Result; import org.junit.runner.notification.Failure; /** * This class executes the JUnit Test specified from the command line This will

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Provided classes:

package week8;

import java.util.List;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

/**

* This class executes the JUnit Test specified from the command line This will

* be used by the reference system for testing your code.

*/

public class TestHarness

{

public static void main(String[] args)

{

trace("TestHarness");

try

{

Result result = org.junit.runner.JUnitCore

.runClasses(Week10JUnitTest.class);

int runs = result.getRunCount();

int ignores = result.getIgnoreCount();

trace(String.format("Runs: %d", runs));

trace(String.format("Ingores: %d", ignores));

int failCount = result.getFailureCount();

if(failCount > 0)

{

List failures = result.getFailures();

for(Failure fail : failures)

{

trace("FAILED: " + fail.getMessage());

}

}

else

{

trace("SUCCESS");

}

}

catch(Exception ex)

{

trace("Unhandled exception: " + ex.getMessage());

}

}

private static void trace(String msg)

{

System.out.println(msg);

}

}

package week8;

import static org.junit.Assert.*;

import java.util.ArrayList;

import java.util.Date;

import java.util.Random;

import org.junit.Test;

public class Week8JUnitTest

{

/**

* Pass in invalid guesses and get an InvalidArgumentException

*/

@Test

public void testSelectionSort()

{

trace("testSelectionSort");

int[] testList = generateRandomIntegerList();

SortUtility util = new SortUtility();

try

{

int[] sortedList = util.sort(testList, SORT_ALGORITHM_TYPE.SELECTION);

if( !verifySort(sortedList) )

{

fail("SelectionSort failed");

}

String msg = String.format("Elapsed time: %d ms", util.getElapsedTime());

trace(msg);

}

catch(NotImplementedException ex)

{

fail("Sort selection not implemented " + ex.getMessage());

}

catch(Exception ex)

{

fail("Unexpected exception " + ex.getMessage());

}

}

/**

* Pass in invalid guesses and get an InvalidArgumentException

*/

@Test

public void testQuickSort()

{

trace("testQuickSort");

int[] testList = generateRandomIntegerList();

SortUtility util = new SortUtility();

try

{

int[] sortedList = util.sort(testList, SORT_ALGORITHM_TYPE.QUICK);

if( !verifySort(sortedList) )

{

fail("QuickSort failed");

}

String msg = String.format("Elapsed time: %d ms", util.getElapsedTime());

trace(msg);

}

catch(NotImplementedException ex)

{

fail("Sort quick not implemented " + ex.getMessage());

}

catch(Exception ex)

{

fail("Unexpected exception " + ex.getMessage());

}

}

/**

* Verifies the list is sorted smallest to largest

* @param list list to verify

* @return true if sorted, otherwise false

*/

private boolean verifySort(int[] list)

{

boolean result = true;

for(int i = 0; i

{

int nextInt = i+1;

if(list[i] > list[nextInt])

{

String msg = String

.format("Unsorted valies at index %d and %d", i, nextInt);

trace(msg);

result = false;

break; // early out

}

}

return result;

}

/**

* Random integers, must all be unique

*/

private int[] generateRandomIntegerList()

{

Random rand = new Random();

int[] list = new int[LIST_SIZE];

for(int i = 0; i

{

int val = rand.nextInt(LIST_SIZE);

list[i] = val;

}

return list;

}

private void trace(String msg)

{

System.out.println(msg);

}

//private int[] m_list;

private static int LIST_SIZE = 100000;

}

The Key elements to this assignment are Abstract base classes, modularity, capturing elapsed time, pluggable algorithms. research and implement Selectionsot, and Quicksort algorithms in this assignment. Your task will be to figure out how to accomplish the task assigned. You CANNOT use the Java libraries directly for this assignment. You MUST implement the algorithms yourself. You must provide J comments for the public methods defined. the SORT ALGORITHM TYPE is a separate file and you must implement the supporting classes AbstractSort NolmplementationException. Sortutility and Stopwatch. This is typical software development where the key capability requires a number of infrastructure items to be effectively implemented SortUtility Abstract Sort plemented Exception Notlm m-name string m. mType SORT ALGORITHM TYPE getElapsed Time() :long sortintO intl getsortAlgorithmosORTLALGORITHM-TYPE) Abstractsort Exception (String) sortint0. SORT ALGORITHM TYPE) :void Abstracts ort(String Exception(String. Throwable) enumerations SORT ALGORITHM-TYPE Selection Sort0 QuickSort0 sort into) :int0 sortint0) int0 StopWatch m startTime :long m. stop Time long getElapsed TimeMilliseconds0 long getStartTime0 :long getstop Time(0 :long

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

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions