-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestSelectionSort.java
More file actions
103 lines (82 loc) · 1.79 KB
/
testSelectionSort.java
File metadata and controls
103 lines (82 loc) · 1.79 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
class testSelectionSort {
SelectionSort x = new SelectionSort();
@Test
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;
arr = x.basicSelectionSort(arr);
for(int i =0; i<arr.length; i++)
assertEquals(sortedArr[i], arr[i]);
}
public void testNegative() {
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[4] = -2;
sortedArr[3] = -7;
sortedArr[2] = -8;
sortedArr[1] = -9;
sortedArr[0] = -10;
arr = x.basicSelectionSort(arr);
for(int i =0; i<arr.length; i++)
assertEquals(sortedArr[i], arr[i]);
}
public void testMixed() {
int[] arr = new int[5];
arr[0] = 2;
arr[1] = -7;
arr[2] = 8;
arr[3] = -9;
arr[4] = 10;
int[] sortedArr = new int[5];
sortedArr[0] = -9;
sortedArr[1] = -7;
sortedArr[2] = 2;
sortedArr[3] = 8;
sortedArr[4] = 10;
arr = x.basicSelectionSort(arr);
for(int i =0; i<arr.length; i++)
assertEquals(sortedArr[i], arr[i]);
}
public void testDuplicates() {
int[] arr = new int[5];
arr[0] = 2;
arr[1] = 2 ;
arr[2] = -9 ;
arr[3] = 7 ;
arr[4] = -9;
int[] sortedArr = new int[5];
sortedArr[0] = -9;
sortedArr[1] = -9;
sortedArr[2] = 2;
sortedArr[3] = 2;
sortedArr[4] = 7;
arr = x.basicSelectionSort(arr);
for(int i =0; i<arr.length; i++)
assertEquals(sortedArr[i], arr[i]);
}
}