Skip to content

Commit 3a15104

Browse files
Update HammingDistanceTest.java
1 parent cee0a9b commit 3a15104

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/test/java/com/thealgorithms/strings/HammingDistanceTest.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
import java.util.stream.Stream;
55
import org.junit.jupiter.api.DisplayName;
66
import org.junit.jupiter.api.Nested;
7-
import org.junit.jupiter.api.Test;
8-
import org.junit.jupiter.params.ParameterizedTest;
9-
import org.junit.jupiter.params.provider.Arguments;
7+
@@ -14,104 +10,62 @@
108
import org.junit.jupiter.params.provider.CsvSource;
119
import org.junit.jupiter.params.provider.MethodSource;
1210

13-
/**
14-
* HammingDistanceTest performs unit tests on the HammingDistance class.
15-
*/
1611
class HammingDistanceTest {
1712

18-
// Valid Input Tests
1913
@Nested
2014
@DisplayName("Valid Input Tests")
2115
class ValidInputTests {
@@ -30,7 +24,6 @@ class ValidInputTests {
3024
"'10101', '10100', 1"
3125
})
3226
void testHammingDistance(String s1, String s2, int expected) {
33-
// Assert that the calculated distance matches the expected result
3427
assertEquals(
3528
expected,
3629
HammingDistance.calculateHammingDistance(s1, s2),
@@ -39,15 +32,13 @@ void testHammingDistance(String s1, String s2, int expected) {
3932
}
4033
}
4134

42-
// Invalid Input Tests
4335
@Nested
4436
@DisplayName("Invalid Input Tests")
4537
class InvalidInputTests {
4638

47-
@ParameterizedTest(name = "Expect exception for null inputs: \"{0}\", \"{1}\"")
39+
@ParameterizedTest(name = "Hamming distance should throw exception for null inputs: \"{0}\", \"{1}\"")
4840
@MethodSource("provideNullInputs")
4941
void testHammingDistanceWithNullInputs(String input1, String input2) {
50-
// Check for IllegalArgumentException when inputs are null
5142
IllegalArgumentException exception = assertThrows(
5243
IllegalArgumentException.class,
5344
() -> HammingDistance.calculateHammingDistance(input1, input2),
@@ -56,7 +47,6 @@ void testHammingDistanceWithNullInputs(String input1, String input2) {
5647
assertEquals("Input strings cannot be null", exception.getMessage());
5748
}
5849

59-
// Provide null input test cases
6050
private static Stream<Arguments> provideNullInputs() {
6151
return Stream.of(
6252
Arguments.of(null, "abc"),
@@ -68,7 +58,6 @@ private static Stream<Arguments> provideNullInputs() {
6858
@Test
6959
@DisplayName("Should throw exception for unequal string lengths")
7060
void testNotEqualStringLengths() {
71-
// Check for IllegalArgumentException when string lengths are unequal
7261
IllegalArgumentException exception = assertThrows(
7362
IllegalArgumentException.class,
7463
() -> HammingDistance.calculateHammingDistance("ab", "abc"),

0 commit comments

Comments
 (0)