-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickTest.java
More file actions
89 lines (70 loc) · 2.24 KB
/
QuickTest.java
File metadata and controls
89 lines (70 loc) · 2.24 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
package quick;
import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
public class QuickTest {
@Test(expected = AssertionError.class)
public void testAssertionEnabled() {
assert false;
}
@Test
public void defaultTestCase() {
int[] ary = { 2, 10, 15, 23, 0, 5 };
int[] ans = { 0, 2, 5, 10, 15, 23 };
for (int i = 0; i < 6; i++) {
assertEquals(ans[i], Quick.quickselect(ary.clone(), i));
}
}
@Test
public void testStaticArray() {
int[] arr = { 2, 10, 15, 23, 0, 5 };
int[] sorted = arr.clone();
Arrays.sort(sorted);
Quick.quicksort(arr);
TestTools.testIntArraysEquals(sorted, arr);
}
@Test
public void testAlreadySorted() {
int[] arr = { 0, 2, 5, 10, 15, 23 };
int[] sorted = arr.clone();
Arrays.sort(sorted);
Quick.quicksort(arr);
TestTools.testIntArraysEquals(sorted, arr);
}
@Test
public void testQuicksortLimitedVals() {
final int size = 10;
int low = 0;
int high = 5;
for (int i = 0; i < 5; i++) {
int[] arr = TestTools.generateIntArray(size, low, high);
int[] sorted = arr.clone();
Arrays.sort(sorted);
Quick.quicksort(arr);
TestTools.testIntArraysEquals(sorted, arr);
}
}
@Test
public void testQuicksortRandVals() {
final int size = 100;
for (int i = 0; i < 5; i++) {
int[] arr = TestTools.generateIntArray(size, 0);
int[] sorted = arr.clone();
Arrays.sort(sorted);
Quick.quicksort(arr);
TestTools.testIntArraysEquals(sorted, arr);
}
}
@Test
public void testDifferentSizes() {
final int[] sizes = {1, 2, 2 * 2, 2 * 2 * 2, 2 * 2 * 2 * 2 * 2 * 2,
2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2, 3 * 3 * 3 };
for (int size : sizes) {
int[] arr = TestTools.generateIntArray(size, 0);
int[] sorted = arr.clone();
Arrays.sort(sorted);
Quick.quicksort(arr);
TestTools.testIntArraysEquals(sorted, arr);
}
}
}