added tests
This commit is contained in:
parent
9bcb7f5f0b
commit
60c0291e6a
@ -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());
|
||||
}
|
||||
|
33
DynamicProgramming/LongestPalindromicSubsequenceTests.java
Normal file
33
DynamicProgramming/LongestPalindromicSubsequenceTests.java
Normal 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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user