Skip to content

Commit 60c0291

Browse files
committed
added tests
1 parent 9bcb7f5 commit 60c0291

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

DynamicProgramming/LongestPalindromicSubsequence.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package DynamicProgramming;
1+
package test;
22
import java.lang.*;
33
import java.io.*;
44
import java.util.*;
55

66
/**
7-
* @author Matteo Messmer https://github.com/matteomessmer
87
* Algorithm explanation https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
98
*/
109
public class LongestPalindromicSubsequence {
@@ -19,9 +18,8 @@ public static void main(String[] args) {
1918
System.out.println(b + " => " + bLPS);
2019
}
2120

22-
private static String LPS(String original) {
23-
StringBuilder reverse = new StringBuilder();
24-
reverse.append(original);
21+
public static String LPS(String original) throws IllegalArgumentException {
22+
StringBuilder reverse = new StringBuilder(original);
2523
reverse = reverse.reverse();
2624
return recursiveLPS(original, reverse.toString());
2725
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package test;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
class LongestPalindromicSubsequenceTests {
8+
9+
@Test
10+
void test1() {
11+
assertEquals(LongestPalindromicSubsequence.LPS(""), "");
12+
}
13+
14+
@Test
15+
void test2() {
16+
assertEquals(LongestPalindromicSubsequence.LPS("A"), "A");
17+
}
18+
19+
@Test
20+
void test3() {
21+
assertEquals(LongestPalindromicSubsequence.LPS("BABCBAB"), "BABCBAB");
22+
}
23+
24+
@Test
25+
void test4() {
26+
assertEquals(LongestPalindromicSubsequence.LPS("BBABCBCAB"), "BABCBAB");
27+
}
28+
29+
@Test
30+
void test5() {
31+
assertEquals(LongestPalindromicSubsequence.LPS("AAAAAAAAAAAAAAAAAAAAAAAA"), "AAAAAAAAAAAAAAAAAAAAAAAA");
32+
}
33+
}

0 commit comments

Comments
 (0)