forked from Kotlin-Polytech/FromKotlinToJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointTest.java
More file actions
39 lines (32 loc) · 1.36 KB
/
Copy pathPointTest.java
File metadata and controls
39 lines (32 loc) · 1.36 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
package part2.point;
import org.junit.Test;
import java.util.*;
import static org.junit.Assert.*;
public class PointTest {
private void generate(Collection<Point> toFill, int size) {
Random random = new Random();
for (int i = 0; i < size; i++) {
toFill.add(new Point(random.nextDouble() * 1e+3,
random.nextDouble() * 1e+3));
}
}
@Test
public void testArrayList() {
Collection<Point> points = new ArrayList<>();
generate(points, 20000000);
long startTime = Calendar.getInstance().getTimeInMillis();
System.out.println(startTime);
Point result = points.stream()
.min(Comparator.comparingDouble(Point::abs))
.get();
System.out.println("Closest point: " + result + " with distance: " + result.abs());
long intermediateTime = Calendar.getInstance().getTimeInMillis();
System.out.println("Time spent: " + (intermediateTime - startTime));
Point result2 = points.parallelStream()
.min(Comparator.comparingDouble(Point::abs))
.get();
System.out.println("Closest point: " + result2 + " with distance: " + result2.abs());
System.out.println("Time spent: " + (Calendar.getInstance().getTimeInMillis() - intermediateTime));
assertEquals(result, result2);
}
}