mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
package cn.hutool.core.lang;
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.text.TextSimilarity;
|
||||
|
||||
/**
|
||||
* 文本相似度计算工具类单元测试
|
||||
* @author looly
|
||||
@@ -21,6 +19,12 @@ public class TextSimilarityTest {
|
||||
Assert.assertEquals(0.8571428571428571D, degree, 16);
|
||||
|
||||
String similarPercent = TextSimilarity.similar(a, b, 2);
|
||||
Assert.assertEquals("85.71%", similarPercent);
|
||||
Assert.assertEquals("84.62%", similarPercent);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void similarTest(){
|
||||
final double abd = TextSimilarity.similar("abd", "1111");
|
||||
Assert.assertEquals(0, abd, 1);
|
||||
}
|
||||
}
|
@@ -1,15 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.lang.func.Func1;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ReUtilTest {
|
||||
final String content = "ZZZaaabbbccc中文1234";
|
||||
@@ -52,7 +49,7 @@ public class ReUtilTest {
|
||||
@Test
|
||||
public void findAllTest() {
|
||||
// 查找所有匹配文本
|
||||
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<String>());
|
||||
List<String> resultFindAll = ReUtil.findAll("\\w{2}", content, 0, new ArrayList<>());
|
||||
ArrayList<String> expected = CollectionUtil.newArrayList("ZZ", "Za", "aa", "bb", "bc", "cc", "12", "34");
|
||||
Assert.assertEquals(expected, resultFindAll);
|
||||
}
|
||||
@@ -82,13 +79,7 @@ public class ReUtilTest {
|
||||
@Test
|
||||
public void replaceAllTest2() {
|
||||
//此处把1234替换为 ->1234<-
|
||||
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", new Func1<Matcher, String>() {
|
||||
|
||||
@Override
|
||||
public String call(Matcher parameters) {
|
||||
return "->" + parameters.group(1) + "<-";
|
||||
}
|
||||
});
|
||||
String replaceAll = ReUtil.replaceAll(this.content, "(\\d+)", parameters -> "->" + parameters.group(1) + "<-");
|
||||
Assert.assertEquals("ZZZaaabbbccc中文->1234<-", replaceAll);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user