rambling-trie 2.4.0 → 2.5.1

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.
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
@@ -0,0 +1,11 @@
1
+ module Zip
2
+ class File
3
+ CREATE: bool
4
+
5
+ def self.open: [TContent] (String, ?bool?) { (File) -> TContent } -> TContent
6
+
7
+ def entries: -> Array[Entry]
8
+
9
+ def add: (String, String) -> void
10
+ end
11
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rambling-trie
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgar Gonzalez
@@ -9,50 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-01-27 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '13.1'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '13.1'
28
- - !ruby/object:Gem::Dependency
29
- name: rspec
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - "~>"
33
- - !ruby/object:Gem::Version
34
- version: '3.12'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - "~>"
40
- - !ruby/object:Gem::Version
41
- version: '3.12'
42
- - !ruby/object:Gem::Dependency
43
- name: yard
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 0.9.34
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 0.9.34
12
+ date: 2024-12-05 00:00:00.000000000 Z
13
+ dependencies: []
56
14
  description: 'The Rambling Trie is a Ruby implementation of the trie data structure,
57
15
  which includes compression abilities and is designed to be very fast to traverse. '
58
16
  email:
@@ -62,11 +20,13 @@ executables: []
62
20
  extensions: []
63
21
  extra_rdoc_files: []
64
22
  files:
23
+ - Dockerfile
65
24
  - Gemfile
66
25
  - Guardfile
67
26
  - LICENSE
68
27
  - README.md
69
28
  - Rakefile
29
+ - Steepfile
70
30
  - lib/rambling-trie.rb
71
31
  - lib/rambling/trie.rb
72
32
  - lib/rambling/trie/comparable.rb
@@ -96,49 +56,37 @@ files:
96
56
  - lib/rambling/trie/stringifyable.rb
97
57
  - lib/rambling/trie/version.rb
98
58
  - rambling-trie.gemspec
99
- - spec/assets/test_words.en_US.txt
100
- - spec/assets/test_words.es_DO.txt
101
- - spec/integration/rambling/trie_spec.rb
102
- - spec/lib/rambling/trie/comparable_spec.rb
103
- - spec/lib/rambling/trie/compressor_spec.rb
104
- - spec/lib/rambling/trie/configuration/properties_spec.rb
105
- - spec/lib/rambling/trie/configuration/provider_collection_spec.rb
106
- - spec/lib/rambling/trie/container_spec.rb
107
- - spec/lib/rambling/trie/enumerable_spec.rb
108
- - spec/lib/rambling/trie/inspectable_spec.rb
109
- - spec/lib/rambling/trie/nodes/compressed_spec.rb
110
- - spec/lib/rambling/trie/nodes/node_spec.rb
111
- - spec/lib/rambling/trie/nodes/raw_spec.rb
112
- - spec/lib/rambling/trie/readers/plain_text_spec.rb
113
- - spec/lib/rambling/trie/readers/reader_spec.rb
114
- - spec/lib/rambling/trie/serializers/file_spec.rb
115
- - spec/lib/rambling/trie/serializers/marshal_spec.rb
116
- - spec/lib/rambling/trie/serializers/serializer_spec.rb
117
- - spec/lib/rambling/trie/serializers/yaml_spec.rb
118
- - spec/lib/rambling/trie/serializers/zip_spec.rb
119
- - spec/lib/rambling/trie/stringifyable_spec.rb
120
- - spec/lib/rambling/trie_spec.rb
121
- - spec/spec_helper.rb
122
- - spec/support/config.rb
123
- - spec/support/helpers/add_word.rb
124
- - spec/support/helpers/one_line_heredoc.rb
125
- - spec/support/shared_examples/a_compressible_trie.rb
126
- - spec/support/shared_examples/a_container_partial_word.rb
127
- - spec/support/shared_examples/a_container_scan.rb
128
- - spec/support/shared_examples/a_container_word.rb
129
- - spec/support/shared_examples/a_container_words_within.rb
130
- - spec/support/shared_examples/a_serializable_trie.rb
131
- - spec/support/shared_examples/a_serializer.rb
132
- - spec/support/shared_examples/a_trie_data_structure.rb
133
- - spec/support/shared_examples/a_trie_node.rb
134
- - spec/support/shared_examples/a_trie_node_implementation.rb
135
- - spec/tmp/.gitkeep
59
+ - sig/lib/rambling/trie.rbs
60
+ - sig/lib/rambling/trie/comparable.rbs
61
+ - sig/lib/rambling/trie/compressible.rbs
62
+ - sig/lib/rambling/trie/compressor.rbs
63
+ - sig/lib/rambling/trie/configuration/properties.rbs
64
+ - sig/lib/rambling/trie/configuration/provider_collection.rbs
65
+ - sig/lib/rambling/trie/container.rbs
66
+ - sig/lib/rambling/trie/enumerable.rbs
67
+ - sig/lib/rambling/trie/inspectable.rbs
68
+ - sig/lib/rambling/trie/invalid_operation.rbs
69
+ - sig/lib/rambling/trie/nodes/compressed.rbs
70
+ - sig/lib/rambling/trie/nodes/missing.rbs
71
+ - sig/lib/rambling/trie/nodes/node.rbs
72
+ - sig/lib/rambling/trie/nodes/raw.rbs
73
+ - sig/lib/rambling/trie/readers/plain_text.rbs
74
+ - sig/lib/rambling/trie/readers/reader.rbs
75
+ - sig/lib/rambling/trie/serializers/file.rbs
76
+ - sig/lib/rambling/trie/serializers/marshal.rbs
77
+ - sig/lib/rambling/trie/serializers/serializer.rbs
78
+ - sig/lib/rambling/trie/serializers/yaml.rbs
79
+ - sig/lib/rambling/trie/serializers/zip.rbs
80
+ - sig/lib/rambling/trie/stringifyable.rbs
81
+ - sig/lib/zip/entry.rbs
82
+ - sig/lib/zip/file.rbs
136
83
  homepage: https://github.com/gonzedge/rambling-trie
137
84
  licenses:
138
85
  - MIT
139
86
  metadata:
140
- changelog_uri: https://github.com/gonzedge/rambling-trie/blob/master/CHANGELOG.md
87
+ changelog_uri: https://github.com/gonzedge/rambling-trie/blob/main/CHANGELOG.md
141
88
  documentation_uri: https://www.rubydoc.info/gems/rambling-trie
89
+ rubygems_mfa_required: 'true'
142
90
  post_install_message:
143
91
  rdoc_options: []
144
92
  require_paths:
@@ -147,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
95
  requirements:
148
96
  - - ">="
149
97
  - !ruby/object:Gem::Version
150
- version: '2.7'
98
+ version: '3.1'
151
99
  - - "<"
152
100
  - !ruby/object:Gem::Version
153
101
  version: '4'
@@ -157,45 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
105
  - !ruby/object:Gem::Version
158
106
  version: '0'
159
107
  requirements: []
160
- rubygems_version: 3.5.3
108
+ rubygems_version: 3.5.22
161
109
  signing_key:
162
110
  specification_version: 4
163
111
  summary: A Ruby implementation of the trie data structure.
164
- test_files:
165
- - spec/assets/test_words.en_US.txt
166
- - spec/assets/test_words.es_DO.txt
167
- - spec/integration/rambling/trie_spec.rb
168
- - spec/lib/rambling/trie/comparable_spec.rb
169
- - spec/lib/rambling/trie/compressor_spec.rb
170
- - spec/lib/rambling/trie/configuration/properties_spec.rb
171
- - spec/lib/rambling/trie/configuration/provider_collection_spec.rb
172
- - spec/lib/rambling/trie/container_spec.rb
173
- - spec/lib/rambling/trie/enumerable_spec.rb
174
- - spec/lib/rambling/trie/inspectable_spec.rb
175
- - spec/lib/rambling/trie/nodes/compressed_spec.rb
176
- - spec/lib/rambling/trie/nodes/node_spec.rb
177
- - spec/lib/rambling/trie/nodes/raw_spec.rb
178
- - spec/lib/rambling/trie/readers/plain_text_spec.rb
179
- - spec/lib/rambling/trie/readers/reader_spec.rb
180
- - spec/lib/rambling/trie/serializers/file_spec.rb
181
- - spec/lib/rambling/trie/serializers/marshal_spec.rb
182
- - spec/lib/rambling/trie/serializers/serializer_spec.rb
183
- - spec/lib/rambling/trie/serializers/yaml_spec.rb
184
- - spec/lib/rambling/trie/serializers/zip_spec.rb
185
- - spec/lib/rambling/trie/stringifyable_spec.rb
186
- - spec/lib/rambling/trie_spec.rb
187
- - spec/spec_helper.rb
188
- - spec/support/config.rb
189
- - spec/support/helpers/add_word.rb
190
- - spec/support/helpers/one_line_heredoc.rb
191
- - spec/support/shared_examples/a_compressible_trie.rb
192
- - spec/support/shared_examples/a_container_partial_word.rb
193
- - spec/support/shared_examples/a_container_scan.rb
194
- - spec/support/shared_examples/a_container_word.rb
195
- - spec/support/shared_examples/a_container_words_within.rb
196
- - spec/support/shared_examples/a_serializable_trie.rb
197
- - spec/support/shared_examples/a_serializer.rb
198
- - spec/support/shared_examples/a_trie_data_structure.rb
199
- - spec/support/shared_examples/a_trie_node.rb
200
- - spec/support/shared_examples/a_trie_node_implementation.rb
201
- - spec/tmp/.gitkeep
112
+ test_files: []
@@ -1,23 +0,0 @@
1
- are
2
- beautiful
3
- course
4
- false
5
- hello
6
- hi
7
- is
8
- it
9
- mine
10
- my
11
- no
12
- of
13
- ours
14
- today
15
- true
16
- truth
17
- whatever
18
- where
19
- who
20
- yeah
21
- you
22
- your
23
- yours
@@ -1,24 +0,0 @@
1
- claro
2
- donde
3
- dónde
4
- eres
5
- es
6
- eso
7
- falso
8
- hermoso
9
- hola
10
- hoy
11
- mi
12
- mío
13
- no
14
- nuestro
15
- ola
16
- quien
17
- quién
18
- si
19
- tu
20
- tus
21
- tuyos
22
- verdad
23
- verdadero
24
- 🙃
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'zip'
5
-
6
- describe Rambling::Trie do
7
- let(:assets_path) { File.join ::SPEC_ROOT, 'assets' }
8
-
9
- describe '::VERSION' do
10
- let(:root_path) { File.join ::SPEC_ROOT, '..' }
11
- let(:readme_path) { File.join root_path, 'README.md' }
12
- let(:readme) { File.read readme_path }
13
- let(:changelog_path) { File.join root_path, 'CHANGELOG.md' }
14
- let(:changelog) { File.read changelog_path }
15
-
16
- let(:changelog_versions) do
17
- matches = []
18
- changelog.scan %r{^## (\d+\.\d+\.\d+)} do |match|
19
- matches << match[0]
20
- end
21
- matches
22
- end
23
-
24
- it 'matches with the version in the README badge' do
25
- match = %r{\?version=(?<version>.*)$}.match readme
26
- expect(match['version']).to eq Rambling::Trie::VERSION
27
- end
28
-
29
- it 'is the version before the one at the top of the CHANGELOG' do
30
- changelog_version = Gem::Version.new changelog_versions.first
31
- lib_version = Gem::Version.new "#{Rambling::Trie::VERSION}.0"
32
- expect(changelog_version).to eq lib_version.bump
33
- end
34
-
35
- it 'is included in the CHANGELOG diffs' do
36
- changelog_versions.shift
37
- expect(changelog_versions.first).to eq Rambling::Trie::VERSION
38
- end
39
- end
40
-
41
- context 'when providing words directly' do
42
- it_behaves_like 'a compressible trie' do
43
- let(:trie) { described_class.create }
44
- let(:words) { %w(a couple of words for our full trie integration test) }
45
-
46
- before { trie.concat words }
47
- end
48
- end
49
-
50
- context 'when provided with words with unicode characters' do
51
- it_behaves_like 'a compressible trie' do
52
- let(:trie) { described_class.create }
53
- let :words do
54
- %w(poquísimas palabras para nuestra prueba de integración completa 🙃)
55
- end
56
-
57
- before { trie.concat words }
58
- end
59
- end
60
-
61
- context 'when provided with a filepath' do
62
- let(:trie) { described_class.create filepath }
63
- let(:words) { File.readlines(filepath).map(&:chomp) }
64
-
65
- context 'with english words' do
66
- it_behaves_like 'a compressible trie' do
67
- let(:filepath) { File.join assets_path, 'test_words.en_US.txt' }
68
- end
69
- end
70
-
71
- context 'with unicode characters' do
72
- it_behaves_like 'a compressible trie' do
73
- let(:filepath) { File.join assets_path, 'test_words.es_DO.txt' }
74
- end
75
- end
76
- end
77
-
78
- describe 'dump and load' do
79
- let(:words_filepath) { File.join assets_path, 'test_words.en_US.txt' }
80
- let(:words) { File.readlines(words_filepath).map(&:chomp) }
81
-
82
- context 'when serialized with Ruby marshal format (default)' do
83
- it_behaves_like 'a serializable trie' do
84
- let(:trie_to_serialize) { described_class.create words_filepath }
85
- let(:file_format) { :marshal }
86
- end
87
- end
88
-
89
- context 'when serialized with YAML' do
90
- it_behaves_like 'a serializable trie' do
91
- let(:trie_to_serialize) { described_class.create words_filepath }
92
- let(:file_format) { :yml }
93
- end
94
- end
95
-
96
- context 'when serialized with zipped Ruby marshal format' do
97
- let!(:original_on_exists_proc) { ::Zip.on_exists_proc }
98
- let!(:original_continue_on_exists_proc) { ::Zip.continue_on_exists_proc }
99
-
100
- before do
101
- ::Zip.on_exists_proc = true
102
- ::Zip.continue_on_exists_proc = true
103
- end
104
-
105
- after do
106
- ::Zip.on_exists_proc = original_on_exists_proc
107
- ::Zip.continue_on_exists_proc = original_continue_on_exists_proc
108
- end
109
-
110
- it_behaves_like 'a serializable trie' do
111
- let(:trie_to_serialize) { described_class.create words_filepath }
112
- let(:file_format) { 'marshal.zip' }
113
- end
114
- end
115
- end
116
- end
@@ -1,87 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Rambling::Trie::Comparable do
6
- describe '#==' do
7
- let(:node_one) { Rambling::Trie::Nodes::Raw.new }
8
- let(:node_two) { Rambling::Trie::Nodes::Raw.new }
9
-
10
- context 'when the nodes do not have the same letter' do
11
- before do
12
- node_one.letter = :a
13
- node_two.letter = :b
14
- end
15
-
16
- it 'returns false' do
17
- expect(node_one).not_to eq node_two
18
- end
19
- end
20
-
21
- context 'when nodes have same letter, not terminal and no children' do
22
- before do
23
- node_one.letter = :a
24
- node_two.letter = :a
25
- end
26
-
27
- it 'returns true' do
28
- expect(node_one).to eq node_two
29
- end
30
- end
31
-
32
- context 'when the nodes have the same letter and are terminal' do
33
- before do
34
- node_one.letter = :a
35
- node_one.terminal!
36
-
37
- node_two.letter = :a
38
- node_two.terminal!
39
- end
40
-
41
- it 'returns true' do
42
- expect(node_one).to eq node_two
43
- end
44
- end
45
-
46
- context 'when the nodes have the same letter but are not both terminal' do
47
- before do
48
- node_one.letter = :a
49
- node_one.terminal!
50
-
51
- node_two.letter = :a
52
- end
53
-
54
- it 'returns false' do
55
- expect(node_one).not_to eq node_two
56
- end
57
- end
58
-
59
- context 'when the nodes have the same letter and the same children' do
60
- before do
61
- node_one.letter = :t
62
- add_words node_one, %w(hese hree hings)
63
-
64
- node_two.letter = :t
65
- add_words node_two, %w(hese hree hings)
66
- end
67
-
68
- it 'returns true' do
69
- expect(node_one).to eq node_two
70
- end
71
- end
72
-
73
- context 'when the nodes have the same letter but different children' do
74
- before do
75
- node_one.letter = :t
76
- add_words node_one, %w(hese wo)
77
-
78
- node_two.letter = :t
79
- add_words node_two, %w(hese hree hings)
80
- end
81
-
82
- it 'returns false' do
83
- expect(node_one).not_to eq node_two
84
- end
85
- end
86
- end
87
- end
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Rambling::Trie::Compressor do
6
- let(:compressor) { described_class.new }
7
-
8
- describe '#compress' do
9
- let(:node) { Rambling::Trie::Nodes::Raw.new }
10
-
11
- it 'compresses the node' do
12
- add_words node, %w(a few words hello hell)
13
- compressed = compressor.compress node
14
-
15
- expect(compressed.children_tree.keys).to eq %i(a f w h)
16
- end
17
-
18
- context 'with at least one word' do
19
- before { add_words node, %w(all the words) }
20
-
21
- it 'keeps the node letter nil' do
22
- compressed = compressor.compress node
23
-
24
- expect(compressed.letter).to be_nil
25
- end
26
- end
27
-
28
- context 'with a single word' do
29
- before { add_word node, 'all' }
30
-
31
- # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
32
- it 'compresses into a single node without children' do
33
- compressed = compressor.compress node
34
- compressed_node_a = compressed[:a]
35
-
36
- expect(compressed_node_a.letter).to eq :all
37
- expect(compressed_node_a.children.size).to eq 0
38
- expect(compressed_node_a).to be_terminal
39
- expect(compressed_node_a).to be_compressed
40
- end
41
- # rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
42
- end
43
-
44
- context 'with two words' do
45
- before { add_words node, %w(all ask) }
46
-
47
- # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
48
- it 'compresses into corresponding three nodes' do
49
- compressed = compressor.compress node
50
-
51
- expect(compressed[:a].letter).to eq :a
52
- expect(compressed[:a].children.size).to eq 2
53
-
54
- expect(compressed[:a][:l].letter).to eq :ll
55
- expect(compressed[:a][:s].letter).to eq :sk
56
-
57
- expect(compressed[:a][:l].children.size).to eq 0
58
- expect(compressed[:a][:s].children.size).to eq 0
59
-
60
- expect(compressed[:a][:l]).to be_terminal
61
- expect(compressed[:a][:s]).to be_terminal
62
-
63
- expect(compressed[:a][:l]).to be_compressed
64
- expect(compressed[:a][:s]).to be_compressed
65
- end
66
- # rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
67
- end
68
-
69
- # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
70
- it 'reassigns the parent nodes correctly' do
71
- add_words node, %w(repay rest repaint)
72
- compressed = compressor.compress node
73
-
74
- expect(compressed[:r].letter).to eq :re
75
- expect(compressed[:r].parent).to eq compressed
76
- expect(compressed[:r].children.size).to eq 2
77
-
78
- expect(compressed[:r][:p].letter).to eq :pa
79
- expect(compressed[:r][:p].parent).to eq compressed[:r]
80
- expect(compressed[:r][:p].children.size).to eq 2
81
-
82
- expect(compressed[:r][:s].letter).to eq :st
83
- expect(compressed[:r][:s].parent).to eq compressed[:r]
84
- expect(compressed[:r][:s].children.size).to eq 0
85
-
86
- expect(compressed[:r][:p][:y].letter).to eq :y
87
- expect(compressed[:r][:p][:y].parent).to eq compressed[:r][:p]
88
- expect(compressed[:r][:p][:y].children.size).to eq 0
89
-
90
- expect(compressed[:r][:p][:i].letter).to eq :int
91
- expect(compressed[:r][:p][:i].parent).to eq compressed[:r][:p]
92
- expect(compressed[:r][:p][:i].children.size).to eq 0
93
- end
94
- # rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
95
-
96
- # rubocop:disable RSpec/ExampleLength, RSpec/MultipleExpectations
97
- it 'does not compress terminal nodes' do
98
- add_words node, %w(you your yours)
99
- compressed = compressor.compress node
100
-
101
- expect(compressed[:y].letter).to eq :you
102
-
103
- expect(compressed[:y][:r].letter).to eq :r
104
- expect(compressed[:y][:r]).to be_compressed
105
-
106
- expect(compressed[:y][:r][:s].letter).to eq :s
107
- expect(compressed[:y][:r][:s]).to be_compressed
108
- end
109
- # rubocop:enable RSpec/ExampleLength, RSpec/MultipleExpectations
110
- end
111
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe Rambling::Trie::Configuration::Properties do
6
- let(:properties) { described_class.new }
7
-
8
- describe '.new' do
9
- it 'configures the serializer formats' do
10
- serializers = properties.serializers
11
- expect(serializers.formats).to match_array %i(marshal yaml yml zip)
12
- end
13
-
14
- # rubocop:disable RSpec/ExampleLength
15
- it 'configures the serializer providers' do
16
- serializers = properties.serializers
17
- expect(serializers.providers.to_a).to match_array [
18
- [:marshal, Rambling::Trie::Serializers::Marshal],
19
- [:yaml, Rambling::Trie::Serializers::Yaml],
20
- [:yml, Rambling::Trie::Serializers::Yaml],
21
- [:zip, Rambling::Trie::Serializers::Zip],
22
- ]
23
- end
24
- # rubocop:enable RSpec/ExampleLength
25
-
26
- it 'configures the reader formats' do
27
- readers = properties.readers
28
- expect(readers.formats).to match_array %i(txt)
29
- end
30
-
31
- it 'configures the reader providers' do
32
- readers = properties.readers
33
- expect(readers.providers.to_a).to match_array [
34
- [:txt, Rambling::Trie::Readers::PlainText],
35
- ]
36
- end
37
-
38
- it 'configures the compressor' do
39
- compressor = properties.compressor
40
- expect(compressor).to be_instance_of Rambling::Trie::Compressor
41
- end
42
-
43
- it 'configures the root_builder' do
44
- root = properties.root_builder.call
45
- expect(root).to be_instance_of Rambling::Trie::Nodes::Raw
46
- end
47
- end
48
-
49
- describe '#reset' do
50
- before do
51
- properties.serializers.add :test, 'test'
52
- properties.readers.add :test, 'test'
53
- end
54
-
55
- # rubocop:disable RSpec/MultipleExpectations
56
- it 'resets the serializers to initial values' do
57
- expect(properties.serializers.formats).to include :test
58
-
59
- properties.reset
60
-
61
- expect(properties.serializers.formats).not_to include :test
62
- end
63
- # rubocop:enable RSpec/MultipleExpectations
64
-
65
- # rubocop:disable RSpec/MultipleExpectations
66
- it 'resets the readers to initial values' do
67
- expect(properties.readers.formats).to include :test
68
-
69
- properties.reset
70
-
71
- expect(properties.readers.formats).not_to include :test
72
- end
73
- # rubocop:enable RSpec/MultipleExpectations
74
- end
75
- end