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.assertThat;
20 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
21
22 import org.junit.jupiter.api.BeforeAll;
23 import org.junit.jupiter.api.Test;
24
25
26
27
28 public class LongestCommonSubsequenceDistanceTest {
29
30 private static LongestCommonSubsequenceDistance subject;
31
32 @BeforeAll
33 public static void setup() {
34 subject = new LongestCommonSubsequenceDistance();
35 }
36
37 @Test
38 public void testGettingLongestCommonSubsequenceDistance() {
39 assertThat(subject.apply("", "")).isEqualTo(0);
40 assertThat(subject.apply("left", "")).isEqualTo(4);
41 assertThat(subject.apply("", "right")).isEqualTo(5);
42 assertThat(subject.apply("frog", "fog")).isEqualTo(1);
43 assertThat(subject.apply("fly", "ant")).isEqualTo(6);
44 assertThat(subject.apply("elephant", "hippo")).isEqualTo(11);
45 assertThat(subject.apply("ABC Corporation", "ABC Corp")).isEqualTo(7);
46 assertThat(subject.apply("D N H Enterprises Inc", "D & H Enterprises, Inc.")).isEqualTo(4);
47 assertThat(subject.apply("My Gym Children's Fitness Center", "My Gym. Childrens Fitness")).isEqualTo(9);
48 assertThat(subject.apply("PENNSYLVANIA", "PENNCISYLVNIA")).isEqualTo(3);
49 assertThat(subject.apply("left", "right")).isEqualTo(7);
50 assertThat(subject.apply("leettteft", "ritttght")).isEqualTo(9);
51 assertThat(subject.apply("the same string", "the same string")).isEqualTo(0);
52 }
53
54 @Test
55 public void testGettingLongestCommonSubsequenceDistanceNullNull() {
56 assertThatIllegalArgumentException().isThrownBy(() -> subject.apply(null, null));
57 }
58
59 @Test
60 public void testGettingLongestCommonSubsequenceDistanceNullString() {
61 assertThatIllegalArgumentException().isThrownBy(() -> subject.apply(null, "right"));
62 }
63
64 @Test
65 public void testGettingLongestCommonSubsequenceDistanceStringNull() {
66 assertThatIllegalArgumentException().isThrownBy(() -> subject.apply(" ", null));
67 }
68
69 }