Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/inspector-unit/trie.html |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector-unit/trie.html b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/trie.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c0835c4c46fe42d08f10180642b32662262b699b |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector-unit/trie.html |
| @@ -0,0 +1,173 @@ |
| +<html> |
| +<head> |
| +<base href="/inspector-debug/"></base> |
| +<script src="/inspector-debug/Runtime.js"></script> |
| +<script src="/inspector-unit/inspector-unit-test.js"></script> |
| +<script> |
| +function test() { |
| + var trie; |
| + |
| + UnitTest.addResult("\nTest add:"); |
|
dgozman
2016/10/03 20:32:57
Useless one.
lushnikov
2016/10/03 22:56:22
Done.
|
| + |
| + UnitTest.runTests([ |
| + function testAddWord() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "hello"); |
| + hasWord(trie, "he"); |
| + hasWord(trie, "hello"); |
| + hasWord(trie, "helloo"); |
| + }, |
| + |
| + function testAddWords() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + addWord(trie, "bar"); |
| + addWord(trie, "bazz"); |
| + hasWord(trie, "f"); |
| + hasWord(trie, "ba"); |
| + hasWord(trie, "baz"); |
| + hasWord(trie, "bar"); |
| + hasWord(trie, "bazz"); |
| + }, |
| + |
| + function testRemoveWord() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + removeWord(trie, "f"); |
| + removeWord(trie, "fo"); |
| + removeWord(trie, "fooo"); |
| + hasWord(trie, "foo"); |
| + removeWord(trie, "foo"); |
| + hasWord(trie, "foo"); |
| + }, |
| + |
| + function testWordOverwrite() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + addWord(trie, "foo"); |
| + removeWord(trie, "foo"); |
| + hasWord(trie, "foo"); |
| + }, |
| + |
| + function testRemoveNonExisting() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + removeWord(trie, "bar"); |
| + removeWord(trie, "baz"); |
| + hasWord(trie, "foo"); |
| + }, |
| + |
| + function testEmptyWord() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, ""); |
| + hasWord(trie, ""); |
| + removeWord(trie, ""); |
| + hasWord(trie, ""); |
| + }, |
| + |
| + function testAllWords() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + addWord(trie, "bar"); |
| + addWord(trie, "bazzz"); |
| + words(trie); |
| + words(trie, "f"); |
| + words(trie, "g"); |
| + words(trie, "b"); |
| + words(trie, "ba"); |
| + words(trie, "bar"); |
| + words(trie, "barz"); |
| + words(trie, "baz"); |
| + }, |
| + |
| + function testOneCharWords() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "a"); |
| + addWord(trie, "b"); |
| + addWord(trie, "c"); |
| + words(trie); |
| + }, |
| + |
| + function testChainWords() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "f"); |
| + addWord(trie, "fo"); |
| + addWord(trie, "foo"); |
| + addWord(trie, "foo"); |
| + words(trie); |
| + }, |
| + |
| + function testClearTrie() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "foo"); |
| + addWord(trie, "bar"); |
| + words(trie); |
| + clear(trie); |
| + words(trie); |
| + }, |
| + |
| + function testLongestPrefix() |
| + { |
| + var trie = new Trie(); |
| + addWord(trie, "fo"); |
| + addWord(trie, "food"); |
| + longestPrefix(trie, "fear", false); |
| + longestPrefix(trie, "fear", true); |
| + longestPrefix(trie, "football", false); |
| + longestPrefix(trie, "football", true); |
| + longestPrefix(trie, "bar", false); |
| + longestPrefix(trie, "bar", true); |
| + }, |
| + ]); |
| + |
| + function hasWord(trie, word) |
| + { |
| + UnitTest.addResult(`trie.has("${word}") = ${trie.has(word)}`); |
| + } |
| + |
| + function addWord(trie, word) |
| + { |
| + UnitTest.addResult(`trie.add("${word}")`); |
| + trie.add(word); |
| + } |
| + |
| + function removeWord(trie, word) |
| + { |
| + UnitTest.addResult(`trie.remove("${word}") = ${trie.remove(word)}`); |
| + } |
| + |
| + function words(trie, prefix) |
| + { |
| + var title = prefix ? `trie.words("${prefix}")` : `trie.words()`; |
| + var words = trie.words(prefix); |
| + var text = words.length ? `[\n ${words.join(",\n ")}\n]` : "[]"; |
| + UnitTest.addResult(title + " = " + text); |
| + } |
| + |
| + function clear(trie) |
| + { |
| + trie.clear(); |
| + UnitTest.addResult("trie.clear()"); |
| + } |
| + |
| + function longestPrefix(trie, word, fullWordOnly) |
| + { |
| + UnitTest.addResult(`trie.longestPrefix("${word}", ${fullWordOnly}) = "${trie.longestPrefix(word, fullWordOnly)}"`); |
| + } |
| +} |
| +</script> |
| +</head> |
| +<body> |
| +Verify "trie" functionality. |
| +</body> |
| +</html> |