Skip to content

Commit 5f1fc77

Browse files
author
alxkm
committed
test: EditDistanceTest
1 parent 7e9cdad commit 5f1fc77

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

src/main/java/com/thealgorithms/dynamicprogramming/EditDistance.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.thealgorithms.dynamicprogramming;
22

3-
import java.util.Scanner;
43
/**
54
* A DynamicProgramming based solution for Edit Distance problem In Java
65
* Description of Edit Distance with an Example:
@@ -68,20 +67,6 @@ then take the minimum of the various operations(i.e insertion,removal,substituti
6867
return dp[len1][len2];
6968
}
7069

71-
public static void main(String[] args) {
72-
Scanner input = new Scanner(System.in);
73-
String s1;
74-
String s2;
75-
System.out.println("Enter the First String");
76-
s1 = input.nextLine();
77-
System.out.println("Enter the Second String");
78-
s2 = input.nextLine();
79-
// ans stores the final Edit Distance between the two strings
80-
int ans = minDistance(s1, s2);
81-
System.out.println("The minimum Edit Distance between \"" + s1 + "\" and \"" + s2 + "\" is " + ans);
82-
input.close();
83-
}
84-
8570
// edit distance problem
8671
public static int editDistance(String s1, String s2) {
8772
int[][] storage = new int[s1.length() + 1][s2.length() + 1];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.thealgorithms.dynamicprogramming;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
public class EditDistanceTest {
9+
10+
@ParameterizedTest
11+
@CsvSource({"'', '', 0", "'abc', '', 3", "'', 'abcd', 4", "'same', 'same', 0", "'a', 'b', 1", "'abc', 'abd', 1"})
12+
void testMinDistance(String str1, String str2, int expected) {
13+
assertEquals(expected, EditDistance.minDistance(str1, str2));
14+
}
15+
}

0 commit comments

Comments
 (0)