diff --git a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java index 55ce50d3..020d1519 100644 --- a/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java +++ b/src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java @@ -1,6 +1,5 @@ package com.thealgorithms.dynamicprogramming; -import java.util.Scanner; /** * A DynamicProgramming based solution for Edit Distance problem In Java * Description of Edit Distance with an Example: @@ -68,20 +67,6 @@ public final class EditDistance { return dp[len1][len2]; } - public static void main(String[] args) { - Scanner input = new Scanner(System.in); - String s1; - String s2; - System.out.println("Enter the First String"); - s1 = input.nextLine(); - System.out.println("Enter the Second String"); - s2 = input.nextLine(); - // ans stores the final Edit Distance between the two strings - int ans = minDistance(s1, s2); - System.out.println("The minimum Edit Distance between \"" + s1 + "\" and \"" + s2 + "\" is " + ans); - input.close(); - } - // edit distance problem public static int editDistance(String s1, String s2) { int[][] storage = new int[s1.length() + 1][s2.length() + 1]; diff --git a/src/test/java/com/thealgorithms/dynamicprogramming/EditDistanceTest.java b/src/test/java/com/thealgorithms/dynamicprogramming/EditDistanceTest.java new file mode 100644 index 00000000..267be9b0 --- /dev/null +++ b/src/test/java/com/thealgorithms/dynamicprogramming/EditDistanceTest.java @@ -0,0 +1,15 @@ +package com.thealgorithms.dynamicprogramming; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +public class EditDistanceTest { + + @ParameterizedTest + @CsvSource({"'', '', 0", "'abc', '', 3", "'', 'abcd', 4", "'same', 'same', 0", "'a', 'b', 1", "'abc', 'abd', 1"}) + void testMinDistance(String str1, String str2, int expected) { + assertEquals(expected, EditDistance.minDistance(str1, str2)); + } +}