test: EditDistanceTest (#5397)

This commit is contained in:
Alex Klymenko 2024-08-26 08:48:30 +02:00 committed by GitHub
parent cdb6412601
commit be6b0d835b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 15 deletions

View File

@ -1,6 +1,5 @@
package com.thealgorithms.dynamicprogramming; package com.thealgorithms.dynamicprogramming;
import java.util.Scanner;
/** /**
* A DynamicProgramming based solution for Edit Distance problem In Java * A DynamicProgramming based solution for Edit Distance problem In Java
* Description of Edit Distance with an Example: * Description of Edit Distance with an Example:
@ -68,20 +67,6 @@ public final class EditDistance {
return dp[len1][len2]; 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 // edit distance problem
public static int editDistance(String s1, String s2) { public static int editDistance(String s1, String s2) {
int[][] storage = new int[s1.length() + 1][s2.length() + 1]; int[][] storage = new int[s1.length() + 1][s2.length() + 1];

View File

@ -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));
}
}