added tests

This commit is contained in:
mmessmer 2020-10-10 18:07:03 +02:00
parent 9bcb7f5f0b
commit 60c0291e6a
2 changed files with 36 additions and 5 deletions

View File

@ -1,10 +1,9 @@
package DynamicProgramming;
package test;
import java.lang.*;
import java.io.*;
import java.util.*;
/**
* @author Matteo Messmer https://github.com/matteomessmer
* Algorithm explanation https://www.educative.io/edpresso/longest-palindromic-subsequence-algorithm
*/
public class LongestPalindromicSubsequence {
@ -19,9 +18,8 @@ public class LongestPalindromicSubsequence {
System.out.println(b + " => " + bLPS);
}
private static String LPS(String original) {
StringBuilder reverse = new StringBuilder();
reverse.append(original);
public static String LPS(String original) throws IllegalArgumentException {
StringBuilder reverse = new StringBuilder(original);
reverse = reverse.reverse();
return recursiveLPS(original, reverse.toString());
}

View File

@ -0,0 +1,33 @@
package test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class LongestPalindromicSubsequenceTests {
@Test
void test1() {
assertEquals(LongestPalindromicSubsequence.LPS(""), "");
}
@Test
void test2() {
assertEquals(LongestPalindromicSubsequence.LPS("A"), "A");
}
@Test
void test3() {
assertEquals(LongestPalindromicSubsequence.LPS("BABCBAB"), "BABCBAB");
}
@Test
void test4() {
assertEquals(LongestPalindromicSubsequence.LPS("BBABCBCAB"), "BABCBAB");
}
@Test
void test5() {
assertEquals(LongestPalindromicSubsequence.LPS("AAAAAAAAAAAAAAAAAAAAAAAA"), "AAAAAAAAAAAAAAAAAAAAAAAA");
}
}