Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathHammingDistanceTest.java
More file actions
Latest commit
36 lines (29 loc) · 1.47 KB
/
Copy pathHammingDistanceTest.java
File metadata and controls
36 lines (29 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
packagecom.thealgorithms.strings;
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
importstaticorg.junit.jupiter.api.Assertions.assertThrows;
importjava.util.stream.Stream;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.Arguments;
importorg.junit.jupiter.params.provider.CsvSource;
importorg.junit.jupiter.params.provider.MethodSource;
classHammingDistanceTest {
@ParameterizedTest
@CsvSource({"'', '', 0", "'java', 'java', 0", "'karolin', 'kathrin', 3", "'kathrin', 'kerstin', 4", "'00000', '11111', 5", "'10101', '10100', 1"})
voidtestHammingDistance(Strings1, Strings2, intexpected) {
assertEquals(expected, HammingDistance.calculateHammingDistance(s1, s2));
}
@ParameterizedTest
@MethodSource("provideNullInputs")
voidtestHammingDistanceWithNullInputs(Stringinput1, Stringinput2) {
assertThrows(IllegalArgumentException.class, () -> HammingDistance.calculateHammingDistance(input1, input2));
}
privatestaticStream<Arguments> provideNullInputs() {
returnStream.of(Arguments.of(null, "abc"), Arguments.of("abc", null), Arguments.of(null, null));
}
@Test
voidtestNotEqualStringLengths() {
Exceptionexception = assertThrows(IllegalArgumentException.class, () -> HammingDistance.calculateHammingDistance("ab", "abc"));
assertEquals("String lengths must be equal", exception.getMessage());
}
}