Skip to content

Commit

Permalink
ref: remove duplicated test data
Browse files Browse the repository at this point in the history
  • Loading branch information
TruongNhanNguyen committed May 3, 2024
1 parent 46a4167 commit 0883eb8
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.stream.Stream;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public class LevenshteinDistanceTests {
private static final Object[][] TEST_CASES
= {{0, "", ""}, {0, "Hello, World!", "Hello, World!"}, {4, "", "Rust"}, {3, "horse", "ros"}, {6, "tan", "elephant"}, {8, "execute", "intention"}, {0, "", ""}, {0, "Hello, World!", "Hello, World!"}, {4, "", "Rust"}, {3, "horse", "ros"}, {6, "tan", "elephant"}, {8, "execute", "intention"}};

@ParameterizedTest
@CsvSource({// String 1, String 2, Expected Distance
"'', '', 0", "'Hello, World!', 'Hello, World!', 0", "'', 'Rust', 4", "horse, ros, 3", "tan, elephant, 6", "execute, intention, 8"})
void
naiveLevenshteinDistanceTest(String str1, String str2, int expectedDistance) {
int result = LevenshteinDistance.naiveLevenshteinDistance(str1, str2);
assertEquals(expectedDistance, result);
@MethodSource("testCases")
void testLevenshteinDistance(int expectedDistance, String str1, String str2) {
assertEquals(expectedDistance, LevenshteinDistance.naiveLevenshteinDistance(str1, str2));
assertEquals(expectedDistance, LevenshteinDistance.optimizedLevenshteinDistance(str1, str2));
}

@ParameterizedTest
@CsvSource({// String 1, String 2, Expected Distance
"'', '', 0", "'Hello, World!', 'Hello, World!', 0", "'', 'Rust', 4", "horse, ros, 3", "tan, elephant, 6", "execute, intention, 8"})
void
optimizedLevenshteinDistanceTest(String str1, String str2, int expectedDistance) {
int result = LevenshteinDistance.optimizedLevenshteinDistance(str1, str2);
assertEquals(expectedDistance, result);
private static Stream<Arguments> testCases() {
return Stream.of(TEST_CASES).map(args -> Arguments.of(args[0], args[1], args[2]));
}
}

0 comments on commit 0883eb8

Please sign in to comment.