-
Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathRandomizedClosestPairTest.java
45 lines (38 loc) · 1.27 KB
/
RandomizedClosestPairTest.java
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
package com.thealgorithms.randomized;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.thealgorithms.randomized.RandomizedClosestPair.Point;
import org.junit.jupiter.api.Test;
public class RandomizedClosestPairTest {
@Test
public void testClosestPairBasic() {
Point[] points = new Point[] {
new Point(2, 3),
new Point(12, 30),
new Point(40, 50),
new Point(5, 1),
new Point(12, 10),
new Point(3, 4)
};
double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(Math.hypot(1, 1), result, 0.01); // Closest pair: (2,3) and (3,4)
}
@Test
public void testIdenticalPoints() {
Point[] points = new Point[] {
new Point(0, 0),
new Point(0, 0),
new Point(1, 1),
};
double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(0.0, result, 0.00001);
}
@Test
public void testMinimalCase() {
Point[] points = new Point[] {
new Point(0, 0),
new Point(3, 4)
};
double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(5.0, result, 0.00001);
}
}