Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop unit test for each function defined in TestingFunctions.java, to verify both that the basic behavior works and that edge cases are handled properly. The

Develop unit test for each function defined in TestingFunctions.java, to verify both that the basic behavior works and that edge cases are handled properly.

The BlackBoxCorrect class is correctly implemented, while the BlackBoxIncorrect class has bugs in edge cases. As such, all of your tests should pass for BlackBoxCorrect, but some will fail with BlackBoxIncorrect.

Implement the tests outlined in TestCases.java, and write additional tests for each function. There are 2 bugs in the incorrect version of greatestCommonDivisor, and one bug in reverseWindow. Expose all of these bugs with unit tests for completion.

Here are some example test cases you should look for:

For greatestCommonDivisor:

Negative, and 0 value inputs

Inputs with a GCD of 1

Inputs with a GCD equal to one of the values

For reverseWindow:

Input indices out of bound of the array size

Input indices at the bounds of the array size

Reversed input indices

Input with an empty array

Input with equal indices

TestingFunctions.java

public interface TestingFunctions {

/**

* This method calculates and returns the GCD of a and b using a binary calculation

* method based on the pseudo code retrieved from Wikipedia on 4/5/18

* (original pseudo code show below method)

* @param a - the first integer, must be positive

* @param b - the second integer, must be positive

* @return gcd of a and b, if a or b is negative returns -1

*/

public int greatestCommonDivisor(int a, int b);

/**

* This method reverses the subsection of the passed array defined by index1

* and index2. index2 is non-inclusive and will not be swapped with index1. If

* index1 > index2 then the two indexes will be swapped before they are checked

* for validity.

* @param arr - the array to reverse

* @param index1 - the first index of the subsection

* @param index2 - the non-inclusive upper bound of the subsection,

* last element swapped will be at the index (index2 - 1)

* @throws IndexOutOfBoundsException if index1 or (index2-1) are not valid indexes of arr

*/

public void reverseWindow(int[] arr, int index1, int index2) throws IndexOutOfBoundsException;

}

TestCases.java

import static org.junit.Assert.*;

import java.util.Arrays;

import org.junit.Test;

public class TestCases {

//Switch which line is commented out in order to test the correct vs broken code TestingFunctions functions = new BlackBoxCorrect(); //TestingFunctions functions = new BlackBoxIncorrect(); /** * This is a simple validity check for the method greatestCommonDivisor. Checks that the method * returns the correct result for a known GCD problem gcd(2,4) = 2 */ @Test public void testGCD() { assertEquals("Error: should return 2", 2, functions.greatestCommonDivisor(2, 4)); } /** * This is a simple check of the reverseWindow method. Checks if the method will reverse the entire contents * of the passed array correctly. */ @Test public void testReverseWindow() { }

//For completion, write additonal tests as described in the lab documentation. }

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_2

Step: 3

blur-text-image_3

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

Advances In Knowledge Discovery In Databases

Authors: Animesh Adhikari, Jhimli Adhikari

1st Edition

3319132121, 9783319132129

More Books

Students also viewed these Databases questions

Question

Azure Analytics is a suite made up of which three tools?

Answered: 1 week ago