rambling-trie 2.4.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +28 -0
  3. data/Gemfile +20 -8
  4. data/Guardfile +16 -5
  5. data/README.md +38 -32
  6. data/Rakefile +6 -0
  7. data/Steepfile +35 -0
  8. data/lib/rambling/trie/comparable.rb +2 -2
  9. data/lib/rambling/trie/compressible.rb +1 -1
  10. data/lib/rambling/trie/compressor.rb +22 -19
  11. data/lib/rambling/trie/configuration/properties.rb +10 -6
  12. data/lib/rambling/trie/configuration/provider_collection.rb +14 -9
  13. data/lib/rambling/trie/configuration.rb +2 -3
  14. data/lib/rambling/trie/container.rb +32 -24
  15. data/lib/rambling/trie/enumerable.rb +5 -6
  16. data/lib/rambling/trie/nodes/compressed.rb +26 -16
  17. data/lib/rambling/trie/nodes/node.rb +35 -12
  18. data/lib/rambling/trie/nodes/raw.rb +18 -20
  19. data/lib/rambling/trie/nodes.rb +2 -3
  20. data/lib/rambling/trie/readers/plain_text.rb +3 -3
  21. data/lib/rambling/trie/readers.rb +2 -3
  22. data/lib/rambling/trie/serializers/file.rb +1 -3
  23. data/lib/rambling/trie/serializers/marshal.rb +4 -4
  24. data/lib/rambling/trie/serializers/yaml.rb +3 -3
  25. data/lib/rambling/trie/serializers/zip.rb +13 -5
  26. data/lib/rambling/trie/serializers.rb +2 -3
  27. data/lib/rambling/trie/stringifyable.rb +1 -1
  28. data/lib/rambling/trie/version.rb +1 -1
  29. data/lib/rambling/trie.rb +12 -15
  30. data/rambling-trie.gemspec +4 -10
  31. data/sig/lib/rambling/trie/comparable.rbs +17 -0
  32. data/sig/lib/rambling/trie/compressible.rbs +17 -0
  33. data/sig/lib/rambling/trie/compressor.rbs +17 -0
  34. data/sig/lib/rambling/trie/configuration/properties.rbs +28 -0
  35. data/sig/lib/rambling/trie/configuration/provider_collection.rbs +47 -0
  36. data/sig/lib/rambling/trie/container.rbs +69 -0
  37. data/sig/lib/rambling/trie/enumerable.rbs +23 -0
  38. data/sig/lib/rambling/trie/inspectable.rbs +27 -0
  39. data/sig/lib/rambling/trie/invalid_operation.rbs +7 -0
  40. data/sig/lib/rambling/trie/nodes/compressed.rbs +25 -0
  41. data/sig/lib/rambling/trie/nodes/missing.rbs +9 -0
  42. data/sig/lib/rambling/trie/nodes/node.rbs +69 -0
  43. data/sig/lib/rambling/trie/nodes/raw.rbs +27 -0
  44. data/sig/lib/rambling/trie/readers/plain_text.rbs +9 -0
  45. data/sig/lib/rambling/trie/readers/reader.rbs +9 -0
  46. data/sig/lib/rambling/trie/serializers/file.rbs +8 -0
  47. data/sig/lib/rambling/trie/serializers/marshal.rbs +13 -0
  48. data/sig/lib/rambling/trie/serializers/serializer.rbs +10 -0
  49. data/sig/lib/rambling/trie/serializers/yaml.rbs +13 -0
  50. data/sig/lib/rambling/trie/serializers/zip.rbs +21 -0
  51. data/sig/lib/rambling/trie/stringifyable.rbs +21 -0
  52. data/sig/lib/rambling/trie.rbs +27 -0
  53. data/sig/lib/zip/entry.rbs +11 -0
  54. data/sig/lib/zip/file.rbs +11 -0
  55. metadata +34 -123
  56. data/spec/assets/test_words.en_US.txt +0 -23
  57. data/spec/assets/test_words.es_DO.txt +0 -24
  58. data/spec/integration/rambling/trie_spec.rb +0 -116
  59. data/spec/lib/rambling/trie/comparable_spec.rb +0 -87
  60. data/spec/lib/rambling/trie/compressor_spec.rb +0 -111
  61. data/spec/lib/rambling/trie/configuration/properties_spec.rb +0 -75
  62. data/spec/lib/rambling/trie/configuration/provider_collection_spec.rb +0 -177
  63. data/spec/lib/rambling/trie/container_spec.rb +0 -466
  64. data/spec/lib/rambling/trie/enumerable_spec.rb +0 -50
  65. data/spec/lib/rambling/trie/inspectable_spec.rb +0 -62
  66. data/spec/lib/rambling/trie/nodes/compressed_spec.rb +0 -43
  67. data/spec/lib/rambling/trie/nodes/node_spec.rb +0 -9
  68. data/spec/lib/rambling/trie/nodes/raw_spec.rb +0 -184
  69. data/spec/lib/rambling/trie/readers/plain_text_spec.rb +0 -26
  70. data/spec/lib/rambling/trie/readers/reader_spec.rb +0 -14
  71. data/spec/lib/rambling/trie/serializers/file_spec.rb +0 -11
  72. data/spec/lib/rambling/trie/serializers/marshal_spec.rb +0 -10
  73. data/spec/lib/rambling/trie/serializers/serializer_spec.rb +0 -21
  74. data/spec/lib/rambling/trie/serializers/yaml_spec.rb +0 -10
  75. data/spec/lib/rambling/trie/serializers/zip_spec.rb +0 -36
  76. data/spec/lib/rambling/trie/stringifyable_spec.rb +0 -89
  77. data/spec/lib/rambling/trie_spec.rb +0 -244
  78. data/spec/spec_helper.rb +0 -42
  79. data/spec/support/config.rb +0 -15
  80. data/spec/support/helpers/add_word.rb +0 -20
  81. data/spec/support/helpers/one_line_heredoc.rb +0 -11
  82. data/spec/support/shared_examples/a_compressible_trie.rb +0 -46
  83. data/spec/support/shared_examples/a_container_partial_word.rb +0 -17
  84. data/spec/support/shared_examples/a_container_scan.rb +0 -14
  85. data/spec/support/shared_examples/a_container_word.rb +0 -43
  86. data/spec/support/shared_examples/a_container_words_within.rb +0 -44
  87. data/spec/support/shared_examples/a_serializable_trie.rb +0 -26
  88. data/spec/support/shared_examples/a_serializer.rb +0 -60
  89. data/spec/support/shared_examples/a_trie_data_structure.rb +0 -45
  90. data/spec/support/shared_examples/a_trie_node.rb +0 -135
  91. data/spec/support/shared_examples/a_trie_node_implementation.rb +0 -149
  92. data/spec/tmp/.gitkeep +0 -0
@@ -1,135 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_examples_for 'a trie node' do
4
- let(:node_class) { node.class }
5
-
6
- describe '.new' do
7
- it 'has no letter' do
8
- expect(node.letter).to be_nil
9
- end
10
-
11
- it 'has no children' do
12
- expect(node.children.size).to eq 0
13
- end
14
-
15
- it 'is not terminal' do
16
- expect(node).not_to be_terminal
17
- end
18
-
19
- it 'returns empty string as its word' do
20
- expect(node.as_word).to be_empty
21
- end
22
-
23
- context 'with a letter and a parent' do
24
- let(:parent) { node_class.new }
25
- # noinspection RubyArgCount
26
- let(:node_with_parent) { node_class.new :a, parent }
27
-
28
- it 'does not have any letter' do
29
- expect(node_with_parent.letter).to eq :a
30
- end
31
-
32
- it 'has no children' do
33
- expect(node_with_parent.children.size).to eq 0
34
- end
35
-
36
- it 'is not terminal' do
37
- expect(node_with_parent).not_to be_terminal
38
- end
39
- end
40
- end
41
-
42
- describe '#root?' do
43
- context 'when the node has a parent' do
44
- before { node.parent = node }
45
-
46
- it 'returns false' do
47
- expect(node).not_to be_root
48
- end
49
- end
50
-
51
- context 'when the node does not have a parent' do
52
- before { node.parent = nil }
53
-
54
- it 'returns true' do
55
- expect(node).to be_root
56
- end
57
- end
58
- end
59
-
60
- describe '#terminal!' do
61
- # rubocop:disable RSpec/MultipleExpectations
62
- it 'forces the node to be terminal' do
63
- expect(node).not_to be_terminal
64
- node.terminal!
65
- expect(node).to be_terminal
66
- end
67
- # rubocop:enable RSpec/MultipleExpectations
68
-
69
- it 'returns the node' do
70
- expect(node.terminal!).to eq node
71
- end
72
- end
73
-
74
- describe 'delegates and aliases' do
75
- let :children_tree do
76
- instance_double(
77
- 'Hash',
78
- :children_tree,
79
- :[] => 'value',
80
- :[]= => nil,
81
- key?: false,
82
- delete: true,
83
- )
84
- end
85
-
86
- before { node.children_tree = children_tree }
87
-
88
- # rubocop:disable RSpec/MultipleExpectations
89
- it 'delegates `#[]` to its children tree' do
90
- expect(node[:key]).to eq 'value'
91
- expect(children_tree).to have_received(:[]).with :key
92
- end
93
- # rubocop:enable RSpec/MultipleExpectations
94
-
95
- it 'delegates `#[]=` to its children tree' do
96
- node[:key] = 'value'
97
- expect(children_tree).to have_received(:[]=).with(:key, 'value')
98
- end
99
-
100
- # rubocop:disable RSpec/MultipleExpectations
101
- it 'delegates `#key?` to its children tree' do
102
- allow(children_tree).to receive(:key?)
103
- .with(:present_key)
104
- .and_return true
105
-
106
- expect(node).to have_key(:present_key)
107
- expect(node).not_to have_key(:absent_key)
108
- end
109
- # rubocop:enable RSpec/MultipleExpectations
110
-
111
- # rubocop:disable RSpec/MultipleExpectations
112
- it 'delegates `#delete` to its children tree' do
113
- expect(node.delete :key).to be true
114
- expect(children_tree).to have_received(:delete).with :key
115
- end
116
- # rubocop:enable RSpec/MultipleExpectations
117
-
118
- # rubocop:disable RSpec/ExampleLength
119
- it 'delegates `#children` to its children tree values' do
120
- children = [
121
- instance_double('Rambling::Trie::Nodes::Node', :child_one),
122
- instance_double('Rambling::Trie::Nodes::Node', :child_two),
123
- ]
124
- allow(children_tree).to receive(:values).and_return children
125
-
126
- expect(node.children).to eq children
127
- end
128
- # rubocop:enable RSpec/ExampleLength
129
-
130
- it 'aliases `#has_key?` to `#key?`' do
131
- node.has_key? :nope
132
- expect(children_tree).to have_received(:key?).with :nope
133
- end
134
- end
135
- end
@@ -1,149 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_examples_for 'a trie node implementation' do
4
- it_behaves_like 'a trie node'
5
-
6
- describe '#partial_word?' do
7
- context 'when the chars array is empty' do
8
- it 'returns true' do
9
- expect(node.partial_word? []).to be true
10
- end
11
- end
12
-
13
- context 'when the chars array is not empty' do
14
- context 'when the node has a tree that matches the characters' do
15
- before { add_word_to_tree 'abc' }
16
-
17
- [%w(a), %w(a b), %w(a b c)].each do |letters|
18
- it "returns true for '#{letters}'" do
19
- expect(node.partial_word? letters).to be true
20
- end
21
- end
22
- end
23
-
24
- context 'when the node has a tree that does not match the characters' do
25
- before { add_word_to_tree 'cba' }
26
-
27
- [%w(a), %w(a b), %w(a b c)].each do |letters|
28
- it "returns false for '#{letters}'" do
29
- expect(node.partial_word? letters).to be false
30
- end
31
- end
32
- end
33
- end
34
- end
35
-
36
- describe '#word?' do
37
- context 'when the chars array is empty' do
38
- context 'when the node is terminal' do
39
- before { node.terminal! }
40
-
41
- it 'returns true' do
42
- expect(node.word? []).to be true
43
- end
44
- end
45
-
46
- context 'when the node is not terminal' do
47
- it 'returns false' do
48
- expect(node.word? []).to be false
49
- end
50
- end
51
- end
52
-
53
- context 'when the chars array is not empty' do
54
- context 'when the node has a tree that matches all the characters' do
55
- before { add_word_to_tree 'abc' }
56
-
57
- it 'returns true' do
58
- expect(node.word? %w(a b c).map(&:dup)).to be true
59
- end
60
- end
61
-
62
- context 'when the node subtree does not match all the characters' do
63
- before { add_word_to_tree 'abc' }
64
-
65
- [%w(a), %w(a b)].each do |letters|
66
- it "returns false for '#{letters}'" do
67
- expect(node.word? letters.map(&:dup)).to be false
68
- end
69
- end
70
- end
71
- end
72
- end
73
-
74
- describe '#scan' do
75
- context 'when the chars array is empty' do
76
- it 'returns itself' do
77
- expect(node.scan []).to eq node
78
- end
79
- end
80
-
81
- context 'when the chars array is not empty' do
82
- before { add_words_to_tree %w(cba ccab) }
83
-
84
- context 'when the chars are found' do
85
- [
86
- [%w(c), %w(cba ccab)],
87
- [%w(c b), %w(cba)],
88
- [%w(c b a), %w(cba)],
89
- ].each do |test_params|
90
- letters, expected = test_params
91
-
92
- it "returns the corresponding children (#{letters} => #{expected})" do
93
- expect(node.scan letters).to match_array expected
94
- end
95
- end
96
- end
97
-
98
- context 'when the chars are not found' do
99
- [
100
- %w(a),
101
- %w(a b),
102
- %w(a b c),
103
- %w(c a),
104
- %w(c c b),
105
- %w(c b a d),
106
- ].each do |letters|
107
- it "returns a Nodes::Missing for '#{letters}'" do
108
- expect(node.scan letters).to be_a Rambling::Trie::Nodes::Missing
109
- end
110
- end
111
- end
112
- end
113
- end
114
-
115
- describe '#match_prefix' do
116
- before do
117
- assign_letter :i
118
- add_words_to_tree %w(gnite mport mportant mportantly)
119
- end
120
-
121
- context 'when the node is terminal' do
122
- before { node.terminal! }
123
-
124
- it 'adds itself to the words' do
125
- expect(node.match_prefix %w(g n i t e)).to include 'i'
126
- end
127
- end
128
-
129
- context 'when the node is not terminal' do
130
- it 'does not add itself to the words' do
131
- expect(node.match_prefix %w(g n i t e)).not_to include 'i'
132
- end
133
- end
134
-
135
- context 'when the first few chars match a terminal node' do
136
- it 'adds those terminal nodes to the words' do
137
- words = node.match_prefix(%w(m p o r t a n t l y)).to_a
138
- expect(words).to include 'import', 'important', 'importantly'
139
- end
140
- end
141
-
142
- context 'when the first few chars do not match a terminal node' do
143
- it 'does not add any other words found' do
144
- words = node.match_prefix(%w(m p m p o r t a n t l y)).to_a
145
- expect(words).not_to include 'import', 'important', 'importantly'
146
- end
147
- end
148
- end
149
- end
data/spec/tmp/.gitkeep DELETED
File without changes