-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortTaskTest.java
More file actions
47 lines (38 loc) · 1.16 KB
/
Copy pathSortTaskTest.java
File metadata and controls
47 lines (38 loc) · 1.16 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
package fork.join;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
public class SortTaskTest {
private static final int NARRAY = 16; //For demo only
long[] array = new long[NARRAY];
Random rand = new Random();
@Before
public void setUp() {
for (int i = 0; i < array.length; i++) {
array[i] = rand.nextLong()%100; //For demo only
}
System.out.println("Initial Array: " + Arrays.toString(array));
}
@Test
public void testSort() throws Exception {
ForkJoinTask<?> sort = new SortTask(array);
ForkJoinPool fjpool = new ForkJoinPool();
fjpool.submit(sort);
fjpool.shutdown();
fjpool.awaitTermination(30, TimeUnit.SECONDS);
assertTrue(checkSorted(array));
}
boolean checkSorted(long[] a) {
for (int i = 0; i < a.length - 1; i++) {
if (a[i] > (a[i + 1])) {
return false;
}
}
return true;
}
}