10
10
import org .junit .jupiter .params .provider .CsvSource ;
11
11
import org .junit .jupiter .params .provider .MethodSource ;
12
12
13
+ /**
14
+ * HammingDistanceTest performs unit tests on the HammingDistance class.
15
+ */
13
16
class HammingDistanceTest {
14
17
18
+ // Valid Input Tests
15
19
@ Nested
16
20
@ DisplayName ("Valid Input Tests" )
17
21
class ValidInputTests {
@@ -26,6 +30,7 @@ class ValidInputTests {
26
30
"'10101', '10100', 1"
27
31
})
28
32
void testHammingDistance (String s1 , String s2 , int expected ) {
33
+ // Assert that the calculated distance matches the expected result
29
34
assertEquals (
30
35
expected ,
31
36
HammingDistance .calculateHammingDistance (s1 , s2 ),
@@ -34,13 +39,15 @@ void testHammingDistance(String s1, String s2, int expected) {
34
39
}
35
40
}
36
41
42
+ // Invalid Input Tests
37
43
@ Nested
38
44
@ DisplayName ("Invalid Input Tests" )
39
45
class InvalidInputTests {
40
46
41
- @ ParameterizedTest (name = "Hamming distance should throw exception for null inputs: \" {0}\" , \" {1}\" " )
47
+ @ ParameterizedTest (name = "Expect exception for null inputs: \" {0}\" , \" {1}\" " )
42
48
@ MethodSource ("provideNullInputs" )
43
49
void testHammingDistanceWithNullInputs (String input1 , String input2 ) {
50
+ // Check for IllegalArgumentException when inputs are null
44
51
IllegalArgumentException exception = assertThrows (
45
52
IllegalArgumentException .class ,
46
53
() -> HammingDistance .calculateHammingDistance (input1 , input2 ),
@@ -49,6 +56,7 @@ void testHammingDistanceWithNullInputs(String input1, String input2) {
49
56
assertEquals ("Input strings cannot be null" , exception .getMessage ());
50
57
}
51
58
59
+ // Provide null input test cases
52
60
private static Stream <Arguments > provideNullInputs () {
53
61
return Stream .of (
54
62
Arguments .of (null , "abc" ),
@@ -60,6 +68,7 @@ private static Stream<Arguments> provideNullInputs() {
60
68
@ Test
61
69
@ DisplayName ("Should throw exception for unequal string lengths" )
62
70
void testNotEqualStringLengths () {
71
+ // Check for IllegalArgumentException when string lengths are unequal
63
72
IllegalArgumentException exception = assertThrows (
64
73
IllegalArgumentException .class ,
65
74
() -> HammingDistance .calculateHammingDistance ("ab" , "abc" ),
0 commit comments