rambling-trie 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/Gemfile +1 -5
- data/LICENSE +3 -1
- data/README.markdown +19 -8
- data/lib/rambling/trie.rb +4 -3
- data/lib/rambling/trie/branches.rb +24 -29
- data/lib/rambling/trie/compressor.rb +9 -5
- data/lib/rambling/trie/enumerable.rb +1 -1
- data/lib/rambling/trie/inspector.rb +1 -1
- data/lib/rambling/trie/node.rb +26 -11
- data/lib/rambling/trie/root.rb +28 -14
- data/lib/rambling/trie/tasks/performance.rb +4 -29
- data/lib/rambling/trie/version.rb +1 -1
- data/spec/lib/rambling/trie/node_spec.rb +82 -47
- data/spec/lib/rambling/trie/root_spec.rb +121 -97
- data/spec/spec_helper.rb +2 -0
- metadata +17 -38
- data/lib/rambling/trie/children_hash_deferer.rb +0 -35
- data/spec/lib/rambling/trie/children_hash_deferer_spec.rb +0 -59
@@ -3,170 +3,205 @@ require 'spec_helper'
|
|
3
3
|
module Rambling
|
4
4
|
module Trie
|
5
5
|
describe Node do
|
6
|
+
it 'delegates `#[]` to its children tree' do
|
7
|
+
subject.children_tree.should_receive(:[]).with(:key).and_return('value')
|
8
|
+
expect(subject[:key]).to eq 'value'
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'delegates `#[]=` to its children tree' do
|
12
|
+
subject.children_tree.should_receive(:[]=).with(:key, 'value')
|
13
|
+
subject[:key] = 'value'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'delegates `#delete` to its children tree' do
|
17
|
+
subject.children_tree.should_receive(:delete).with(:key).and_return('value')
|
18
|
+
expect(subject.delete :key).to eq 'value'
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'delegates `#has_key?` to its children tree' do
|
22
|
+
subject.children_tree.should_receive(:has_key?).with(:present_key).and_return(true)
|
23
|
+
expect(subject).to have_key(:present_key)
|
24
|
+
|
25
|
+
subject.children_tree.should_receive(:has_key?).with(:absent_key).and_return(false)
|
26
|
+
expect(subject).not_to have_key(:absent_key)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'delegates `#children` to its children tree values' do
|
30
|
+
children = [double('child 1'), double('child 2')]
|
31
|
+
subject.children_tree.should_receive(:values).and_return(children)
|
32
|
+
expect(subject.children).to eq children
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#root?' do
|
36
|
+
it 'returns false' do
|
37
|
+
expect(subject).to_not be_root
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
6
41
|
describe '.new' do
|
7
42
|
context 'with no word' do
|
8
|
-
|
43
|
+
subject { Node.new }
|
9
44
|
|
10
45
|
it 'does not have any letter' do
|
11
|
-
expect(
|
46
|
+
expect(subject.letter).to be_nil
|
12
47
|
end
|
13
48
|
|
14
49
|
it 'includes no children' do
|
15
|
-
expect(
|
50
|
+
expect(subject).to have(0).children
|
16
51
|
end
|
17
52
|
|
18
53
|
it 'is not a terminal node' do
|
19
|
-
expect(
|
54
|
+
expect(subject).to_not be_terminal
|
20
55
|
end
|
21
56
|
|
22
57
|
it 'returns empty string as its word' do
|
23
|
-
expect(
|
58
|
+
expect(subject.as_word).to be_empty
|
24
59
|
end
|
25
60
|
|
26
61
|
it 'is not compressed' do
|
27
|
-
expect(
|
62
|
+
expect(subject).to_not be_compressed
|
28
63
|
end
|
29
64
|
end
|
30
65
|
|
31
66
|
context 'with an empty word' do
|
32
|
-
|
67
|
+
subject { Node.new '' }
|
33
68
|
|
34
69
|
it 'does not have any letter' do
|
35
|
-
expect(
|
70
|
+
expect(subject.letter).to be_nil
|
36
71
|
end
|
37
72
|
|
38
73
|
it 'includes no children' do
|
39
|
-
expect(
|
74
|
+
expect(subject).to have(0).children
|
40
75
|
end
|
41
76
|
|
42
77
|
it 'is not a terminal node' do
|
43
|
-
expect(
|
78
|
+
expect(subject).to_not be_terminal
|
44
79
|
end
|
45
80
|
|
46
81
|
it 'returns empty string as its word' do
|
47
|
-
expect(
|
82
|
+
expect(subject.as_word).to be_empty
|
48
83
|
end
|
49
84
|
|
50
85
|
it 'is not compressed' do
|
51
|
-
expect(
|
86
|
+
expect(subject).to_not be_compressed
|
52
87
|
end
|
53
88
|
end
|
54
89
|
|
55
90
|
context 'with one letter' do
|
56
|
-
|
91
|
+
subject { Node.new 'a' }
|
57
92
|
|
58
93
|
it 'makes it the node letter' do
|
59
|
-
expect(
|
94
|
+
expect(subject.letter).to eq :a
|
60
95
|
end
|
61
96
|
|
62
97
|
it 'includes no children' do
|
63
|
-
expect(
|
98
|
+
expect(subject).to have(0).children
|
64
99
|
end
|
65
100
|
|
66
101
|
it 'is a terminal node' do
|
67
|
-
expect(
|
102
|
+
expect(subject).to be_terminal
|
68
103
|
end
|
69
104
|
end
|
70
105
|
|
71
106
|
context 'with two letters' do
|
72
|
-
|
107
|
+
subject { Node.new 'ba' }
|
73
108
|
|
74
109
|
it 'takes the first as the node letter' do
|
75
|
-
expect(
|
110
|
+
expect(subject.letter).to eq :b
|
76
111
|
end
|
77
112
|
|
78
113
|
it 'includes one child' do
|
79
|
-
expect(
|
114
|
+
expect(subject).to have(1).children
|
80
115
|
end
|
81
116
|
|
82
117
|
it 'includes a child with the expected letter' do
|
83
|
-
expect(
|
118
|
+
expect(subject.children.first.letter).to eq :a
|
84
119
|
end
|
85
120
|
|
86
121
|
it 'has the expected letter as a key' do
|
87
|
-
expect(
|
122
|
+
expect(subject).to have_key(:a)
|
88
123
|
end
|
89
124
|
|
90
125
|
it 'returns the child corresponding to the key' do
|
91
|
-
expect(
|
126
|
+
expect(subject[:a]).to eq subject.children_tree[:a]
|
92
127
|
end
|
93
128
|
|
94
129
|
it 'does not mark itself as a terminal node' do
|
95
|
-
expect(
|
130
|
+
expect(subject).to_not be_terminal
|
96
131
|
end
|
97
132
|
|
98
133
|
it 'marks the first child as a terminal node' do
|
99
|
-
expect(
|
134
|
+
expect(subject[:a]).to be_terminal
|
100
135
|
end
|
101
136
|
end
|
102
137
|
|
103
138
|
context 'with a large word' do
|
104
|
-
|
139
|
+
subject { Node.new 'spaghetti' }
|
105
140
|
|
106
141
|
it 'marks the last letter as terminal node' do
|
107
|
-
expect(
|
142
|
+
expect(subject[:p][:a][:g][:h][:e][:t][:t][:i]).to be_terminal
|
108
143
|
end
|
109
144
|
|
110
145
|
it 'does not mark any other letter as terminal node' do
|
111
|
-
expect(
|
112
|
-
expect(
|
113
|
-
expect(
|
114
|
-
expect(
|
115
|
-
expect(
|
116
|
-
expect(
|
117
|
-
expect(
|
146
|
+
expect(subject[:p][:a][:g][:h][:e][:t][:t]).to_not be_terminal
|
147
|
+
expect(subject[:p][:a][:g][:h][:e][:t]).to_not be_terminal
|
148
|
+
expect(subject[:p][:a][:g][:h][:e]).to_not be_terminal
|
149
|
+
expect(subject[:p][:a][:g][:h]).to_not be_terminal
|
150
|
+
expect(subject[:p][:a][:g]).to_not be_terminal
|
151
|
+
expect(subject[:p][:a]).to_not be_terminal
|
152
|
+
expect(subject[:p]).to_not be_terminal
|
118
153
|
end
|
119
154
|
end
|
120
155
|
end
|
121
156
|
|
122
157
|
describe '#as_word' do
|
123
158
|
context 'for an empty node' do
|
124
|
-
|
159
|
+
subject { Node.new '' }
|
125
160
|
|
126
161
|
it 'returns nil' do
|
127
|
-
expect(
|
162
|
+
expect(subject.as_word).to be_empty
|
128
163
|
end
|
129
164
|
end
|
130
165
|
|
131
166
|
context 'for one letter' do
|
132
|
-
|
167
|
+
subject { Node.new 'a' }
|
133
168
|
|
134
169
|
it 'returns the expected one letter word' do
|
135
|
-
expect(
|
170
|
+
expect(subject.as_word).to eq 'a'
|
136
171
|
end
|
137
172
|
end
|
138
173
|
|
139
174
|
context 'for a small word' do
|
140
|
-
|
175
|
+
subject { Node.new 'all' }
|
141
176
|
|
142
177
|
it 'returns the expected small word' do
|
143
|
-
expect(
|
178
|
+
expect(subject[:l][:l].as_word).to eq 'all'
|
144
179
|
end
|
145
180
|
|
146
181
|
it 'raises an error for a non terminal node' do
|
147
|
-
expect {
|
182
|
+
expect { subject[:l].as_word }.to raise_error InvalidOperation
|
148
183
|
end
|
149
184
|
end
|
150
185
|
|
151
186
|
context 'for a long word' do
|
152
|
-
|
187
|
+
subject { Node.new 'beautiful' }
|
153
188
|
|
154
189
|
it 'returns the expected long word' do
|
155
|
-
expect(
|
190
|
+
expect(subject[:e][:a][:u][:t][:i][:f][:u][:l].as_word).to eq 'beautiful'
|
156
191
|
end
|
157
192
|
end
|
158
193
|
|
159
194
|
context 'for a node with nil letter' do
|
160
|
-
|
195
|
+
subject { Node.new nil }
|
161
196
|
it 'returns nil' do
|
162
|
-
expect(
|
197
|
+
expect(subject.as_word).to be_empty
|
163
198
|
end
|
164
199
|
end
|
165
200
|
end
|
166
201
|
|
167
202
|
describe '#compressed?' do
|
168
203
|
let(:root) { double 'Root' }
|
169
|
-
|
204
|
+
subject { Node.new '', root }
|
170
205
|
|
171
206
|
context 'parent is compressed' do
|
172
207
|
before do
|
@@ -174,7 +209,7 @@ module Rambling
|
|
174
209
|
end
|
175
210
|
|
176
211
|
it 'returns true' do
|
177
|
-
expect(
|
212
|
+
expect(subject).to be_compressed
|
178
213
|
end
|
179
214
|
end
|
180
215
|
|
@@ -184,7 +219,7 @@ module Rambling
|
|
184
219
|
end
|
185
220
|
|
186
221
|
it 'returns false' do
|
187
|
-
expect(
|
222
|
+
expect(subject).to_not be_compressed
|
188
223
|
end
|
189
224
|
end
|
190
225
|
end
|
@@ -3,52 +3,56 @@ require 'spec_helper'
|
|
3
3
|
module Rambling
|
4
4
|
module Trie
|
5
5
|
describe Root do
|
6
|
-
|
6
|
+
describe '#root?' do
|
7
|
+
it 'returns true' do
|
8
|
+
expect(subject).to be_root
|
9
|
+
end
|
10
|
+
end
|
7
11
|
|
8
12
|
describe '.new' do
|
9
13
|
it 'has no children' do
|
10
|
-
expect(
|
14
|
+
expect(subject).to have(0).children
|
11
15
|
end
|
12
16
|
|
13
17
|
it 'has no letter' do
|
14
|
-
expect(
|
18
|
+
expect(subject.letter).to be_nil
|
15
19
|
end
|
16
20
|
|
17
21
|
it 'is not a terminal node' do
|
18
|
-
expect(
|
22
|
+
expect(subject).to_not be_terminal
|
19
23
|
end
|
20
24
|
|
21
25
|
it 'is not a word' do
|
22
|
-
expect(
|
26
|
+
expect(subject).to_not be_word
|
23
27
|
end
|
24
28
|
|
25
29
|
context 'with a block' do
|
26
|
-
|
30
|
+
subject { Root.new { |root| root << 'test' } }
|
27
31
|
|
28
32
|
it 'has no letter' do
|
29
|
-
expect(
|
33
|
+
expect(subject.letter).to be_nil
|
30
34
|
end
|
31
35
|
|
32
36
|
it 'is not a terminal node' do
|
33
|
-
expect(
|
37
|
+
expect(subject).to_not be_terminal
|
34
38
|
end
|
35
39
|
|
36
40
|
it 'is not a word' do
|
37
|
-
expect(
|
41
|
+
expect(subject).to_not be_word
|
38
42
|
end
|
39
43
|
|
40
44
|
it 'executes the block' do
|
41
|
-
expect(
|
42
|
-
expect(
|
45
|
+
expect(subject).to have(1).children
|
46
|
+
expect(subject.word? 'test').to be_true
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
47
51
|
describe '#compress!' do
|
48
|
-
let(:compressed_root) {
|
52
|
+
let(:compressed_root) { subject.compress! }
|
49
53
|
|
50
54
|
it 'returns itself marked as compressed' do
|
51
|
-
expect(compressed_root).to eq
|
55
|
+
expect(compressed_root).to eq subject
|
52
56
|
expect(compressed_root).to be_compressed
|
53
57
|
end
|
54
58
|
|
@@ -56,108 +60,108 @@ module Rambling
|
|
56
60
|
let(:recompressed_root) { compressed_root.compress! }
|
57
61
|
|
58
62
|
it 'keeps returning itself' do
|
59
|
-
expect(recompressed_root).to eq
|
63
|
+
expect(recompressed_root).to eq subject
|
60
64
|
expect(recompressed_root).to be_compressed
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
context 'with at least one word' do
|
65
69
|
it 'keeps the root letter nil' do
|
66
|
-
|
67
|
-
|
70
|
+
subject << 'all'
|
71
|
+
subject.compress!
|
68
72
|
|
69
|
-
expect(
|
73
|
+
expect(subject.letter).to be_nil
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
73
77
|
context 'with a single word' do
|
74
78
|
before do
|
75
|
-
|
76
|
-
|
79
|
+
subject << 'all'
|
80
|
+
subject.compress!
|
77
81
|
end
|
78
82
|
|
79
83
|
it 'compresses into a single node without children' do
|
80
|
-
expect(
|
81
|
-
expect(
|
82
|
-
expect(
|
83
|
-
expect(
|
84
|
+
expect(subject[:all].letter).to eq :all
|
85
|
+
expect(subject[:all]).to have(0).children
|
86
|
+
expect(subject[:all]).to be_terminal
|
87
|
+
expect(subject[:all]).to be_compressed
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
87
91
|
context 'with two words' do
|
88
92
|
before do
|
89
|
-
|
90
|
-
|
91
|
-
|
93
|
+
subject << 'all'
|
94
|
+
subject << 'ask'
|
95
|
+
subject.compress!
|
92
96
|
end
|
93
97
|
|
94
98
|
it 'compresses into corresponding three nodes' do
|
95
|
-
expect(
|
96
|
-
expect(
|
99
|
+
expect(subject[:a].letter).to eq :a
|
100
|
+
expect(subject[:a]).to have(2).children
|
97
101
|
|
98
|
-
expect(
|
99
|
-
expect(
|
102
|
+
expect(subject[:a][:ll].letter).to eq :ll
|
103
|
+
expect(subject[:a][:sk].letter).to eq :sk
|
100
104
|
|
101
|
-
expect(
|
102
|
-
expect(
|
105
|
+
expect(subject[:a][:ll]).to have(0).children
|
106
|
+
expect(subject[:a][:sk]).to have(0).children
|
103
107
|
|
104
|
-
expect(
|
105
|
-
expect(
|
108
|
+
expect(subject[:a][:ll]).to be_terminal
|
109
|
+
expect(subject[:a][:sk]).to be_terminal
|
106
110
|
|
107
|
-
expect(
|
108
|
-
expect(
|
111
|
+
expect(subject[:a][:ll]).to be_compressed
|
112
|
+
expect(subject[:a][:sk]).to be_compressed
|
109
113
|
end
|
110
114
|
end
|
111
115
|
|
112
116
|
it 'reassigns the parent nodes correctly' do
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
+
subject << 'repay'
|
118
|
+
subject << 'rest'
|
119
|
+
subject << 'repaint'
|
120
|
+
subject.compress!
|
117
121
|
|
118
|
-
expect(
|
119
|
-
expect(
|
122
|
+
expect(subject[:re].letter).to eq :re
|
123
|
+
expect(subject[:re]).to have(2).children
|
120
124
|
|
121
|
-
expect(
|
122
|
-
expect(
|
125
|
+
expect(subject[:re][:pa].letter).to eq :pa
|
126
|
+
expect(subject[:re][:st].letter).to eq :st
|
123
127
|
|
124
|
-
expect(
|
125
|
-
expect(
|
128
|
+
expect(subject[:re][:pa]).to have(2).children
|
129
|
+
expect(subject[:re][:st]).to have(0).children
|
126
130
|
|
127
|
-
expect(
|
128
|
-
expect(
|
131
|
+
expect(subject[:re][:pa][:y].letter).to eq :y
|
132
|
+
expect(subject[:re][:pa][:int].letter).to eq :int
|
129
133
|
|
130
|
-
expect(
|
131
|
-
expect(
|
134
|
+
expect(subject[:re][:pa][:y]).to have(0).children
|
135
|
+
expect(subject[:re][:pa][:int]).to have(0).children
|
132
136
|
|
133
|
-
expect(
|
134
|
-
expect(
|
137
|
+
expect(subject[:re][:pa][:y].parent).to eq subject[:re][:pa]
|
138
|
+
expect(subject[:re][:pa][:int].parent).to eq subject[:re][:pa]
|
135
139
|
end
|
136
140
|
|
137
141
|
it 'does not compress terminal nodes' do
|
138
|
-
|
139
|
-
|
140
|
-
|
142
|
+
subject << 'you'
|
143
|
+
subject << 'your'
|
144
|
+
subject << 'yours'
|
141
145
|
|
142
|
-
|
146
|
+
subject.compress!
|
143
147
|
|
144
|
-
expect(
|
148
|
+
expect(subject[:you].letter).to eq :you
|
145
149
|
|
146
|
-
expect(
|
147
|
-
expect(
|
150
|
+
expect(subject[:you][:r].letter).to eq :r
|
151
|
+
expect(subject[:you][:r]).to be_compressed
|
148
152
|
|
149
|
-
expect(
|
150
|
-
expect(
|
153
|
+
expect(subject[:you][:r][:s].letter).to eq :s
|
154
|
+
expect(subject[:you][:r][:s]).to be_compressed
|
151
155
|
end
|
152
156
|
|
153
|
-
describe 'and trying to add a
|
157
|
+
describe 'and trying to add a word' do
|
154
158
|
it 'raises an error' do
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
+
subject << 'repay'
|
160
|
+
subject << 'rest'
|
161
|
+
subject << 'repaint'
|
162
|
+
subject.compress!
|
159
163
|
|
160
|
-
expect {
|
164
|
+
expect { subject << 'restaurant' }.to raise_error InvalidOperation
|
161
165
|
end
|
162
166
|
end
|
163
167
|
end
|
@@ -165,99 +169,119 @@ module Rambling
|
|
165
169
|
describe '#word?' do
|
166
170
|
context 'word is contained' do
|
167
171
|
before do
|
168
|
-
|
169
|
-
|
172
|
+
subject << 'hello'
|
173
|
+
subject << 'high'
|
170
174
|
end
|
171
175
|
|
172
176
|
it 'matches the whole word' do
|
173
|
-
expect(
|
174
|
-
expect(
|
177
|
+
expect(subject.word? 'hello').to be_true
|
178
|
+
expect(subject.word? 'high').to be_true
|
175
179
|
end
|
176
180
|
|
177
181
|
it 'is aliased as #include?' do
|
178
|
-
expect(
|
179
|
-
expect(
|
182
|
+
expect(subject).to include 'hello'
|
183
|
+
expect(subject).to include 'high'
|
180
184
|
end
|
181
185
|
|
182
186
|
context 'and the root has been compressed' do
|
183
187
|
before do
|
184
|
-
|
188
|
+
subject.compress!
|
185
189
|
end
|
186
190
|
|
187
191
|
it 'matches the whole word' do
|
188
|
-
expect(
|
189
|
-
expect(
|
192
|
+
expect(subject.word? 'hello').to be_true
|
193
|
+
expect(subject.word? 'high').to be_true
|
190
194
|
end
|
191
195
|
end
|
192
196
|
end
|
193
197
|
|
194
198
|
context 'word is not contained' do
|
195
199
|
before do
|
196
|
-
|
200
|
+
subject << 'hello'
|
197
201
|
end
|
198
202
|
|
199
203
|
it 'does not match the whole word' do
|
200
|
-
expect(
|
204
|
+
expect(subject.word? 'halt').to be_false
|
201
205
|
end
|
202
206
|
|
203
207
|
it 'is aliased as #include?' do
|
204
|
-
expect(
|
208
|
+
expect(subject).to_not include 'high'
|
205
209
|
end
|
206
210
|
|
207
211
|
context 'and the root has been compressed' do
|
208
212
|
before do
|
209
|
-
|
213
|
+
subject.compress!
|
210
214
|
end
|
211
215
|
|
212
216
|
it 'does not match the whole word' do
|
213
|
-
expect(
|
217
|
+
expect(subject.word? 'halt').to be_false
|
214
218
|
end
|
215
219
|
end
|
216
220
|
end
|
217
221
|
end
|
218
222
|
|
219
|
-
describe '#
|
223
|
+
describe '#partial_word?' do
|
224
|
+
it 'is aliased as #match?' do
|
225
|
+
subject << 'hello'
|
226
|
+
subject << 'high'
|
227
|
+
expect(subject.match? 'hel').to be_true
|
228
|
+
expect(subject.match? 'hig').to be_true
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'is aliased as #branch?, but with a warning' do
|
232
|
+
subject << 'hello'
|
233
|
+
subject << 'high'
|
234
|
+
subject.should_receive(:warn).with('The `#branch?` method will be deprecated, please use `#partial_word?` instead.').twice
|
235
|
+
expect(subject.branch? 'hel').to be_true
|
236
|
+
expect(subject.branch? 'hig').to be_true
|
237
|
+
end
|
238
|
+
|
220
239
|
context 'word is contained' do
|
221
240
|
before do
|
222
|
-
|
223
|
-
|
241
|
+
subject << 'hello'
|
242
|
+
subject << 'high'
|
224
243
|
end
|
225
244
|
|
226
245
|
it 'matches part of the word' do
|
227
|
-
expect(
|
228
|
-
expect(
|
246
|
+
expect(subject.partial_word? 'hell').to be_true
|
247
|
+
expect(subject.partial_word? 'hig').to be_true
|
229
248
|
end
|
230
249
|
|
231
250
|
context 'and the root has been compressed' do
|
232
251
|
before do
|
233
|
-
|
252
|
+
subject.compress!
|
234
253
|
end
|
235
254
|
|
236
255
|
it 'matches part of the word' do
|
237
|
-
expect(
|
238
|
-
expect(
|
256
|
+
expect(subject.partial_word? 'h').to be_true
|
257
|
+
expect(subject.partial_word? 'he').to be_true
|
258
|
+
expect(subject.partial_word? 'hell').to be_true
|
259
|
+
expect(subject.partial_word? 'hello').to be_true
|
260
|
+
expect(subject.partial_word? 'hi').to be_true
|
261
|
+
expect(subject.partial_word? 'hig').to be_true
|
262
|
+
expect(subject.partial_word? 'high').to be_true
|
239
263
|
end
|
240
264
|
end
|
241
265
|
end
|
242
266
|
|
243
267
|
context 'word is not contained' do
|
244
268
|
before do
|
245
|
-
|
269
|
+
subject << 'hello'
|
246
270
|
end
|
247
271
|
|
248
272
|
it 'does not match any part of the word' do
|
249
|
-
expect(
|
250
|
-
expect(
|
273
|
+
expect(subject.partial_word? 'ha').to be_false
|
274
|
+
expect(subject.partial_word? 'hal').to be_false
|
251
275
|
end
|
252
276
|
|
253
277
|
context 'and the root has been compressed' do
|
254
278
|
before do
|
255
|
-
|
279
|
+
subject.compress!
|
256
280
|
end
|
257
281
|
|
258
282
|
it 'does not match any part of the word' do
|
259
|
-
expect(
|
260
|
-
expect(
|
283
|
+
expect(subject.partial_word? 'ha').to be_false
|
284
|
+
expect(subject.partial_word? 'hal').to be_false
|
261
285
|
end
|
262
286
|
end
|
263
287
|
end
|
@@ -268,12 +292,12 @@ module Rambling
|
|
268
292
|
let(:word) { original_word.clone }
|
269
293
|
|
270
294
|
it 'does not change the original word' do
|
271
|
-
|
295
|
+
subject.add word
|
272
296
|
expect(word).to eq original_word
|
273
297
|
end
|
274
298
|
|
275
299
|
it 'is still aliased as #<<' do
|
276
|
-
|
300
|
+
subject << word
|
277
301
|
expect(word).to eq original_word
|
278
302
|
end
|
279
303
|
end
|