!1154 [v6] 添加WordTree扁平化功能

Merge pull request !1154 from 阿超/v6-dev
This commit is contained in:
Looly
2024-01-15 09:24:22 +00:00
committed by Gitee
2 changed files with 50 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ import org.dromara.hutool.core.collection.ListUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
@@ -209,4 +211,14 @@ public class DfaTest {
strings = wordTree.matchAll("abab", -1, true, true);
Assertions.assertEquals("[ab, b, ab, b]", strings.toString());
}
@Test
void flattenTest() {
final WordTree wordTree = new WordTree();
final List<String> list = Arrays.asList("阿帕奇", "阿超", "HuTool", "HuTao");
wordTree.addWords(list);
final List<String> flattened = wordTree.flatten();
flattened.sort(Comparator.comparingInt(list::indexOf));
Assertions.assertEquals(list, flattened);
}
}