blob: 39e8db96aa0300ff844c342a4c7b09e9ebd63ddb [file] [log] [blame]
Verify "trie" functionality.
test: testAddWord
trie.add("hello")
trie.has("he") = false
trie.has("hello") = true
trie.has("helloo") = false
test: testAddWords
trie.add("foo")
trie.add("bar")
trie.add("bazz")
trie.has("f") = false
trie.has("ba") = false
trie.has("baz") = false
trie.has("bar") = true
trie.has("bazz") = true
test: testRemoveWord
trie.add("foo")
trie.remove("f") = false
trie.remove("fo") = false
trie.remove("fooo") = false
trie.has("foo") = true
trie.remove("foo") = true
trie.has("foo") = false
test: testAddAfterRemove
trie.add("foo")
trie.remove("foo") = true
trie.add("bar")
trie.has("foo") = false
trie.has("bar") = true
test: testWordOverwrite
trie.add("foo")
trie.add("foo")
trie.remove("foo") = true
trie.has("foo") = false
test: testRemoveNonExisting
trie.add("foo")
trie.remove("bar") = false
trie.remove("baz") = false
trie.has("foo") = true
test: testEmptyWord
trie.add("")
trie.has("") = true
trie.remove("") = true
trie.has("") = false
test: testAllWords
trie.add("foo")
trie.add("bar")
trie.add("bazzz")
trie.words() = [
foo,
bar,
bazzz
]
trie.words("f") = [
foo
]
trie.words("g") = []
trie.words("b") = [
bar,
bazzz
]
trie.words("ba") = [
bar,
bazzz
]
trie.words("bar") = [
bar
]
trie.words("barz") = []
trie.words("baz") = [
bazzz
]
test: testOneCharWords
trie.add("a")
trie.add("b")
trie.add("c")
trie.words() = [
a,
b,
c
]
test: testChainWords
trie.add("f")
trie.add("fo")
trie.add("foo")
trie.add("foo")
trie.words() = [
f,
fo,
foo
]
test: testClearTrie
trie.add("foo")
trie.add("bar")
trie.words() = [
foo,
bar
]
trie.clear()
trie.words() = []
test: testLongestPrefix
trie.add("fo")
trie.add("food")
trie.longestPrefix("fear", false) = "f"
trie.longestPrefix("fear", true) = ""
trie.longestPrefix("football", false) = "foo"
trie.longestPrefix("football", true) = "fo"
trie.longestPrefix("bar", false) = ""
trie.longestPrefix("bar", true) = ""
trie.longestPrefix("foo", false) = "foo"
trie.longestPrefix("foo", true) = "fo"