Repository: commons-text Updated Branches: refs/heads/master b2434bcbc -> feb9a9b1c
Tests should be suffixed with 'test' Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/feb9a9b1 Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/feb9a9b1 Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/feb9a9b1 Branch: refs/heads/master Commit: feb9a9b1ce94541c3dd4d14401ea097da103684c Parents: b2434bc Author: Benedikt Ritter <[email protected]> Authored: Sat Nov 29 11:59:50 2014 +0100 Committer: Benedikt Ritter <[email protected]> Committed: Sat Nov 29 11:59:50 2014 +0100 ---------------------------------------------------------------------- .../text/similarity/FuzzyDistanceTest.java | 75 ++++++++++ .../similarity/JaroWrinklerDistanceTest.java | 62 ++++++++ .../similarity/LevenshteinDistanceTest.java | 146 +++++++++++++++++++ .../text/similarity/TestFuzzyDistance.java | 75 ---------- .../similarity/TestJaroWrinklerDistance.java | 62 -------- .../similarity/TestLevenshteinDistance.java | 146 ------------------- 6 files changed, 283 insertions(+), 283 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/FuzzyDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/FuzzyDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/FuzzyDistanceTest.java new file mode 100644 index 0000000..49e51ba --- /dev/null +++ b/src/test/java/org/apache/commons/text/similarity/FuzzyDistanceTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +import static org.junit.Assert.assertEquals; + +import java.util.Locale; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit tests for {@link org.apache.commons.text.FuzzyDistance}. + */ +public class FuzzyDistanceTest { + + private static FuzzyDistance distance; + + @BeforeClass + public static void setUp() { + distance = new FuzzyDistance(); + } + + @Test + public void testGetFuzzyDistance() throws Exception { + assertEquals(0, (int) distance.compare("", "", Locale.ENGLISH)); + assertEquals(0, + (int) distance.compare("Workshop", "b", Locale.ENGLISH)); + assertEquals(1, + (int) distance.compare("Room", "o", Locale.ENGLISH)); + assertEquals(1, + (int) distance.compare("Workshop", "w", Locale.ENGLISH)); + assertEquals(2, + (int) distance.compare("Workshop", "ws", Locale.ENGLISH)); + assertEquals(4, + (int) distance.compare("Workshop", "wo", Locale.ENGLISH)); + assertEquals(3, (int) distance.compare( + "Apache Software Foundation", "asf", Locale.ENGLISH)); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetFuzzyDistance_NullNullNull() throws Exception { + distance.compare(null, null, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetFuzzyDistance_StringNullLoclae() throws Exception { + distance.compare(" ", null, Locale.ENGLISH); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetFuzzyDistance_NullStringLocale() throws Exception { + distance.compare(null, "clear", Locale.ENGLISH); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetFuzzyDistance_StringStringNull() throws Exception { + distance.compare(" ", "clear", null); + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/JaroWrinklerDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/JaroWrinklerDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/JaroWrinklerDistanceTest.java new file mode 100644 index 0000000..73e18f7 --- /dev/null +++ b/src/test/java/org/apache/commons/text/similarity/JaroWrinklerDistanceTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit tests for {@link org.apache.commons.text.JaroWrinklerDistance}. + */ +public class JaroWrinklerDistanceTest { + + private static JaroWrinklerDistance distance; + + @BeforeClass + public static void setUp() { + distance = new JaroWrinklerDistance(); + } + + @Test + public void testGetJaroWinklerDistance_StringString() { + assertEquals(0.93d, (double) distance.compare("frog", "fog"), 0.0d); + assertEquals(0.0d, (double) distance.compare("fly", "ant"), 0.0d); + assertEquals(0.44d, (double) distance.compare("elephant", "hippo"), 0.0d); + assertEquals(0.91d, (double) distance.compare("ABC Corporation", "ABC Corp"), 0.0d); + assertEquals(0.93d, (double) distance.compare("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d); + assertEquals(0.94d, (double) distance.compare("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); + assertEquals(0.9d, (double) distance.compare("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetJaroWinklerDistance_NullNull() throws Exception { + distance.compare(null, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetJaroWinklerDistance_StringNull() throws Exception { + distance.compare(" ", null); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetJaroWinklerDistance_NullString() throws Exception { + distance.compare(null, "clear"); + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java b/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java new file mode 100644 index 0000000..1d4e6fa --- /dev/null +++ b/src/test/java/org/apache/commons/text/similarity/LevenshteinDistanceTest.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.text.similarity; + +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit tests for {@link org.apache.commons.text.LevenshteinDistance}. + */ +public class LevenshteinDistanceTest { + + private static LevenshteinDistance distance; + + @BeforeClass + public static void setUp() { + distance = new LevenshteinDistance(); + } + + @Test + public void testGetLevenshteinDistance_StringString() { + assertEquals(0, (int) distance.compare("", "")); + assertEquals(1, (int) distance.compare("", "a")); + assertEquals(7, (int) distance.compare("aaapppp", "")); + assertEquals(1, (int) distance.compare("frog", "fog")); + assertEquals(3, (int) distance.compare("fly", "ant")); + assertEquals(7, (int) distance.compare("elephant", "hippo")); + assertEquals(7, (int) distance.compare("hippo", "elephant")); + assertEquals(8, (int) distance.compare("hippo", "zzzzzzzz")); + assertEquals(8, (int) distance.compare("zzzzzzzz", "hippo")); + assertEquals(1, (int) distance.compare("hello", "hallo")); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLevenshteinDistance_NullString() throws Exception { + distance.compare("a", null); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLevenshteinDistance_StringNull() throws Exception { + distance.compare(null, "a"); + } + + @Test + public void testGetLevenshteinDistance_StringStringInt() { + // empty strings + assertEquals(0, (int) distance.compare("", "", 0)); + assertEquals(7, (int) distance.compare("aaapppp", "", 8)); + assertEquals(7, (int) distance.compare("aaapppp", "", 7)); + assertEquals(-1, (int) distance.compare("aaapppp", "", 6)); + + // unequal strings, zero threshold + assertEquals(-1, (int) distance.compare("b", "a", 0)); + assertEquals(-1, (int) distance.compare("a", "b", 0)); + + // equal strings + assertEquals(0, (int) distance.compare("aa", "aa", 0)); + assertEquals(0, (int) distance.compare("aa", "aa", 2)); + + // same length + assertEquals(-1, (int) distance.compare("aaa", "bbb", 2)); + assertEquals(3, (int) distance.compare("aaa", "bbb", 3)); + + // big stripe + assertEquals(6, (int) distance.compare("aaaaaa", "b", 10)); + + // distance less than threshold + assertEquals(7, (int) distance.compare("aaapppp", "b", 8)); + assertEquals(3, (int) distance.compare("a", "bbb", 4)); + + // distance equal to threshold + assertEquals(7, (int) distance.compare("aaapppp", "b", 7)); + assertEquals(3, (int) distance.compare("a", "bbb", 3)); + + // distance greater than threshold + assertEquals(-1, (int) distance.compare("a", "bbb", 2)); + assertEquals(-1, (int) distance.compare("bbb", "a", 2)); + assertEquals(-1, (int) distance.compare("aaapppp", "b", 6)); + + // stripe runs off array, strings not similar + assertEquals(-1, (int) distance.compare("a", "bbb", 1)); + assertEquals(-1, (int) distance.compare("bbb", "a", 1)); + + // stripe runs off array, strings are similar + assertEquals(-1, (int) distance.compare("12345", "1234567", 1)); + assertEquals(-1, (int) distance.compare("1234567", "12345", 1)); + + // old getLevenshteinDistance test cases + assertEquals(1, (int) distance.compare("frog", "fog", 1)); + assertEquals(3, (int) distance.compare("fly", "ant", 3)); + assertEquals(7, (int) distance.compare("elephant", "hippo", 7)); + assertEquals(-1, (int) distance.compare("elephant", "hippo", 6)); + assertEquals(7, (int) distance.compare("hippo", "elephant", 7)); + assertEquals(-1, (int) distance.compare("hippo", "elephant", 6)); + assertEquals(8, (int) distance.compare("hippo", "zzzzzzzz", 8)); + assertEquals(8, (int) distance.compare("zzzzzzzz", "hippo", 8)); + assertEquals(1, (int) distance.compare("hello", "hallo", 1)); + + assertEquals(1, + (int) distance.compare("frog", "fog", Integer.MAX_VALUE)); + assertEquals(3, (int) distance.compare("fly", "ant", Integer.MAX_VALUE)); + assertEquals(7, + (int) distance.compare("elephant", "hippo", Integer.MAX_VALUE)); + assertEquals(7, + (int) distance.compare("hippo", "elephant", Integer.MAX_VALUE)); + assertEquals(8, + (int) distance.compare("hippo", "zzzzzzzz", Integer.MAX_VALUE)); + assertEquals(8, + (int) distance.compare("zzzzzzzz", "hippo", Integer.MAX_VALUE)); + assertEquals(1, + (int) distance.compare("hello", "hallo", Integer.MAX_VALUE)); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLevenshteinDistance_NullStringInt() throws Exception { + distance.compare(null, "a", 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLevenshteinDistance_StringNullInt() throws Exception { + distance.compare("a", null, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testGetLevenshteinDistance_StringStringNegativeInt() + throws Exception { + distance.compare("a", "a", -1); + } + +} http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/TestFuzzyDistance.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/TestFuzzyDistance.java b/src/test/java/org/apache/commons/text/similarity/TestFuzzyDistance.java deleted file mode 100644 index 30b1dfc..0000000 --- a/src/test/java/org/apache/commons/text/similarity/TestFuzzyDistance.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -import static org.junit.Assert.assertEquals; - -import java.util.Locale; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Unit tests for {@link org.apache.commons.text.FuzzyDistance}. - */ -public class TestFuzzyDistance { - - private static FuzzyDistance distance; - - @BeforeClass - public static void setUp() { - distance = new FuzzyDistance(); - } - - @Test - public void testGetFuzzyDistance() throws Exception { - assertEquals(0, (int) distance.compare("", "", Locale.ENGLISH)); - assertEquals(0, - (int) distance.compare("Workshop", "b", Locale.ENGLISH)); - assertEquals(1, - (int) distance.compare("Room", "o", Locale.ENGLISH)); - assertEquals(1, - (int) distance.compare("Workshop", "w", Locale.ENGLISH)); - assertEquals(2, - (int) distance.compare("Workshop", "ws", Locale.ENGLISH)); - assertEquals(4, - (int) distance.compare("Workshop", "wo", Locale.ENGLISH)); - assertEquals(3, (int) distance.compare( - "Apache Software Foundation", "asf", Locale.ENGLISH)); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetFuzzyDistance_NullNullNull() throws Exception { - distance.compare(null, null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetFuzzyDistance_StringNullLoclae() throws Exception { - distance.compare(" ", null, Locale.ENGLISH); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetFuzzyDistance_NullStringLocale() throws Exception { - distance.compare(null, "clear", Locale.ENGLISH); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetFuzzyDistance_StringStringNull() throws Exception { - distance.compare(" ", "clear", null); - } - -} http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/TestJaroWrinklerDistance.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/TestJaroWrinklerDistance.java b/src/test/java/org/apache/commons/text/similarity/TestJaroWrinklerDistance.java deleted file mode 100644 index 6477de0..0000000 --- a/src/test/java/org/apache/commons/text/similarity/TestJaroWrinklerDistance.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -import static org.junit.Assert.assertEquals; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Unit tests for {@link org.apache.commons.text.JaroWrinklerDistance}. - */ -public class TestJaroWrinklerDistance { - - private static JaroWrinklerDistance distance; - - @BeforeClass - public static void setUp() { - distance = new JaroWrinklerDistance(); - } - - @Test - public void testGetJaroWinklerDistance_StringString() { - assertEquals(0.93d, (double) distance.compare("frog", "fog"), 0.0d); - assertEquals(0.0d, (double) distance.compare("fly", "ant"), 0.0d); - assertEquals(0.44d, (double) distance.compare("elephant", "hippo"), 0.0d); - assertEquals(0.91d, (double) distance.compare("ABC Corporation", "ABC Corp"), 0.0d); - assertEquals(0.93d, (double) distance.compare("D N H Enterprises Inc", "D & H Enterprises, Inc."), 0.0d); - assertEquals(0.94d, (double) distance.compare("My Gym Children's Fitness Center", "My Gym. Childrens Fitness"), 0.0d); - assertEquals(0.9d, (double) distance.compare("PENNSYLVANIA", "PENNCISYLVNIA"), 0.0d); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetJaroWinklerDistance_NullNull() throws Exception { - distance.compare(null, null); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetJaroWinklerDistance_StringNull() throws Exception { - distance.compare(" ", null); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetJaroWinklerDistance_NullString() throws Exception { - distance.compare(null, "clear"); - } - -} http://git-wip-us.apache.org/repos/asf/commons-text/blob/feb9a9b1/src/test/java/org/apache/commons/text/similarity/TestLevenshteinDistance.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/text/similarity/TestLevenshteinDistance.java b/src/test/java/org/apache/commons/text/similarity/TestLevenshteinDistance.java deleted file mode 100644 index 7790b05..0000000 --- a/src/test/java/org/apache/commons/text/similarity/TestLevenshteinDistance.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.text.similarity; - -import static org.junit.Assert.assertEquals; - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * Unit tests for {@link org.apache.commons.text.LevenshteinDistance}. - */ -public class TestLevenshteinDistance { - - private static LevenshteinDistance distance; - - @BeforeClass - public static void setUp() { - distance = new LevenshteinDistance(); - } - - @Test - public void testGetLevenshteinDistance_StringString() { - assertEquals(0, (int) distance.compare("", "")); - assertEquals(1, (int) distance.compare("", "a")); - assertEquals(7, (int) distance.compare("aaapppp", "")); - assertEquals(1, (int) distance.compare("frog", "fog")); - assertEquals(3, (int) distance.compare("fly", "ant")); - assertEquals(7, (int) distance.compare("elephant", "hippo")); - assertEquals(7, (int) distance.compare("hippo", "elephant")); - assertEquals(8, (int) distance.compare("hippo", "zzzzzzzz")); - assertEquals(8, (int) distance.compare("zzzzzzzz", "hippo")); - assertEquals(1, (int) distance.compare("hello", "hallo")); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetLevenshteinDistance_NullString() throws Exception { - distance.compare("a", null); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetLevenshteinDistance_StringNull() throws Exception { - distance.compare(null, "a"); - } - - @Test - public void testGetLevenshteinDistance_StringStringInt() { - // empty strings - assertEquals(0, (int) distance.compare("", "", 0)); - assertEquals(7, (int) distance.compare("aaapppp", "", 8)); - assertEquals(7, (int) distance.compare("aaapppp", "", 7)); - assertEquals(-1, (int) distance.compare("aaapppp", "", 6)); - - // unequal strings, zero threshold - assertEquals(-1, (int) distance.compare("b", "a", 0)); - assertEquals(-1, (int) distance.compare("a", "b", 0)); - - // equal strings - assertEquals(0, (int) distance.compare("aa", "aa", 0)); - assertEquals(0, (int) distance.compare("aa", "aa", 2)); - - // same length - assertEquals(-1, (int) distance.compare("aaa", "bbb", 2)); - assertEquals(3, (int) distance.compare("aaa", "bbb", 3)); - - // big stripe - assertEquals(6, (int) distance.compare("aaaaaa", "b", 10)); - - // distance less than threshold - assertEquals(7, (int) distance.compare("aaapppp", "b", 8)); - assertEquals(3, (int) distance.compare("a", "bbb", 4)); - - // distance equal to threshold - assertEquals(7, (int) distance.compare("aaapppp", "b", 7)); - assertEquals(3, (int) distance.compare("a", "bbb", 3)); - - // distance greater than threshold - assertEquals(-1, (int) distance.compare("a", "bbb", 2)); - assertEquals(-1, (int) distance.compare("bbb", "a", 2)); - assertEquals(-1, (int) distance.compare("aaapppp", "b", 6)); - - // stripe runs off array, strings not similar - assertEquals(-1, (int) distance.compare("a", "bbb", 1)); - assertEquals(-1, (int) distance.compare("bbb", "a", 1)); - - // stripe runs off array, strings are similar - assertEquals(-1, (int) distance.compare("12345", "1234567", 1)); - assertEquals(-1, (int) distance.compare("1234567", "12345", 1)); - - // old getLevenshteinDistance test cases - assertEquals(1, (int) distance.compare("frog", "fog", 1)); - assertEquals(3, (int) distance.compare("fly", "ant", 3)); - assertEquals(7, (int) distance.compare("elephant", "hippo", 7)); - assertEquals(-1, (int) distance.compare("elephant", "hippo", 6)); - assertEquals(7, (int) distance.compare("hippo", "elephant", 7)); - assertEquals(-1, (int) distance.compare("hippo", "elephant", 6)); - assertEquals(8, (int) distance.compare("hippo", "zzzzzzzz", 8)); - assertEquals(8, (int) distance.compare("zzzzzzzz", "hippo", 8)); - assertEquals(1, (int) distance.compare("hello", "hallo", 1)); - - assertEquals(1, - (int) distance.compare("frog", "fog", Integer.MAX_VALUE)); - assertEquals(3, (int) distance.compare("fly", "ant", Integer.MAX_VALUE)); - assertEquals(7, - (int) distance.compare("elephant", "hippo", Integer.MAX_VALUE)); - assertEquals(7, - (int) distance.compare("hippo", "elephant", Integer.MAX_VALUE)); - assertEquals(8, - (int) distance.compare("hippo", "zzzzzzzz", Integer.MAX_VALUE)); - assertEquals(8, - (int) distance.compare("zzzzzzzz", "hippo", Integer.MAX_VALUE)); - assertEquals(1, - (int) distance.compare("hello", "hallo", Integer.MAX_VALUE)); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetLevenshteinDistance_NullStringInt() throws Exception { - distance.compare(null, "a", 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetLevenshteinDistance_StringNullInt() throws Exception { - distance.compare("a", null, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testGetLevenshteinDistance_StringStringNegativeInt() - throws Exception { - distance.compare("a", "a", -1); - } - -}
