forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHammingDistanceTest.java
More file actions
39 lines (34 loc) · 1.12 KB
/
HammingDistanceTest.java
File metadata and controls
39 lines (34 loc) · 1.12 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
37
38
39
package com.thealgorithms.strings;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
public class HammingDistanceTest {
@Test
void testHammingDistance() throws Exception {
assertEquals(HammingDistance.calculateHammingDistance("", ""), 0);
assertEquals(
HammingDistance.calculateHammingDistance("java", "java"),
0
);
assertEquals(
HammingDistance.calculateHammingDistance("karolin", "kathrin"),
3
);
assertEquals(
HammingDistance.calculateHammingDistance("kathrin", "kerstin"),
4
);
assertEquals(
HammingDistance.calculateHammingDistance("00000", "11111"),
5
);
}
@Test
void testNotEqualStringLengths() {
Exception exception = assertThrows(
Exception.class,
() -> HammingDistance.calculateHammingDistance("ab", "abc")
);
assertEquals("String lengths must be equal", exception.getMessage());
}
}