mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
单元测试由Junit4变更为Junit5
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
package cn.hutool.dfa;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
|
||||
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
|
||||
List<String> matchAll = tree.matchAll(text, -1, false, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class DfaTest {
|
||||
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
List<String> matchAll = tree.matchAll(text, -1, true, false);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅", "出锅"));
|
||||
assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅", "出锅"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于非密集匹配,因此从下一个字符开始查找,匹配到【土豆】接着被匹配
|
||||
// 由于【刚出锅】被匹配,由于非密集匹配,【出锅】被跳过
|
||||
List<String> matchAll = tree.matchAll(text, -1, false, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
assertEquals(matchAll, CollUtil.newArrayList("大", "土^豆", "刚出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class DfaTest {
|
||||
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
|
||||
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
|
||||
List<String> matchAll = tree.matchAll(text, -1, true, true);
|
||||
Assert.assertEquals(matchAll, CollUtil.newArrayList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
assertEquals(matchAll, CollUtil.newArrayList("大", "大土^豆", "土^豆", "刚出锅", "出锅"));
|
||||
|
||||
}
|
||||
|
||||
@@ -88,19 +88,19 @@ public class DfaTest {
|
||||
tree.addWord("赵阿三");
|
||||
|
||||
final List<FoundWord> result = tree.matchAllWords("赵阿三在做什么", -1, true, true);
|
||||
Assert.assertEquals(3, result.size());
|
||||
assertEquals(3, result.size());
|
||||
|
||||
Assert.assertEquals("赵", result.get(0).getWord());
|
||||
Assert.assertEquals(0, result.get(0).getStartIndex().intValue());
|
||||
Assert.assertEquals(0, result.get(0).getEndIndex().intValue());
|
||||
assertEquals("赵", result.get(0).getWord());
|
||||
assertEquals(0, result.get(0).getStartIndex().intValue());
|
||||
assertEquals(0, result.get(0).getEndIndex().intValue());
|
||||
|
||||
Assert.assertEquals("赵阿", result.get(1).getWord());
|
||||
Assert.assertEquals(0, result.get(1).getStartIndex().intValue());
|
||||
Assert.assertEquals(1, result.get(1).getEndIndex().intValue());
|
||||
assertEquals("赵阿", result.get(1).getWord());
|
||||
assertEquals(0, result.get(1).getStartIndex().intValue());
|
||||
assertEquals(1, result.get(1).getEndIndex().intValue());
|
||||
|
||||
Assert.assertEquals("赵阿三", result.get(2).getWord());
|
||||
Assert.assertEquals(0, result.get(2).getStartIndex().intValue());
|
||||
Assert.assertEquals(2, result.get(2).getEndIndex().intValue());
|
||||
assertEquals("赵阿三", result.get(2).getWord());
|
||||
assertEquals(0, result.get(2).getStartIndex().intValue());
|
||||
assertEquals(2, result.get(2).getEndIndex().intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +112,7 @@ public class DfaTest {
|
||||
tree.addWord("tio");
|
||||
|
||||
List<String> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
|
||||
Assert.assertEquals(all, CollUtil.newArrayList("t-io"));
|
||||
assertEquals(all, CollUtil.newArrayList("t-io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,31 +121,31 @@ public class DfaTest {
|
||||
tree.addWord("women");
|
||||
String text = "a WOMEN todo.".toLowerCase();
|
||||
List<String> matchAll = tree.matchAll(text, -1, false, false);
|
||||
Assert.assertEquals("[women]", matchAll.toString());
|
||||
assertEquals("[women]", matchAll.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clearTest(){
|
||||
WordTree tree = new WordTree();
|
||||
tree.addWord("黑");
|
||||
Assert.assertTrue(tree.matchAll("黑大衣").contains("黑"));
|
||||
assertTrue(tree.matchAll("黑大衣").contains("黑"));
|
||||
//clear时直接调用Map的clear并没有把endCharacterSet清理掉
|
||||
tree.clear();
|
||||
tree.addWords("黑大衣","红色大衣");
|
||||
|
||||
//clear() 覆写前 这里想匹配到黑大衣,但是却匹配到了黑
|
||||
// Assert.assertFalse(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
// Assert.assertTrue(tree.matchAll("黑大衣").contains("黑"));
|
||||
// assertFalse(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
// assertTrue(tree.matchAll("黑大衣").contains("黑"));
|
||||
//clear() 覆写后
|
||||
Assert.assertTrue(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
Assert.assertFalse(tree.matchAll("黑大衣").contains("黑"));
|
||||
Assert.assertTrue(tree.matchAll("红色大衣").contains("红色大衣"));
|
||||
assertTrue(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
assertFalse(tree.matchAll("黑大衣").contains("黑"));
|
||||
assertTrue(tree.matchAll("红色大衣").contains("红色大衣"));
|
||||
|
||||
//如果不覆写只能通过new出新对象才不会有问题
|
||||
tree = new WordTree();
|
||||
tree.addWords("黑大衣","红色大衣");
|
||||
Assert.assertTrue(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
Assert.assertTrue(tree.matchAll("红色大衣").contains("红色大衣"));
|
||||
assertTrue(tree.matchAll("黑大衣").contains("黑大衣"));
|
||||
assertTrue(tree.matchAll("红色大衣").contains("红色大衣"));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------------------
|
||||
|
@@ -2,8 +2,8 @@ package cn.hutool.dfa;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,7 +23,7 @@ public class SensitiveUtilTest {
|
||||
bean.setNum(100);
|
||||
SensitiveUtil.init(wordList);
|
||||
bean = SensitiveUtil.sensitiveFilter(bean, true, null);
|
||||
Assert.assertEquals(bean.getStr(), "我有一颗$****,***的");
|
||||
assertEquals(bean.getStr(), "我有一颗$****,***的");
|
||||
}
|
||||
|
||||
@Data
|
||||
@@ -37,6 +37,6 @@ public class SensitiveUtilTest {
|
||||
SensitiveUtil.init(ListUtil.of("赵", "赵阿", "赵阿三"));
|
||||
|
||||
String result = SensitiveUtil.sensitiveFilter("赵阿三在做什么。", true, null);
|
||||
Assert.assertEquals("***在做什么。", result);
|
||||
assertEquals("***在做什么。", result);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user