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