forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSortTest.java
More file actions
49 lines (40 loc) · 1.17 KB
/
QuickSortTest.java
File metadata and controls
49 lines (40 loc) · 1.17 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
package com.examplehub.sorts;
import static org.junit.jupiter.api.Assertions.*;
import com.examplehub.utils.RandomUtils;
import com.examplehub.utils.SortUtils;
import java.util.Arrays;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class QuickSortTest {
private Sort sort;
@BeforeEach
public void before() {
sort = new QuickSort();
}
@Test
void testQuickSort() {
int[] ints = RandomUtils.randomInts(-50, 50, 100);
sort.sort(ints);
assertTrue(SortUtils.isSorted(ints));
ints = new int[] {0, 1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
sort.sort(ints);
assertTrue(SortUtils.isSorted(ints));
}
@Test
void testSortIntegers() {
Integer[] integers =
Arrays.stream(RandomUtils.randomInts(-50, 50, 100)).boxed().toArray(Integer[]::new);
sort.sort(integers);
assertTrue(SortUtils.isSorted(integers));
}
@Test
void testSortedDoubles() {
Double[] doubles = new Double[100];
double[] tempDoubles = RandomUtils.randomDoubles(-50, 50, 100);
for (int i = 0; i < doubles.length; ++i) {
doubles[i] = tempDoubles[i];
}
sort.sort(doubles);
assertTrue(SortUtils.isSorted(doubles));
}
}