1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.text.similarity;
18
19 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21
22 import org.junit.jupiter.api.BeforeAll;
23 import org.junit.jupiter.api.Test;
24
25
26
27
28 public class JaroWinklerDistanceTest {
29
30 private static JaroWinklerDistance distance;
31
32 @BeforeAll
33 public static void setUp() {
34 distance = new JaroWinklerDistance();
35 }
36
37 @Test
38 public void testGetJaroWinklerDistance_NullNull() {
39 assertThatIllegalArgumentException().isThrownBy(() -> distance.apply(null, null));
40 }
41
42 @Test
43 public void testGetJaroWinklerDistance_NullString() {
44 assertThatIllegalArgumentException().isThrownBy(() -> distance.apply(null, "clear"));
45 }
46
47 @Test
48 public void testGetJaroWinklerDistance_StringNull() {
49 assertThatIllegalArgumentException().isThrownBy(() -> distance.apply(" ", null));
50 }
51
52 @Test
53 public void testGetJaroWinklerDistance_StringString() {
54 assertEquals(0.07501d, distance.apply("frog", "fog"), 0.00001d);
55 assertEquals(1.0d, distance.apply("fly", "ant"), 0.00000000000000000001d);
56 assertEquals(0.55834d, distance.apply("elephant", "hippo"), 0.00001d);
57 assertEquals(0.09334d, distance.apply("ABC Corporation", "ABC Corp"), 0.00001d);
58 assertEquals(0.04749d, distance.apply("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.00001d);
59 assertEquals(0.058d, distance.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.00001d);
60 assertEquals(0.101982d, distance.apply("PENNSYLVANIA", "PENNCISYLVNIA"), 0.00001d);
61 assertEquals(0.028572d, distance.apply("/opt/software1", "/opt/software2"), 0.00001d);
62 assertEquals(0.058334d, distance.apply("aaabcd", "aaacdb"), 0.00001d);
63 assertEquals(0.088889d, distance.apply("John Horn", "John Hopkins"), 0.00001d);
64 assertEquals(0d, distance.apply("", ""), 0.00001d);
65 assertEquals(0d, distance.apply("foo", "foo"), 0.00001d);
66 assertEquals(1 - 0.94166d, distance.apply("foo", "foo "), 0.00001d);
67 assertEquals(1 - 0.90666d, distance.apply("foo", "foo "), 0.00001d);
68 assertEquals(1 - 0.86666d, distance.apply("foo", " foo "), 0.00001d);
69 assertEquals(1 - 0.51111d, distance.apply("foo", " foo"), 0.00001d);
70 }
71
72 }