필자는 SelectionSort 클래스에서 blackbox/whitebox JUnit 기술을 이해하려고 시도하고 있지만 취해야 할 방향을 이해하는 데 어려움을 겪고 있습니다.JUnit blackbox/whitebox를 사용하면 선택 정렬을 테스트 할 수 있습니까?
다음 중 하나가 실패했습니다. 크기를 테스트 해 봅니다. 내 선택 정렬 클래스,하지만 내 방법 (unsortedArray는) 인식되지에서 배열 ...의
@Test
public void testUnsortedArray() {
int n = 20;
int[] x = new int[n];
for (int i = 0; i < 20; i++) {
x[i] = (n);
n--;
i++;
}
SelectionSort2 a = new SelectionSort2();
assertArrayEquals(20, a.unsortedArray(x, 20));
}
다음은 제공되었다 내 선택 정렬 클래스입니다. 어떤 도움이나 지침은 매우 높이 평가됩니다 :)
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;
}
}
}
}
나는 당신이 당신의 수업이 기대할 수있는 것들의 목록을 작성하는 것이 좋습니다. 이러한 각각의 요구 사항에 대해 적용 할 수있는 여러 가지 상황의 목록을 작성하십시오. 그런 다음 요구 사항과 환경의 각 조합에 대해 클래스가 요구 사항을 충족시키는 것이 Java 코드로 작성하고이를 테스트로 빌드하십시오 방법. 한 가지 상황에서 각자의 클래스의 동작에 대해 한 가지 주장하는 테스트 방법으로 배터리를 마무리해야합니다. –