| 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: testAddAfterRemove | |
| 29 trie.add("foo") | |
| 30 trie.remove("foo") = true | |
| 31 trie.add("bar") | |
| 32 trie.has("foo") = false | |
| 33 trie.has("bar") = true | |
| 34 | |
| 35 test: testWordOverwrite | |
| 36 trie.add("foo") | |
| 37 trie.add("foo") | |
| 38 trie.remove("foo") = true | |
| 39 trie.has("foo") = false | |
| 40 | |
| 41 test: testRemoveNonExisting | |
| 42 trie.add("foo") | |
| 43 trie.remove("bar") = false | |
| 44 trie.remove("baz") = false | |
| 45 trie.has("foo") = true | |
| 46 | |
| 47 test: testEmptyWord | |
| 48 trie.add("") | |
| 49 trie.has("") = true | |
| 50 trie.remove("") = true | |
| 51 trie.has("") = false | |
| 52 | |
| 53 test: testAllWords | |
| 54 trie.add("foo") | |
| 55 trie.add("bar") | |
| 56 trie.add("bazzz") | |
| 57 trie.words() = [ | |
| 58 foo, | |
| 59 bar, | |
| 60 bazzz | |
| 61 ] | |
| 62 trie.words("f") = [ | |
| 63 foo | |
| 64 ] | |
| 65 trie.words("g") = [] | |
| 66 trie.words("b") = [ | |
| 67 bar, | |
| 68 bazzz | |
| 69 ] | |
| 70 trie.words("ba") = [ | |
| 71 bar, | |
| 72 bazzz | |
| 73 ] | |
| 74 trie.words("bar") = [ | |
| 75 bar | |
| 76 ] | |
| 77 trie.words("barz") = [] | |
| 78 trie.words("baz") = [ | |
| 79 bazzz | |
| 80 ] | |
| 81 | |
| 82 test: testOneCharWords | |
| 83 trie.add("a") | |
| 84 trie.add("b") | |
| 85 trie.add("c") | |
| 86 trie.words() = [ | |
| 87 a, | |
| 88 b, | |
| 89 c | |
| 90 ] | |
| 91 | |
| 92 test: testChainWords | |
| 93 trie.add("f") | |
| 94 trie.add("fo") | |
| 95 trie.add("foo") | |
| 96 trie.add("foo") | |
| 97 trie.words() = [ | |
| 98 f, | |
| 99 fo, | |
| 100 foo | |
| 101 ] | |
| 102 | |
| 103 test: testClearTrie | |
| 104 trie.add("foo") | |
| 105 trie.add("bar") | |
| 106 trie.words() = [ | |
| 107 foo, | |
| 108 bar | |
| 109 ] | |
| 110 trie.clear() | |
| 111 trie.words() = [] | |
| 112 | |
| 113 test: testLongestPrefix | |
| 114 trie.add("fo") | |
| 115 trie.add("food") | |
| 116 trie.longestPrefix("fear", false) = "f" | |
| 117 trie.longestPrefix("fear", true) = "" | |
| 118 trie.longestPrefix("football", false) = "foo" | |
| 119 trie.longestPrefix("football", true) = "fo" | |
| 120 trie.longestPrefix("bar", false) = "" | |
| 121 trie.longestPrefix("bar", true) = "" | |
| 122 trie.longestPrefix("foo", false) = "foo" | |
| 123 trie.longestPrefix("foo", true) = "fo" | |
| 124 | |
| OLD | NEW |