Skip to content

Commit cee0a9b

Browse files
Update HammingDistanceTest.java
1 parent 3515288 commit cee0a9b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import org.junit.jupiter.params.provider.CsvSource;
1111
import org.junit.jupiter.params.provider.MethodSource;
1212

13+
/**
14+
* HammingDistanceTest performs unit tests on the HammingDistance class.
15+
*/
1316
class HammingDistanceTest {
1417

18+
// Valid Input Tests
1519
@Nested
1620
@DisplayName("Valid Input Tests")
1721
class ValidInputTests {
@@ -26,6 +30,7 @@ class ValidInputTests {
2630
"'10101', '10100', 1"
2731
})
2832
void testHammingDistance(String s1, String s2, int expected) {
33+
// Assert that the calculated distance matches the expected result
2934
assertEquals(
3035
expected,
3136
HammingDistance.calculateHammingDistance(s1, s2),
@@ -34,13 +39,15 @@ void testHammingDistance(String s1, String s2, int expected) {
3439
}
3540
}
3641

42+
// Invalid Input Tests
3743
@Nested
3844
@DisplayName("Invalid Input Tests")
3945
class InvalidInputTests {
4046

41-
@ParameterizedTest(name = "Hamming distance should throw exception for null inputs: \"{0}\", \"{1}\"")
47+
@ParameterizedTest(name = "Expect exception for null inputs: \"{0}\", \"{1}\"")
4248
@MethodSource("provideNullInputs")
4349
void testHammingDistanceWithNullInputs(String input1, String input2) {
50+
// Check for IllegalArgumentException when inputs are null
4451
IllegalArgumentException exception = assertThrows(
4552
IllegalArgumentException.class,
4653
() -> HammingDistance.calculateHammingDistance(input1, input2),
@@ -49,6 +56,7 @@ void testHammingDistanceWithNullInputs(String input1, String input2) {
4956
assertEquals("Input strings cannot be null", exception.getMessage());
5057
}
5158

59+
// Provide null input test cases
5260
private static Stream<Arguments> provideNullInputs() {
5361
return Stream.of(
5462
Arguments.of(null, "abc"),
@@ -60,6 +68,7 @@ private static Stream<Arguments> provideNullInputs() {
6068
@Test
6169
@DisplayName("Should throw exception for unequal string lengths")
6270
void testNotEqualStringLengths() {
71+
// Check for IllegalArgumentException when string lengths are unequal
6372
IllegalArgumentException exception = assertThrows(
6473
IllegalArgumentException.class,
6574
() -> HammingDistance.calculateHammingDistance("ab", "abc"),

0 commit comments

Comments
 (0)