软件测试——StringFunction测试
Posted Starzkg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试——StringFunction测试相关的知识,希望对你有一定的参考价值。
源代码:https://gitee.com/shentuzhigang/mini-project/tree/master/test-string-function
测试代码
package io.shentuzhigang.test.stringfunction;
import org.junit.Test;
import static org.junit.Assert.*;
public class StringFunctionTest {
@Test(timeout = 4000)
public void test() {
// 判断是不是回文字符串
boolean b1 = StringFunction.isPalindromeInPlace("abc");
assertFalse(b1);
boolean b2 = StringFunction.isPalindromeInPlace("aba");
assertTrue(b2);
// 获取子字符串集合
String[] strings = StringFunction.generateSubsets("12");
assertArrayEquals(new String[]{"", "2", "1", "21" }, strings);
// 莱文斯坦距离
int i = StringFunction.levenshteinDistanceIterative("abc", "a");
assertEquals(2, i);
int j = StringFunction.levenshteinDistanceRecursive("abc", "a");
assertEquals(2, j);
// 翻转字符串
String s0 = StringFunction.reverseWordsInPlace("");
assertEquals("", s0);
String s1 = StringFunction.reverseWordsInPlace("abc123");
assertEquals("abc123", s1);
String s2 = StringFunction.reverseWordsInPlace("abc 1234");
assertEquals("1234 abc", s2);
String s3 = StringFunction.reverseWordsInPlace("abcd 123 efg");
assertEquals("efg 123 abcd", s3);
// 翻转字符串
String s4 = StringFunction.reverseWordsByCharWithAdditionalStorage("abcd 123");
assertEquals("123 abcd", s4);
String s5 = StringFunction.reverseWordsByCharWithAdditionalStorage("abcd 123 efg");
assertEquals("efg 123 abcd", s5);
}
/**
* 获取最长回文子序列
*/
@Test(timeout = 4000)
public void test1() {
Manacher.getLongestPalindromicSubstring(null);
Manacher.getLongestPalindromicSubstring("");
Manacher.getLongestPalindromicSubstring("abc123");
Manacher.getLongestPalindromicSubstring("abc 123");
Manacher.getLongestPalindromicSubstring("abc1234");
Manacher.getLongestPalindromicSubstring("aba1221");
}
}
测试结果
参考文章
以上是关于软件测试——StringFunction测试的主要内容,如果未能解决你的问题,请参考以下文章