hello, I suppose to create white&black box test case using a Junit test But i ke
ID: 3555582 • Letter: H
Question
hello, I suppose to create white&black box test case using a Junit test
But i keep getting error, I dont know exact problem , could you f help me please
COde
package select;
public class selectionSort2 {
public static void main(String[] args)
{
int n = 20;
int[] numArray = unsortedArray(n); // re-initialize
printArray(numArray,n);
selectSort2(numArray, n);
printArray(numArray, n);
}
//Generate data for the selection sort array
public static int[] unsortedArray(int n) {
int[] a = new int[n];
for (int index = 0; index < n; index++) {
a[index] = (n - index);
}
return a;
}
//print the array
public static void printArray(int[] data, int n)
{
for (int index = 0; index < n; index++) {
System.out.print(data[index] + " ");
}
System.out.println();
} public static void selectSort2(int[] data, int n)
{
for (int numUnsorted = n; numUnsorted > 0; numUnsorted--) {
int maxIndex = 0;
for (int index = 1; index < numUnsorted; index++) {
if (data[maxIndex] < data[index])
maxIndex = index;
//swap the element
int temp = data[numUnsorted-1];
data[numUnsorted-1] = data[maxIndex];
data[maxIndex] = temp;
}
}
}
}
Junit test code
package select;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author secc
*
*/
public static void testSelectSort2() {
selectionSort2 test = new selectionSort2();
int[] num = { 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7,
6, 5, 4, 3, 2, 1 };
int act=0;
act++;
int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20 };
selectionSort2.selectSort2(num, act);
assertArrayEquals(expected, num);
}
}
I got initialzing error and test got error
Explanation / Answer
Is the error still there Angela ??? After we solved it before ?
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.