-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSelectionSort.java
More file actions
56 lines (55 loc) · 1.5 KB
/
testSelectionSort.java
File metadata and controls
56 lines (55 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Test;
public class testSelectionSort {
@Test
public void test() {
testPositive();
testNegative();
testMixed();
testDuplicates();
}
public testSelectionSort() {
}
public void testPositive(){
int[] arr = new int[5];
arr[0] = 8;
arr[1] = 9;
arr[2] = 7;
arr[3] = 10;
arr[4] = 2;
int[] Sortedarr = new int[5];
Sortedarr[0] = 2;
Sortedarr[1] = 7;
Sortedarr[2] = 8;
Sortedarr[3] = 9;
Sortedarr[4] = 10;
SelectionSort sorter = new SelectionSort();
int[] expectedArr = sorter.basicSelectionSort(arr);
assertArrayEquals(Sortedarr, expectedArr);
}
public void testNegative(){
/** Test data contains negative values only **/
int[] arr = {-5, -10, -3, -1, -8};
SelectionSort sorter = new SelectionSort();
int[] sortedArr = sorter.basicSelectionSort(arr);
int[] expectedArr = {-10, -8, -5, -3, -1};
assertArrayEquals(expectedArr, sortedArr);
}
public void testMixed(){
/** Test data contains with both positive, negative and zeros **/
int[] arr = {-5, 10, 0, -1, 3};
SelectionSort sorter = new SelectionSort();
int[] sortedArr = sorter.basicSelectionSort(arr);
int[] expectedArr = {-5, -1, 0, 3, 10};
assertArrayEquals(expectedArr, sortedArr);
}
public void testDuplicates(){
/** Test data contains duplicates **/
int[] arr = {10, 5, 20, 10, 30};
SelectionSort sorter = new SelectionSort();
int[] sortedArr = sorter.basicSelectionSort(arr);
int[] expectedArr = {5, 10, 10, 20, 30};
assertArrayEquals(expectedArr, sortedArr);
}
}