测试用例错误解决

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());
}
// ----------------------------------------------------------------------------------------------------------