forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomizedClosestPairTest.java
More file actions
30 lines (24 loc) · 1.05 KB
/
RandomizedClosestPairTest.java
File metadata and controls
30 lines (24 loc) · 1.05 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
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 testFindClosestPairDistance() {
Point[] points = {new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(8, 8), new Point(13, 13)};
double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(Math.sqrt(2), result, 0.00001);
}
@Test
public void testWithIdenticalPoints() {
Point[] points = {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 testWithDistantPoints() {
Point[] points = {new Point(0, 0), new Point(5, 0), new Point(10, 0)};
double result = RandomizedClosestPair.findClosestPairDistance(points);
assertEquals(5.0, result, 0.00001);
}
}