测试用例错误解决

This commit is contained in:
haibinxiao
2020-12-06 22:00:12 +08:00
parent f7c640934d
commit f5c53a8f60

View File

@@ -7,6 +7,7 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.List;
import java.util.stream.Collectors;
/**
* DFA单元测试
@@ -29,7 +30,7 @@ public class DfaTest {
// 匹配到【大】,就不再继续匹配了,因此【大土豆】不匹配
// 匹配到【刚出锅】,就跳过这三个字了,因此【出锅】不匹配(由于刚首先被匹配,因此长的被匹配,最短匹配只针对第一个字相同选最短)
List<FoundWord> matchAll = tree.matchAll(text, -1, false, false);
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()), CollectionUtil.newArrayList("", "土^豆", "刚出锅"));
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()), CollectionUtil.newArrayList("", "土^豆", "刚出锅"));
}
/**
@@ -45,7 +46,7 @@ public class DfaTest {
// 【大】被匹配,最短匹配原则【大土豆】被跳过,【土豆继续被匹配】
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
List<FoundWord> matchAll = tree.matchAll(text, -1, true, false);
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()), CollectionUtil.newArrayList("", "土^豆", "刚出锅", "出锅"));
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()), CollectionUtil.newArrayList("", "土^豆", "刚出锅", "出锅"));
}
/**
@@ -61,7 +62,7 @@ public class DfaTest {
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配
// 由于【大土豆】被匹配,【土豆】被跳过,由于【刚出锅】被匹配,【出锅】被跳过
List<FoundWord> matchAll = tree.matchAll(text, -1, false, true);
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()), CollectionUtil.newArrayList("", "大土^豆", "刚出锅"));
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()), CollectionUtil.newArrayList("", "大土^豆", "刚出锅"));
}
@@ -78,7 +79,7 @@ public class DfaTest {
// 匹配到【大】,由于到最长匹配,因此【大土豆】接着被匹配,由于不跳过已经匹配的关键词,土豆继续被匹配
// 【刚出锅】被匹配,由于不跳过已经匹配的词,【出锅】被匹配
List<FoundWord> matchAll = tree.matchAll(text, -1, true, true);
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()), CollectionUtil.newArrayList("", "大土^豆", "土^豆", "刚出锅", "出锅"));
Assert.assertEquals(matchAll.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()), CollectionUtil.newArrayList("", "大土^豆", "土^豆", "刚出锅", "出锅"));
}
@@ -91,7 +92,7 @@ public class DfaTest {
tree.addWord("tio");
List<FoundWord> all = tree.matchAll("AAAAAAAt-ioBBBBBBB");
Assert.assertEquals(all.stream().map(fw -> fw.getFoundWord()), CollectionUtil.newArrayList("t-io"));
Assert.assertEquals(all.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()), CollectionUtil.newArrayList("t-io"));
}
@Test
@@ -100,7 +101,7 @@ public class DfaTest {
tree.addWord("women");
String text = "a WOMEN todo.".toLowerCase();
List<FoundWord> matchAll = tree.matchAll(text, -1, false, false);
Assert.assertEquals("[women]", matchAll.stream().map(fw -> fw.getFoundWord()).toString());
Assert.assertEquals("[women]", matchAll.stream().map(fw -> fw.getFoundWord()).collect(Collectors.toList()).toString());
}
// ----------------------------------------------------------------------------------------------------------