OLD | NEW |
(Empty) | |
| 1 Verify "trie" functionality. |
| 2 |
| 3 test: testAddWord |
| 4 trie.add("hello") |
| 5 trie.has("he") = false |
| 6 trie.has("hello") = true |
| 7 trie.has("helloo") = false |
| 8 |
| 9 test: testAddWords |
| 10 trie.add("foo") |
| 11 trie.add("bar") |
| 12 trie.add("bazz") |
| 13 trie.has("f") = false |
| 14 trie.has("ba") = false |
| 15 trie.has("baz") = false |
| 16 trie.has("bar") = true |
| 17 trie.has("bazz") = true |
| 18 |
| 19 test: testRemoveWord |
| 20 trie.add("foo") |
| 21 trie.remove("f") = false |
| 22 trie.remove("fo") = false |
| 23 trie.remove("fooo") = false |
| 24 trie.has("foo") = true |
| 25 trie.remove("foo") = true |
| 26 trie.has("foo") = false |
| 27 |
| 28 test: testWordOverwrite |
| 29 trie.add("foo") |
| 30 trie.add("foo") |
| 31 trie.remove("foo") = true |
| 32 trie.has("foo") = false |
| 33 |
| 34 test: testRemoveNonExisting |
| 35 trie.add("foo") |
| 36 trie.remove("bar") = false |
| 37 trie.remove("baz") = false |
| 38 trie.has("foo") = true |
| 39 |
| 40 test: testEmptyWord |
| 41 trie.add("") |
| 42 trie.has("") = true |
| 43 trie.remove("") = true |
| 44 trie.has("") = false |
| 45 |
| 46 test: testAllWords |
| 47 trie.add("foo") |
| 48 trie.add("bar") |
| 49 trie.add("bazzz") |
| 50 trie.words() = [ |
| 51 foo, |
| 52 bar, |
| 53 bazzz |
| 54 ] |
| 55 trie.words("f") = [ |
| 56 foo |
| 57 ] |
| 58 trie.words("g") = [] |
| 59 trie.words("b") = [ |
| 60 bar, |
| 61 bazzz |
| 62 ] |
| 63 trie.words("ba") = [ |
| 64 bar, |
| 65 bazzz |
| 66 ] |
| 67 trie.words("bar") = [ |
| 68 bar |
| 69 ] |
| 70 trie.words("barz") = [] |
| 71 trie.words("baz") = [ |
| 72 bazzz |
| 73 ] |
| 74 |
| 75 test: testOneCharWords |
| 76 trie.add("a") |
| 77 trie.add("b") |
| 78 trie.add("c") |
| 79 trie.words() = [ |
| 80 a, |
| 81 b, |
| 82 c |
| 83 ] |
| 84 |
| 85 test: testChainWords |
| 86 trie.add("f") |
| 87 trie.add("fo") |
| 88 trie.add("foo") |
| 89 trie.add("foo") |
| 90 trie.words() = [ |
| 91 f, |
| 92 fo, |
| 93 foo |
| 94 ] |
| 95 |
| 96 test: testClearTrie |
| 97 trie.add("foo") |
| 98 trie.add("bar") |
| 99 trie.words() = [ |
| 100 foo, |
| 101 bar |
| 102 ] |
| 103 trie.clear() |
| 104 trie.words() = [] |
| 105 |
| 106 test: testLongestPrefix |
| 107 trie.add("fo") |
| 108 trie.add("food") |
| 109 trie.longestPrefix("fear", false) = "f" |
| 110 trie.longestPrefix("fear", true) = "" |
| 111 trie.longestPrefix("football", false) = "foo" |
| 112 trie.longestPrefix("football", true) = "fo" |
| 113 trie.longestPrefix("bar", false) = "" |
| 114 trie.longestPrefix("bar", true) = "" |
| 115 |
OLD | NEW |