forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmithWatermanTest.java
More file actions
53 lines (43 loc) · 1.63 KB
/
SmithWatermanTest.java
File metadata and controls
53 lines (43 loc) · 1.63 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.thealgorithms.dynamicprogramming;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
/**
* Unit tests for the {@code SmithWaterman} class.
*/
class SmithWatermanTest {
@Test
void testIdenticalStrings() {
int score = SmithWaterman.align("GATTACA", "GATTACA", 2, -1, -2);
assertEquals(14, score); // full match, 7*2
}
@Test
void testPartialMatch() {
int score = SmithWaterman.align("GATTACA", "TTAC", 2, -1, -2);
assertEquals(8, score); // best local alignment "TTAC"
}
@Test
void testNoMatch() {
int score = SmithWaterman.align("AAAA", "TTTT", 1, -1, -2);
assertEquals(0, score); // no alignment worth keeping
}
@Test
void testInsertionDeletion() {
int score = SmithWaterman.align("ACGT", "ACGGT", 1, -1, -2);
assertEquals(3, score); // local alignment "ACG"
}
@Test
void testEmptyStrings() {
assertEquals(0, SmithWaterman.align("", "", 1, -1, -2));
}
@ParameterizedTest
@CsvSource({"null,ABC", "ABC,null", "null,null"})
void testNullInputs(String s1, String s2) {
String first = "null".equals(s1) ? null : s1;
String second = "null".equals(s2) ? null : s2;
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> SmithWaterman.align(first, second, 1, -1, -2));
assertEquals("Input strings must not be null.", ex.getMessage());
}
}