@@ -11,6 +11,128 @@ CTOptimizedTrieTest >> classUnderTest [
1111 ^ CTOptimizedTrie
1212]
1313
14+ { #category : ' tests' }
15+ CTOptimizedTrieTest >> testCompressNodeDoesNotMergeWhenAncestorsTooSmall [
16+ | rootNode nodeToCheck ancestors |
17+ trie := CTOptimizedTrie new .
18+
19+ trie at: ' cat' put: 1 .
20+
21+ rootNode := trie instVarNamed: ' root' .
22+ nodeToCheck := rootNode children first.
23+
24+ ancestors := OrderedCollection new .
25+ ancestors add: nodeToCheck.
26+
27+ trie compressNode: nodeToCheck ancestors: ancestors.
28+
29+ self assert: rootNode keys size equals: 1 .
30+ self assert: rootNode keys first equals: ' cat' .
31+ self assert: (trie at: ' cat' ) equals: 1 .
32+ ]
33+
34+ { #category : ' tests' }
35+ CTOptimizedTrieTest >> testCompressNodeDoesNotMergeWhenHasValue [
36+ | rootNode nodeToCheck ancestors |
37+ trie := CTOptimizedTrie new .
38+
39+ trie at: ' cat' put: 1 .
40+ trie at: ' ca' put: 2 .
41+
42+ rootNode := trie instVarNamed: ' root' .
43+ nodeToCheck := rootNode children first.
44+
45+ ancestors := OrderedCollection new .
46+ ancestors add: rootNode.
47+ ancestors add: nodeToCheck.
48+
49+ trie compressNode: nodeToCheck ancestors: ancestors.
50+
51+ self assert: rootNode keys size equals: 1 .
52+ self assert: rootNode keys first equals: ' ca' .
53+ self assert: (trie at: ' ca' ) equals: 2 .
54+ ]
55+
56+ { #category : ' tests' }
57+ CTOptimizedTrieTest >> testCompressNodeDoesNotMergeWithMultipleChildren [
58+ | rootNode nodeToCheck ancestors |
59+ trie := CTOptimizedTrie new .
60+
61+ trie at: ' cat' put: 1 .
62+ trie at: ' car' put: 2 .
63+
64+ rootNode := trie instVarNamed: ' root' .
65+ nodeToCheck := rootNode children first.
66+
67+ nodeToCheck instVarNamed: ' nodeValue' put: nil .
68+
69+ ancestors := OrderedCollection new .
70+ ancestors add: rootNode.
71+ ancestors add: nodeToCheck.
72+
73+ trie compressNode: nodeToCheck ancestors: ancestors.
74+
75+ self assert: rootNode keys size equals: 1 .
76+ self assert: rootNode keys first equals: ' ca' .
77+ self assert: nodeToCheck keys size equals: 2 .
78+ self assert: (nodeToCheck keys includesAll: #('t' 'r') ).
79+ self assert: (trie at: ' cat' ) equals: 1 .
80+ self assert: (trie at: ' car' ) equals: 2 .
81+ ]
82+
83+ { #category : ' tests' }
84+ CTOptimizedTrieTest >> testCompressNodeMergesDeepSingleChild [
85+ | rootNode parentNode nodeToCheck ancestors |
86+ trie := CTOptimizedTrie new .
87+
88+ trie at: ' a' put: 1 .
89+ trie at: ' ab' put: 2 .
90+ trie at: ' abc' put: 3 .
91+
92+ rootNode := trie instVarNamed: ' root' .
93+ parentNode := rootNode children first.
94+ nodeToCheck := parentNode children first.
95+
96+ nodeToCheck instVarNamed: ' nodeValue' put: nil .
97+
98+ ancestors := OrderedCollection new .
99+ ancestors add: rootNode.
100+ ancestors add: parentNode.
101+ ancestors add: nodeToCheck.
102+
103+ trie compressNode: nodeToCheck ancestors: ancestors.
104+
105+ self assert: parentNode keys size equals: 1 .
106+ self assert: parentNode keys first equals: ' bc' .
107+
108+ self assert: (trie at: ' abc' ) equals: 3 .
109+ self assert: (trie at: ' a' ) equals: 1 .
110+ ]
111+
112+ { #category : ' tests' }
113+ CTOptimizedTrieTest >> testCompressNodeMergesSingleChildWithoutValue [
114+ | rootNode nodeToCheck ancestors |
115+ trie := CTOptimizedTrie new .
116+
117+ trie at: ' cat' put: 1 .
118+ trie at: ' ca' put: 2 .
119+
120+ rootNode := trie instVarNamed: ' root' .
121+ nodeToCheck := rootNode children first.
122+
123+ nodeToCheck instVarNamed: ' nodeValue' put: nil .
124+
125+ ancestors := OrderedCollection new .
126+ ancestors add: rootNode.
127+ ancestors add: nodeToCheck.
128+
129+ trie compressNode: nodeToCheck ancestors: ancestors.
130+
131+ self assert: rootNode keys size equals: 1 .
132+ self assert: rootNode keys first equals: ' cat' .
133+ self assert: (trie at: ' cat' ) equals: 1 .
134+ ]
135+
14136{ #category : ' tests' }
15137CTOptimizedTrieTest >> testOptimizedTrieCompressesOnDeletion [
16138 | trie rootNode |
0 commit comments