-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathHeapSortTest.java
More file actions
58 lines (49 loc) · 1.47 KB
/
HeapSortTest.java
File metadata and controls
58 lines (49 loc) · 1.47 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
package com.examplehub.sorts;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.examplehub.domain.Student;
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 HeapSortTest {
private Sort sort;
@BeforeEach
public void before() {
sort = new HeapSort();
}
@Test
void testSort() {
int[] ints = RandomUtils.randomInts(-50, 50, 100);
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));
}
@Test
void testComparable() {
Student[] students = new Student[5];
students[0] = new Student(1, 98, 99, 100);
students[1] = new Student(2, 100, 99, 98);
students[2] = new Student(3, 100, 98, 99);
students[3] = new Student(4, 100, 100, 100);
students[4] = new Student(5, 99, 99, 99);
sort.sort(students);
assertTrue(SortUtils.isSorted(students));
}
}