xqsr3 0.38.2 → 0.39.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -6
- data/examples/count_word_frequencies.md +12 -12
- data/examples/count_word_frequencies.rb +4 -4
- data/lib/xqsr3/array_utilities/join_with_or.rb +47 -47
- data/lib/xqsr3/array_utilities.rb +2 -2
- data/lib/xqsr3/command_line_utilities/map_option_string.rb +60 -60
- data/lib/xqsr3/command_line_utilities.rb +2 -2
- data/lib/xqsr3/containers/frequency_map.rb +399 -399
- data/lib/xqsr3/containers/multi_map.rb +448 -448
- data/lib/xqsr3/containers.rb +3 -3
- data/lib/xqsr3/conversion/bool_parser.rb +51 -51
- data/lib/xqsr3/conversion/integer_parser.rb +87 -87
- data/lib/xqsr3/conversion.rb +3 -3
- data/lib/xqsr3/diagnostics/exception_utilities.rb +145 -145
- data/lib/xqsr3/diagnostics/exceptions/with_cause.rb +90 -90
- data/lib/xqsr3/diagnostics/inspect_builder.rb +80 -80
- data/lib/xqsr3/diagnostics.rb +3 -3
- data/lib/xqsr3/doc_.rb +130 -130
- data/lib/xqsr3/extensions/array/join_with_or.rb +9 -9
- data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +12 -12
- data/lib/xqsr3/extensions/enumerable/detect_map.rb +35 -35
- data/lib/xqsr3/extensions/enumerable/unique.rb +29 -28
- data/lib/xqsr3/extensions/hash/deep_transform.rb +1 -1
- data/lib/xqsr3/extensions/hash/except.rb +16 -16
- data/lib/xqsr3/extensions/hash/has_match.rb +10 -10
- data/lib/xqsr3/extensions/hash/match.rb +10 -10
- data/lib/xqsr3/extensions/hash/slice.rb +11 -11
- data/lib/xqsr3/extensions/hash.rb +1 -1
- data/lib/xqsr3/extensions/integer/to_s_grp.rb +118 -0
- data/lib/xqsr3/extensions/integer.rb +3 -0
- data/lib/xqsr3/extensions/io/writelines.rb +28 -28
- data/lib/xqsr3/extensions/kernel/integer.rb +20 -20
- data/lib/xqsr3/extensions/kernel/raise_with_options.rb +8 -8
- data/lib/xqsr3/extensions/kernel.rb +1 -0
- data/lib/xqsr3/extensions/string/ends_with.rb +1 -1
- data/lib/xqsr3/extensions/string/map_option_string.rb +4 -4
- data/lib/xqsr3/extensions/string/nil_if_empty.rb +1 -1
- data/lib/xqsr3/extensions/string/nil_if_whitespace.rb +1 -1
- data/lib/xqsr3/extensions/string/quote_if.rb +1 -1
- data/lib/xqsr3/extensions/string/starts_with.rb +1 -1
- data/lib/xqsr3/extensions/string/to_bool.rb +8 -8
- data/lib/xqsr3/extensions/string/to_symbol.rb +1 -1
- data/lib/xqsr3/extensions/string/truncate.rb +1 -1
- data/lib/xqsr3/extensions/test/unit/assert_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_false.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_raise_with_message.rb +61 -61
- data/lib/xqsr3/extensions/test/unit/assert_subclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_superclass_of.rb +10 -7
- data/lib/xqsr3/extensions/test/unit/assert_true.rb +9 -6
- data/lib/xqsr3/extensions/test/unit/assert_type_has_instance_methods.rb +39 -36
- data/lib/xqsr3/extensions.rb +5 -5
- data/lib/xqsr3/hash_utilities/deep_transform.rb +65 -65
- data/lib/xqsr3/hash_utilities/key_matching.rb +77 -77
- data/lib/xqsr3/hash_utilities.rb +3 -3
- data/lib/xqsr3/internal_/test_unit_version_.rb +83 -83
- data/lib/xqsr3/io/writelines.rb +122 -120
- data/lib/xqsr3/quality/parameter_checking.rb +445 -445
- data/lib/xqsr3/quality.rb +2 -2
- data/lib/xqsr3/string_utilities/ends_with.rb +59 -59
- data/lib/xqsr3/string_utilities/nil_if_empty.rb +28 -28
- data/lib/xqsr3/string_utilities/nil_if_whitespace.rb +29 -29
- data/lib/xqsr3/string_utilities/quote_if.rb +50 -50
- data/lib/xqsr3/string_utilities/starts_with.rb +59 -59
- data/lib/xqsr3/string_utilities/to_symbol.rb +75 -75
- data/lib/xqsr3/string_utilities/truncate.rb +55 -55
- data/lib/xqsr3/string_utilities.rb +8 -8
- data/lib/xqsr3/version.rb +12 -12
- data/test/performance/frequency_map.rb +12 -12
- data/test/scratch/test_assert_raise_with_message.rb +11 -11
- data/test/unit/array_utilities/tc_join_with_or.rb +140 -140
- data/test/unit/command_line_utilities/tc_map_option_string.rb +18 -18
- data/test/unit/containers/tc_frequency_map.rb +591 -591
- data/test/unit/containers/tc_multi_map.rb +558 -558
- data/test/unit/conversion/tc_integer_parser.rb +72 -72
- data/test/unit/conversion/tc_to_bool.rb +25 -25
- data/test/unit/diagnostics/exceptions/tc_with_cause.rb +165 -165
- data/test/unit/diagnostics/tc_exception_utilities.rb +156 -156
- data/test/unit/extensions/enumerable/tc_collect_with_index.rb +14 -14
- data/test/unit/extensions/enumerable/tc_detect_map.rb +20 -20
- data/test/unit/extensions/enumerable/tc_unique.rb +34 -34
- data/test/unit/extensions/hash/tc_deep_transform.rb +22 -22
- data/test/unit/extensions/hash/tc_except.rb +28 -28
- data/test/unit/extensions/hash/tc_slice.rb +13 -13
- data/test/unit/extensions/integer/tc_to_s_grp.rb +60 -0
- data/test/unit/extensions/integer/ts_all.rb +12 -0
- data/test/unit/extensions/io/tc_writelines.rb +149 -77
- data/test/unit/extensions/kernel/tc_integer.rb +75 -75
- data/test/unit/extensions/kernel/tc_raise_with_options.rb +155 -155
- data/test/unit/extensions/object/tc_inspect.rb +50 -50
- data/test/unit/extensions/string/tc_bool.tb +24 -24
- data/test/unit/extensions/string/tc_ends_with.rb +53 -53
- data/test/unit/extensions/string/tc_map_option_string.rb +15 -15
- data/test/unit/extensions/string/tc_nil_if_empty.rb +8 -8
- data/test/unit/extensions/string/tc_nil_if_whitespace.rb +8 -8
- data/test/unit/extensions/string/tc_quote_if.rb +18 -18
- data/test/unit/extensions/string/tc_starts_with.rb +53 -53
- data/test/unit/extensions/string/tc_to_symbol.rb +26 -26
- data/test/unit/extensions/string/tc_truncate.rb +18 -18
- data/test/unit/extensions/test/unit/tc_assert_raise_with_message.rb +16 -16
- data/test/unit/extensions/test/unit/tc_assert_subclass_of.rb +9 -9
- data/test/unit/extensions/test/unit/tc_assert_superclass_of.rb +9 -9
- data/test/unit/hash_utilities/tc_has_match.rb +70 -70
- data/test/unit/hash_utilities/tc_match.rb +83 -83
- data/test/unit/io/tc_writelines.rb +166 -106
- data/test/unit/quality/tc_parameter_checking.rb +389 -389
- data/test/unit/string_utilities/tc_truncate.rb +27 -27
- data/test/unit/tc_version.rb +15 -15
- metadata +6 -2
@@ -11,923 +11,923 @@ include ::Xqsr3::Containers
|
|
11
11
|
|
12
12
|
class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
14
|
+
def test_class_operator_subscript_1
|
15
15
|
|
16
|
-
|
16
|
+
fm1 = FrequencyMap[]
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
assert_equal 0, fm1.count
|
19
|
+
assert fm1.empty?
|
20
|
+
assert_equal 0, fm1.size
|
21
21
|
|
22
|
-
|
22
|
+
assert_nil fm1.default
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
assert_match (/^#<Xqsr3::Containers::FrequencyMap:0x\d+:\s*@count\(\w+\)=0; @elements\(Hash\)={}\s*>$/), fm1.inspect
|
25
|
+
end
|
26
26
|
|
27
|
-
|
27
|
+
def test_class_operator_subscript_2
|
28
28
|
|
29
|
-
|
29
|
+
fm2 = FrequencyMap[ abc: 1, def: 2 ]
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
assert_equal 3, fm2.count
|
32
|
+
assert_not fm2.empty?
|
33
|
+
assert_equal 2, fm2.size
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
assert_match (/^#<Xqsr3::Containers::FrequencyMap:0x\d+:\s*@count\(\w+\)=3; @elements\(Hash\)={.*abc.*def.*}\s*>$/), fm2.inspect
|
36
|
+
end
|
37
37
|
|
38
|
-
|
38
|
+
def test_class_operator_subscript_3
|
39
39
|
|
40
|
-
|
40
|
+
fm3 = FrequencyMap[ [ [ :abc, 1 ], [ :def, 2 ] ] ]
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
assert_equal 3, fm3.count
|
43
|
+
assert_not fm3.empty?
|
44
|
+
assert_equal 2, fm3.size
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
assert_raise(::TypeError) { FrequencyMap[ [ [ :abc, 1 ], [ :def, '2' ] ] ] }
|
47
|
+
assert_raise(::ArgumentError) { FrequencyMap[ [ [ :abc, 1 ], [ :def ] ] ] }
|
48
|
+
end
|
49
49
|
|
50
|
-
|
50
|
+
def test_class_operator_subscript_4
|
51
51
|
|
52
|
-
|
52
|
+
fm3 = FrequencyMap[ [ :abc, 1, :def, 2 ] ]
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
assert_equal 3, fm3.count
|
55
|
+
assert_not fm3.empty?
|
56
|
+
assert_equal 2, fm3.size
|
57
57
|
|
58
|
-
|
58
|
+
fm4 = FrequencyMap[ [] ]
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
assert_equal 0, fm4.count
|
61
|
+
assert fm4.empty?
|
62
|
+
assert_equal 0, fm4.size
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
assert_raise(::ArgumentError) { FrequencyMap[ [ :abc, 1, :def, '2' ] ] }
|
65
|
+
assert_raise(::ArgumentError) { FrequencyMap[ [ :abc, 1, :def ] ] }
|
66
|
+
end
|
67
67
|
|
68
|
-
|
68
|
+
def test_class_operator_subscript_5
|
69
69
|
|
70
|
-
|
71
|
-
|
70
|
+
assert_raise(::ArgumentError) { FrequencyMap[ [ :abc ] ] }
|
71
|
+
end
|
72
72
|
|
73
|
-
|
73
|
+
def test_class_operator_subscript_6
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
assert_raise(::TypeError) { FrequencyMap[ :abc ] }
|
76
|
+
end
|
77
77
|
|
78
|
-
|
78
|
+
def test_class_operator_subscript_7
|
79
79
|
|
80
|
-
|
80
|
+
fm3 = FrequencyMap[ :abc, 1, :def, 2 ]
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
assert_equal 3, fm3.count
|
83
|
+
assert_not fm3.empty?
|
84
|
+
assert_equal 2, fm3.size
|
85
85
|
|
86
|
-
|
86
|
+
fm4 = FrequencyMap[]
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
assert_equal 0, fm4.count
|
89
|
+
assert fm4.empty?
|
90
|
+
assert_equal 0, fm4.size
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
92
|
+
assert_raise(::ArgumentError) { FrequencyMap[ :abc, 1, :def, '2' ] }
|
93
|
+
assert_raise(::ArgumentError) { FrequencyMap[ :abc, 1, :def ] }
|
94
|
+
end
|
95
95
|
|
96
|
-
|
96
|
+
def test_class_operator_subscript_8
|
97
97
|
|
98
|
-
|
98
|
+
fm = FrequencyMap::ByElement[ :abc, :def, :abc, 1, :ghi, 'jkl', :abc, 1, 'jkl' ]
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
100
|
+
assert_equal 9, fm.count
|
101
|
+
assert_not fm.empty?
|
102
|
+
assert_equal 5, fm.size
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
assert_equal 3, fm[:abc]
|
105
|
+
assert_equal 1, fm[:def]
|
106
|
+
assert_equal 2, fm[1]
|
107
|
+
assert_equal 1, fm[:ghi]
|
108
|
+
assert_equal 2, fm['jkl']
|
109
|
+
end
|
110
110
|
|
111
|
-
|
111
|
+
def test_class_operator_subscript_9
|
112
112
|
|
113
|
-
|
113
|
+
fm = FrequencyMap::ByElement[ 'abc', 'def', 'abc', :x, 'x', :y ]
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
115
|
+
assert_false fm.empty? # => false
|
116
|
+
assert_equal 5, fm.size # => 5
|
117
|
+
assert_equal 6, fm.count # => 6
|
118
|
+
assert_equal 2, fm['abc'] # => 2
|
119
|
+
assert_equal 1, fm['def'] # => 1
|
120
|
+
assert_equal 0, fm['ghi'] # => 0
|
121
|
+
assert_equal 1, fm['x'] # => 1
|
122
|
+
assert_equal 0, fm['y'] # => 0
|
123
|
+
assert_equal 0, fm['z'] # => 0
|
124
|
+
assert_equal 1, fm[:x] # => 1
|
125
|
+
assert_equal 1, fm[:y] # => 1
|
126
|
+
assert_equal 0, fm[:z] # => 0
|
127
127
|
|
128
|
-
|
128
|
+
fm.push 'abc'
|
129
129
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
assert_false fm.empty?
|
131
|
+
assert_equal 5, fm.size
|
132
|
+
assert_equal 7, fm.count
|
133
|
+
assert_equal 3, fm['abc']
|
134
134
|
|
135
|
-
|
135
|
+
fm.push 'abc', 2
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
assert_false fm.empty?
|
138
|
+
assert_equal 5, fm.size
|
139
|
+
assert_equal 9, fm.count
|
140
|
+
assert_equal 5, fm['abc']
|
141
141
|
|
142
|
-
|
142
|
+
fm.push 'abc', -4
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
144
|
+
assert_false fm.empty?
|
145
|
+
assert_equal 5, fm.size
|
146
|
+
assert_equal 5, fm.count
|
147
|
+
assert_equal 1, fm['abc']
|
148
148
|
|
149
|
-
|
149
|
+
fm.push 'abc', -1
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
151
|
+
assert_false fm.empty?
|
152
|
+
assert_equal 4, fm.size
|
153
|
+
assert_equal 4, fm.count
|
154
|
+
assert_equal 0, fm['abc']
|
155
|
+
end
|
156
156
|
|
157
|
-
|
157
|
+
def test_instance_operator_equals
|
158
158
|
|
159
|
-
|
160
|
-
|
159
|
+
fm1 = FrequencyMap.new
|
160
|
+
fm2 = FrequencyMap.new
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
assert fm1 == fm1
|
163
|
+
assert fm2 == fm2
|
164
|
+
assert fm1 == fm2
|
165
165
|
|
166
|
-
|
166
|
+
fm1 << :abc << :def
|
167
167
|
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
assert fm1 == fm1
|
169
|
+
assert fm2 == fm2
|
170
|
+
assert_not fm1 == fm2
|
171
171
|
|
172
|
-
|
172
|
+
fm2 << :def << :abc
|
173
173
|
|
174
|
-
|
175
|
-
|
176
|
-
|
174
|
+
assert fm1 == fm1
|
175
|
+
assert fm2 == fm2
|
176
|
+
assert fm1 == fm2
|
177
177
|
|
178
|
-
|
178
|
+
# can compare against Hash
|
179
179
|
|
180
|
-
|
181
|
-
|
180
|
+
fm1 = FrequencyMap.new
|
181
|
+
fm2 = Hash.new
|
182
182
|
|
183
|
-
|
184
|
-
|
185
|
-
|
183
|
+
assert fm1 == fm1
|
184
|
+
assert fm2 == fm2
|
185
|
+
assert fm1 == fm2
|
186
186
|
|
187
|
-
|
187
|
+
fm1 << :abc << :def
|
188
188
|
|
189
|
-
|
190
|
-
|
191
|
-
|
189
|
+
assert_not fm1 == fm2
|
190
|
+
assert fm1 == fm1
|
191
|
+
assert fm2 == fm2
|
192
192
|
|
193
|
-
|
194
|
-
|
193
|
+
fm2[:abc] = 1
|
194
|
+
fm2[:def] = 1
|
195
195
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
196
|
+
assert fm1 == fm1
|
197
|
+
assert fm2 == fm2
|
198
|
+
assert fm1 == fm2
|
199
|
+
end
|
200
200
|
|
201
|
-
|
201
|
+
def test_instance_operator_subscript
|
202
202
|
|
203
|
-
|
203
|
+
fm = FrequencyMap.new
|
204
204
|
|
205
|
-
|
206
|
-
|
205
|
+
assert_equal 0, fm[:abc]
|
206
|
+
assert_equal 0, fm[:def]
|
207
207
|
|
208
|
-
|
208
|
+
fm << :abc
|
209
209
|
|
210
|
-
|
211
|
-
|
210
|
+
assert_equal 1, fm[:abc]
|
211
|
+
assert_equal 0, fm[:def]
|
212
212
|
|
213
|
-
|
213
|
+
fm << :def << :def << :def
|
214
214
|
|
215
|
-
|
216
|
-
|
217
|
-
|
215
|
+
assert_equal 1, fm[:abc]
|
216
|
+
assert_equal 3, fm[:def]
|
217
|
+
end
|
218
218
|
|
219
|
-
|
219
|
+
def test_instance_operator_subscript_assign
|
220
220
|
|
221
|
-
|
221
|
+
fm = FrequencyMap.new
|
222
222
|
|
223
|
-
|
223
|
+
fm[:abc] = 1
|
224
224
|
|
225
|
-
|
225
|
+
assert_equal 1, fm[:abc]
|
226
226
|
|
227
|
-
|
227
|
+
fm[:def] = 3
|
228
228
|
|
229
|
-
|
229
|
+
assert_equal 3, fm[:def]
|
230
230
|
|
231
|
-
|
231
|
+
fm[:abc] = 2
|
232
232
|
|
233
|
-
|
234
|
-
|
233
|
+
assert_equal 2, fm[:abc]
|
234
|
+
end
|
235
235
|
|
236
|
-
|
236
|
+
def test_assoc
|
237
237
|
|
238
|
-
|
238
|
+
fm = FrequencyMap.new
|
239
239
|
|
240
|
-
|
240
|
+
assert_nil fm.assoc :abc
|
241
241
|
|
242
|
-
|
242
|
+
fm << :abc
|
243
243
|
|
244
|
-
|
244
|
+
assert_equal [:abc, 1], fm.assoc(:abc)
|
245
245
|
|
246
|
-
|
246
|
+
fm << :abc
|
247
247
|
|
248
|
-
|
249
|
-
|
248
|
+
assert_equal [:abc, 2], fm.assoc(:abc)
|
249
|
+
end
|
250
250
|
|
251
|
-
|
251
|
+
def test_clear
|
252
252
|
|
253
|
-
|
253
|
+
fm = FrequencyMap.new
|
254
254
|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
255
|
+
assert_equal 0, fm['abc']
|
256
|
+
assert_equal 0, fm.count
|
257
|
+
assert fm.empty?
|
258
|
+
assert_equal 0, fm.size
|
259
259
|
|
260
|
-
|
260
|
+
fm << 'abc'
|
261
261
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
262
|
+
assert_not_nil fm['abc']
|
263
|
+
assert_equal 1, fm.count
|
264
|
+
assert_not fm.empty?
|
265
|
+
assert_equal 1, fm.size
|
266
266
|
|
267
|
-
|
267
|
+
fm.clear
|
268
268
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
269
|
+
assert_equal 0, fm['abc']
|
270
|
+
assert_equal 0, fm.count
|
271
|
+
assert fm.empty?
|
272
|
+
assert_equal 0, fm.size
|
273
|
+
end
|
274
274
|
|
275
|
-
|
275
|
+
def test_count_and_delete
|
276
276
|
|
277
|
-
|
277
|
+
fm = FrequencyMap.new
|
278
278
|
|
279
|
-
|
279
|
+
assert_equal 0, fm.count
|
280
280
|
|
281
|
-
|
281
|
+
fm << :abc
|
282
282
|
|
283
|
-
|
283
|
+
assert_equal 1, fm.count
|
284
284
|
|
285
|
-
|
285
|
+
fm << :abc
|
286
286
|
|
287
|
-
|
287
|
+
assert_equal 2, fm.count
|
288
288
|
|
289
|
-
|
289
|
+
fm << :def
|
290
290
|
|
291
|
-
|
291
|
+
assert_equal 3, fm.count
|
292
292
|
|
293
|
-
|
293
|
+
fm.delete :ghi
|
294
294
|
|
295
|
-
|
295
|
+
assert_equal 3, fm.count
|
296
296
|
|
297
|
-
|
297
|
+
fm.delete :abc
|
298
298
|
|
299
|
-
|
300
|
-
|
299
|
+
assert_equal 1, fm.count
|
300
|
+
end
|
301
301
|
|
302
|
-
|
302
|
+
def test_count
|
303
303
|
|
304
|
-
|
305
|
-
|
304
|
+
test_count_and_delete
|
305
|
+
end
|
306
306
|
|
307
|
-
|
307
|
+
def test_default
|
308
308
|
|
309
|
-
|
309
|
+
fm = FrequencyMap.new
|
310
310
|
|
311
|
-
|
312
|
-
|
311
|
+
assert_nil fm.default
|
312
|
+
end
|
313
313
|
|
314
|
-
|
314
|
+
def test_delete
|
315
315
|
|
316
|
-
|
317
|
-
|
316
|
+
test_count_and_delete
|
317
|
+
end
|
318
318
|
|
319
|
-
|
319
|
+
def test_dup
|
320
320
|
|
321
|
-
|
322
|
-
|
321
|
+
fm1 = FrequencyMap.new
|
322
|
+
fm2 = fm1.dup
|
323
323
|
|
324
|
-
|
325
|
-
|
324
|
+
assert_equal fm1, fm2
|
325
|
+
assert_eql fm1, fm2
|
326
326
|
|
327
|
-
|
327
|
+
fm1 << :abc
|
328
328
|
|
329
|
-
|
330
|
-
|
329
|
+
assert_not_equal fm1, fm2
|
330
|
+
assert_not_eql fm1, fm2
|
331
331
|
|
332
|
-
|
332
|
+
fm3 = fm1.dup
|
333
333
|
|
334
|
-
|
335
|
-
|
336
|
-
|
334
|
+
assert_equal fm1, fm3
|
335
|
+
assert_eql fm1, fm3
|
336
|
+
end
|
337
337
|
|
338
|
-
|
338
|
+
def test_each_WITH_BLOCK
|
339
339
|
|
340
|
-
|
340
|
+
fm = FrequencyMap.new
|
341
341
|
|
342
|
-
|
343
|
-
|
344
|
-
|
342
|
+
fm << :def
|
343
|
+
fm << :abc << :abc << :abc << :abc
|
344
|
+
fm << :ghi << :ghi
|
345
345
|
|
346
|
-
|
346
|
+
r = []
|
347
347
|
|
348
|
-
|
348
|
+
fm.each do |k, v|
|
349
349
|
|
350
|
-
|
351
|
-
|
350
|
+
r << [k, v]
|
351
|
+
end
|
352
352
|
|
353
|
-
|
353
|
+
r.sort! { |a, b| a[0] <=> b[0] }
|
354
354
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
355
|
+
assert_equal 3, r.size
|
356
|
+
assert_equal [:abc, 4], r[0]
|
357
|
+
assert_equal [:def, 1], r[1]
|
358
|
+
assert_equal [:ghi, 2], r[2]
|
359
|
+
end
|
360
360
|
|
361
|
-
|
361
|
+
def test_each_WITHOUT_BLOCK
|
362
362
|
|
363
|
-
|
363
|
+
fm = FrequencyMap.new
|
364
364
|
|
365
|
-
|
366
|
-
|
367
|
-
|
365
|
+
fm << :def
|
366
|
+
fm << :abc << :abc << :abc << :abc
|
367
|
+
fm << :ghi << :ghi
|
368
368
|
|
369
|
-
|
369
|
+
r = fm.each.to_a
|
370
370
|
|
371
|
-
|
371
|
+
r.sort! { |a, b| a[0] <=> b[0] }
|
372
372
|
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
373
|
+
assert_equal 3, r.size
|
374
|
+
assert_equal [:abc, 4], r[0]
|
375
|
+
assert_equal [:def, 1], r[1]
|
376
|
+
assert_equal [:ghi, 2], r[2]
|
377
|
+
end
|
378
378
|
|
379
|
-
|
379
|
+
def test_each_by_key_WITH_BLOCK
|
380
380
|
|
381
|
-
|
381
|
+
fm = FrequencyMap.new
|
382
382
|
|
383
|
-
|
384
|
-
|
385
|
-
|
383
|
+
fm << :def
|
384
|
+
fm << :abc << :abc << :abc << :abc
|
385
|
+
fm << :ghi << :ghi
|
386
386
|
|
387
|
-
|
387
|
+
r = []
|
388
388
|
|
389
|
-
|
389
|
+
fm.each_by_key do |k, v|
|
390
390
|
|
391
|
-
|
392
|
-
|
391
|
+
r << [k, v]
|
392
|
+
end
|
393
393
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
394
|
+
assert_equal 3, r.size
|
395
|
+
assert_equal [:abc, 4], r[0]
|
396
|
+
assert_equal [:def, 1], r[1]
|
397
|
+
assert_equal [:ghi, 2], r[2]
|
398
|
+
end
|
399
399
|
|
400
|
-
|
400
|
+
def test_each_by_key_WITHOUT_BLOCK
|
401
401
|
|
402
|
-
|
402
|
+
fm = FrequencyMap.new
|
403
403
|
|
404
|
-
|
405
|
-
|
406
|
-
|
404
|
+
fm << :def
|
405
|
+
fm << :abc << :abc << :abc << :abc
|
406
|
+
fm << :ghi << :ghi
|
407
407
|
|
408
|
-
|
408
|
+
r = fm.each_by_key.to_a
|
409
409
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
410
|
+
assert_equal 3, r.size
|
411
|
+
assert_equal [:abc, 4], r[0]
|
412
|
+
assert_equal [:def, 1], r[1]
|
413
|
+
assert_equal [:ghi, 2], r[2]
|
414
|
+
end
|
415
415
|
|
416
|
-
|
416
|
+
def test_each_by_frequency_WITH_BLOCK
|
417
417
|
|
418
|
-
|
418
|
+
fm = FrequencyMap.new
|
419
419
|
|
420
|
-
|
421
|
-
|
422
|
-
|
420
|
+
fm << :def
|
421
|
+
fm << :abc << :abc << :abc << :abc
|
422
|
+
fm << :ghi << :ghi
|
423
423
|
|
424
|
-
|
424
|
+
r = []
|
425
425
|
|
426
|
-
|
426
|
+
fm.each_by_frequency do |k, v|
|
427
427
|
|
428
|
-
|
429
|
-
|
428
|
+
r << [k, v]
|
429
|
+
end
|
430
430
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
431
|
+
assert_equal 3, r.size
|
432
|
+
assert_equal [:abc, 4], r[0]
|
433
|
+
assert_equal [:ghi, 2], r[1]
|
434
|
+
assert_equal [:def, 1], r[2]
|
435
|
+
end
|
436
436
|
|
437
|
-
|
437
|
+
def test_each_by_frequency_WITHOUT_BLOCK
|
438
438
|
|
439
|
-
|
439
|
+
fm = FrequencyMap.new
|
440
440
|
|
441
|
-
|
442
|
-
|
443
|
-
|
441
|
+
fm << :def
|
442
|
+
fm << :abc << :abc << :abc << :abc
|
443
|
+
fm << :ghi << :ghi
|
444
444
|
|
445
|
-
|
445
|
+
r = fm.each_by_frequency.to_a
|
446
446
|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
447
|
+
assert_equal 3, r.size
|
448
|
+
assert_equal [:abc, 4], r[0]
|
449
|
+
assert_equal [:ghi, 2], r[1]
|
450
|
+
assert_equal [:def, 1], r[2]
|
451
|
+
end
|
452
452
|
|
453
|
-
|
453
|
+
def test_each_value_WITH_BLOCK
|
454
454
|
|
455
|
-
|
455
|
+
fm = FrequencyMap.new
|
456
456
|
|
457
|
-
|
458
|
-
|
459
|
-
|
457
|
+
fm << :def
|
458
|
+
fm << :abc << :abc << :abc << :abc
|
459
|
+
fm << :ghi << :ghi
|
460
460
|
|
461
|
-
|
461
|
+
r = []
|
462
462
|
|
463
|
-
|
463
|
+
fm.each_value do |v|
|
464
464
|
|
465
|
-
|
466
|
-
|
465
|
+
r << v
|
466
|
+
end
|
467
467
|
|
468
|
-
|
468
|
+
r.sort!
|
469
469
|
|
470
|
-
|
471
|
-
|
472
|
-
|
470
|
+
assert_equal 3, r.size
|
471
|
+
assert_equal [1, 2, 4], r
|
472
|
+
end
|
473
473
|
|
474
|
-
|
474
|
+
def test_each_value_WITHOUT_BLOCK
|
475
475
|
|
476
|
-
|
476
|
+
fm = FrequencyMap.new
|
477
477
|
|
478
|
-
|
479
|
-
|
480
|
-
|
478
|
+
fm << :def
|
479
|
+
fm << :abc << :abc << :abc << :abc
|
480
|
+
fm << :ghi << :ghi
|
481
481
|
|
482
|
-
|
482
|
+
r = fm.each_value.to_a
|
483
483
|
|
484
|
-
|
484
|
+
r.sort!
|
485
485
|
|
486
|
-
|
487
|
-
|
488
|
-
|
486
|
+
assert_equal 3, r.size
|
487
|
+
assert_equal [1, 2, 4], r
|
488
|
+
end
|
489
489
|
|
490
|
-
|
490
|
+
def test_each_with_index_WITH_BLOCK
|
491
491
|
|
492
|
-
|
492
|
+
fm = FrequencyMap.new
|
493
493
|
|
494
|
-
|
495
|
-
|
496
|
-
|
494
|
+
fm << :def
|
495
|
+
fm << :abc << :abc << :abc << :abc
|
496
|
+
fm << :ghi << :ghi
|
497
497
|
|
498
|
-
|
499
|
-
|
498
|
+
indexes = []
|
499
|
+
kvs = {}
|
500
500
|
|
501
|
-
|
501
|
+
fm.each_with_index do |kv, index|
|
502
502
|
|
503
|
-
|
504
|
-
|
503
|
+
k = kv[0]
|
504
|
+
v = kv[1]
|
505
505
|
|
506
|
-
|
506
|
+
indexes << index
|
507
507
|
|
508
|
-
|
509
|
-
|
508
|
+
kvs[k] = v
|
509
|
+
end
|
510
510
|
|
511
|
-
|
512
|
-
|
513
|
-
|
511
|
+
assert_equal [ 0, 1, 2 ], indexes
|
512
|
+
assert_equal Hash[ :abc, 4, :def, 1, :ghi, 2 ], kvs
|
513
|
+
end
|
514
514
|
|
515
|
-
|
515
|
+
def test_empty
|
516
516
|
|
517
|
-
|
517
|
+
fm = FrequencyMap.new
|
518
518
|
|
519
|
-
|
519
|
+
assert fm.empty?
|
520
520
|
|
521
|
-
|
521
|
+
fm << :def
|
522
522
|
|
523
|
-
|
524
|
-
|
525
|
-
|
523
|
+
assert_not fm.empty?
|
524
|
+
assert_equal 1, fm.size
|
525
|
+
assert_equal 1, fm.count
|
526
526
|
|
527
|
-
|
527
|
+
fm.clear
|
528
528
|
|
529
|
-
|
529
|
+
assert fm.empty?
|
530
530
|
|
531
|
-
|
532
|
-
|
533
|
-
|
531
|
+
assert_equal 0, fm.size
|
532
|
+
assert_equal 0, fm.count
|
533
|
+
end
|
534
534
|
|
535
|
-
|
536
|
-
|
535
|
+
def test_op_equal
|
536
|
+
# `==` evaluates logical equality (except for `Object`)
|
537
537
|
|
538
|
-
|
539
|
-
|
538
|
+
fm1 = FrequencyMap.new
|
539
|
+
fm2 = FrequencyMap.new
|
540
540
|
|
541
|
-
|
542
|
-
|
543
|
-
|
541
|
+
assert fm1 == fm1
|
542
|
+
assert fm2 == fm2
|
543
|
+
assert fm1 == fm2
|
544
544
|
|
545
|
-
|
545
|
+
fm1 << :abc << :def
|
546
546
|
|
547
|
-
|
548
|
-
|
549
|
-
|
547
|
+
assert fm1 == fm1
|
548
|
+
assert fm2 == fm2
|
549
|
+
assert_not fm1 == fm2
|
550
550
|
|
551
|
-
|
551
|
+
fm2 << :def << :abc
|
552
552
|
|
553
|
-
|
554
|
-
|
555
|
-
|
553
|
+
assert fm1 == fm1
|
554
|
+
assert fm2 == fm2
|
555
|
+
assert fm1 == fm2
|
556
556
|
|
557
|
-
|
558
|
-
|
559
|
-
|
557
|
+
assert_equal 2, fm1.size
|
558
|
+
assert_equal 2, fm1.count
|
559
|
+
end
|
560
560
|
|
561
|
-
|
562
|
-
|
561
|
+
def test_eql?
|
562
|
+
# `eql?` evaluates equality based on #hash
|
563
563
|
|
564
|
-
|
565
|
-
|
564
|
+
fm1 = FrequencyMap.new
|
565
|
+
fm2 = FrequencyMap.new
|
566
566
|
|
567
|
-
|
568
|
-
|
569
|
-
|
567
|
+
assert fm1.eql? fm1
|
568
|
+
assert fm2.eql? fm2
|
569
|
+
assert fm1.eql? fm2
|
570
570
|
|
571
|
-
|
571
|
+
fm1 << :abc << :def
|
572
572
|
|
573
|
-
|
574
|
-
|
575
|
-
|
573
|
+
assert fm1.eql? fm1
|
574
|
+
assert fm2.eql? fm2
|
575
|
+
assert_not fm1.eql? fm2
|
576
576
|
|
577
|
-
|
577
|
+
fm2 << :def << :abc
|
578
578
|
|
579
|
-
|
580
|
-
|
581
|
-
|
579
|
+
assert fm1.eql? fm1
|
580
|
+
assert fm2.eql? fm2
|
581
|
+
assert fm1.eql? fm2
|
582
582
|
|
583
|
-
|
584
|
-
|
585
|
-
|
583
|
+
assert_equal 2, fm1.size
|
584
|
+
assert_equal 2, fm1.count
|
585
|
+
end
|
586
586
|
|
587
|
-
|
588
|
-
|
587
|
+
def test_equal
|
588
|
+
# `eql?` evaluates identity
|
589
589
|
|
590
|
-
|
591
|
-
|
590
|
+
fm1 = FrequencyMap.new
|
591
|
+
fm2 = FrequencyMap.new
|
592
592
|
|
593
|
-
|
594
|
-
|
595
|
-
|
593
|
+
assert fm1.equal? fm1
|
594
|
+
assert fm2.equal? fm2
|
595
|
+
assert_not fm1.equal? fm2
|
596
596
|
|
597
|
-
|
597
|
+
fm1 << :abc << :def
|
598
598
|
|
599
|
-
|
600
|
-
|
601
|
-
|
599
|
+
assert fm1.equal? fm1
|
600
|
+
assert fm2.equal? fm2
|
601
|
+
assert_not fm1.equal? fm2
|
602
602
|
|
603
|
-
|
603
|
+
fm2 << :def << :abc
|
604
604
|
|
605
|
-
|
606
|
-
|
607
|
-
|
605
|
+
assert fm1.equal? fm1
|
606
|
+
assert fm2.equal? fm2
|
607
|
+
assert_not fm1.equal? fm2
|
608
608
|
|
609
|
-
|
610
|
-
|
611
|
-
|
609
|
+
assert_equal 2, fm1.size
|
610
|
+
assert_equal 2, fm1.count
|
611
|
+
end
|
612
612
|
|
613
|
-
|
613
|
+
def test_fetch
|
614
614
|
|
615
|
-
|
615
|
+
fm = FrequencyMap.new
|
616
616
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
617
|
+
assert_raise(::KeyError) { fm.fetch(:does_not_exist) }
|
618
|
+
assert_equal 2, fm.fetch(:does_not_exist, 2)
|
619
|
+
assert_raise(::TypeError) { fm.fetch(:does_not_exist, :wrong_type) }
|
620
|
+
assert_equal 33, fm.fetch(:does_not_exist) { |k| 33 }
|
621
|
+
assert_equal 34, fm.fetch(:does_not_exist) { 34 }
|
622
622
|
|
623
|
-
|
623
|
+
fm << :abc << :abc << :abc
|
624
624
|
|
625
|
-
|
626
|
-
|
627
|
-
|
625
|
+
assert_equal 3, fm.fetch(:abc)
|
626
|
+
assert_equal 3, fm.fetch(:abc, 1)
|
627
|
+
assert_equal 3, (fm.fetch(:abc) { |k| 33 })
|
628
628
|
|
629
|
-
|
630
|
-
|
631
|
-
|
629
|
+
assert_equal 1, fm.size
|
630
|
+
assert_equal 3, fm.count
|
631
|
+
end
|
632
632
|
|
633
|
-
|
633
|
+
def test_flatten
|
634
634
|
|
635
|
-
|
635
|
+
fm = FrequencyMap.new
|
636
636
|
|
637
|
-
|
637
|
+
assert_equal [], fm.flatten
|
638
638
|
|
639
|
-
|
639
|
+
fm << :def
|
640
640
|
|
641
|
-
|
641
|
+
assert_equal [:def, 1], fm.flatten
|
642
642
|
|
643
|
-
|
643
|
+
fm << :def
|
644
644
|
|
645
|
-
|
645
|
+
assert_equal [:def, 2], fm.flatten
|
646
646
|
|
647
|
-
|
647
|
+
fm << :abc
|
648
648
|
|
649
|
-
|
650
|
-
|
649
|
+
assert_equal [:def, 2, :abc, 1], fm.flatten
|
650
|
+
end
|
651
651
|
|
652
|
-
|
652
|
+
def test_has_key?
|
653
653
|
|
654
|
-
|
654
|
+
fm = FrequencyMap.new
|
655
655
|
|
656
|
-
|
657
|
-
|
658
|
-
|
656
|
+
assert_not fm.has_key? nil
|
657
|
+
assert_not fm.has_key? :abc
|
658
|
+
assert_not fm.has_key? 'abc'
|
659
659
|
|
660
|
-
|
660
|
+
fm << :abc
|
661
661
|
|
662
|
-
|
663
|
-
|
664
|
-
|
662
|
+
assert_not fm.has_key? nil
|
663
|
+
assert fm.has_key? :abc
|
664
|
+
assert_not fm.has_key? 'abc'
|
665
665
|
|
666
|
-
|
666
|
+
fm << 'abc'
|
667
667
|
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
668
|
+
assert_not fm.has_key? nil
|
669
|
+
assert fm.has_key? :abc
|
670
|
+
assert fm.has_key? 'abc'
|
671
|
+
end
|
672
672
|
|
673
|
-
|
673
|
+
def test_has_value?
|
674
674
|
|
675
|
-
|
675
|
+
fm = FrequencyMap.new
|
676
676
|
|
677
|
-
|
678
|
-
|
679
|
-
|
677
|
+
assert_not fm.has_value? 1
|
678
|
+
assert_not fm.has_value? 2
|
679
|
+
assert_raise(::TypeError) { fm.has_value? 1.1 }
|
680
680
|
|
681
|
-
|
681
|
+
fm << :abc
|
682
682
|
|
683
|
-
|
684
|
-
|
683
|
+
assert fm.has_value? 1
|
684
|
+
assert_not fm.has_value? 2
|
685
685
|
|
686
|
-
|
686
|
+
fm << :abc
|
687
687
|
|
688
|
-
|
689
|
-
|
690
|
-
|
688
|
+
assert_not fm.has_value? 1
|
689
|
+
assert fm.has_value? 2
|
690
|
+
end
|
691
691
|
|
692
|
-
|
692
|
+
def test_key
|
693
693
|
|
694
|
-
|
694
|
+
fm = FrequencyMap.new
|
695
695
|
|
696
|
-
|
697
|
-
|
698
|
-
|
696
|
+
assert_nil fm.key 1
|
697
|
+
assert_nil fm.key 2
|
698
|
+
assert_raise(::TypeError) { fm.key 1.1 }
|
699
699
|
|
700
|
-
|
700
|
+
fm << :abc
|
701
701
|
|
702
|
-
|
703
|
-
|
702
|
+
assert_equal :abc, fm.key(1)
|
703
|
+
assert_not_equal :abc, fm.key(2)
|
704
704
|
|
705
|
-
|
705
|
+
fm << :abc
|
706
706
|
|
707
|
-
|
708
|
-
|
709
|
-
|
707
|
+
assert_not_equal :abc, fm.key(1)
|
708
|
+
assert_equal :abc, fm.key(2)
|
709
|
+
end
|
710
710
|
|
711
|
-
|
711
|
+
def test_length_and_size
|
712
712
|
|
713
|
-
|
713
|
+
fm = FrequencyMap.new
|
714
714
|
|
715
|
-
|
716
|
-
|
715
|
+
assert_equal 0, fm.length
|
716
|
+
assert_equal 0, fm.size
|
717
717
|
|
718
|
-
|
718
|
+
fm << :abc
|
719
719
|
|
720
|
-
|
721
|
-
|
720
|
+
assert_equal 1, fm.length
|
721
|
+
assert_equal 1, fm.size
|
722
722
|
|
723
|
-
|
723
|
+
fm << :abc
|
724
724
|
|
725
|
-
|
726
|
-
|
725
|
+
assert_equal 1, fm.length
|
726
|
+
assert_equal 1, fm.size
|
727
727
|
|
728
|
-
|
728
|
+
fm << :def
|
729
729
|
|
730
|
-
|
731
|
-
|
730
|
+
assert_equal 2, fm.length
|
731
|
+
assert_equal 2, fm.size
|
732
732
|
|
733
|
-
|
733
|
+
fm.delete :abc
|
734
734
|
|
735
|
-
|
736
|
-
|
737
|
-
|
735
|
+
assert_equal 1, fm.length
|
736
|
+
assert_equal 1, fm.size
|
737
|
+
end
|
738
738
|
|
739
|
-
|
739
|
+
def test_length
|
740
740
|
|
741
|
-
|
742
|
-
|
741
|
+
test_length_and_size
|
742
|
+
end
|
743
743
|
|
744
|
-
|
744
|
+
def test_merge
|
745
745
|
|
746
|
-
|
747
|
-
|
746
|
+
fm1 = FrequencyMap.new
|
747
|
+
fm2 = FrequencyMap.new
|
748
748
|
|
749
|
-
|
750
|
-
|
749
|
+
fm1 << :abc << :def << :ghi << :ghi
|
750
|
+
fm2 << :abc << :ghi << :jkl << :jkl
|
751
751
|
|
752
|
-
|
752
|
+
fm3 = fm1.merge fm2
|
753
753
|
|
754
|
-
|
755
|
-
|
754
|
+
assert_equal 8, fm3.count
|
755
|
+
assert_equal 4, fm3.size
|
756
756
|
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
757
|
+
assert_equal 2, fm3[:abc]
|
758
|
+
assert_equal 1, fm3[:def]
|
759
|
+
assert_equal 3, fm3[:ghi]
|
760
|
+
assert_equal 2, fm3[:jkl]
|
761
|
+
end
|
762
762
|
|
763
|
-
|
763
|
+
def test_merge!
|
764
764
|
|
765
|
-
|
766
|
-
|
765
|
+
fm1 = FrequencyMap.new
|
766
|
+
fm2 = FrequencyMap.new
|
767
767
|
|
768
|
-
|
769
|
-
|
768
|
+
fm1 << :abc << :def << :ghi << :ghi
|
769
|
+
fm2 << :abc << :ghi << :jkl << :jkl
|
770
770
|
|
771
|
-
|
771
|
+
fm1.merge! fm2
|
772
772
|
|
773
|
-
|
774
|
-
|
773
|
+
assert_equal 8, fm1.count
|
774
|
+
assert_equal 4, fm1.size
|
775
775
|
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
776
|
+
assert_equal 2, fm1[:abc]
|
777
|
+
assert_equal 1, fm1[:def]
|
778
|
+
assert_equal 3, fm1[:ghi]
|
779
|
+
assert_equal 2, fm1[:jkl]
|
780
|
+
end
|
781
781
|
|
782
|
-
|
782
|
+
def test_push
|
783
783
|
|
784
|
-
|
784
|
+
fm = FrequencyMap.new
|
785
785
|
|
786
|
-
|
786
|
+
assert fm.empty?
|
787
787
|
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
788
|
+
fm.push :abc
|
789
|
+
fm.push :def, 2
|
790
|
+
fm.push :ghi, 1
|
791
|
+
fm.push :ghi, 0
|
792
|
+
fm.push :ghi, 1
|
793
793
|
|
794
|
-
|
795
|
-
|
796
|
-
|
794
|
+
assert_equal 5, fm.count
|
795
|
+
assert_not fm.empty?
|
796
|
+
assert_equal 3, fm.size
|
797
797
|
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
798
|
+
assert_equal 1, fm[:abc]
|
799
|
+
assert_equal 2, fm[:def]
|
800
|
+
assert_equal 2, fm[:ghi]
|
801
|
+
end
|
802
802
|
|
803
|
-
|
803
|
+
def test_shift
|
804
804
|
|
805
|
-
|
805
|
+
fm = FrequencyMap.new
|
806
806
|
|
807
|
-
|
807
|
+
assert_nil fm.shift
|
808
808
|
|
809
809
|
|
810
|
-
|
810
|
+
fm << :abc
|
811
811
|
|
812
|
-
|
813
|
-
|
814
|
-
|
812
|
+
assert_equal 1, fm.count
|
813
|
+
assert_not fm.empty?
|
814
|
+
assert_equal 1, fm.size
|
815
815
|
|
816
|
-
|
816
|
+
r = fm.shift
|
817
817
|
|
818
|
-
|
819
|
-
|
820
|
-
|
818
|
+
assert_equal 0, fm.count
|
819
|
+
assert fm.empty?
|
820
|
+
assert_equal 0, fm.size
|
821
821
|
|
822
|
-
|
822
|
+
assert_equal [:abc, 1], r
|
823
823
|
|
824
824
|
|
825
|
-
|
825
|
+
fm << :def << :def
|
826
826
|
|
827
|
-
|
828
|
-
|
829
|
-
|
827
|
+
assert_equal 2, fm.count
|
828
|
+
assert_not fm.empty?
|
829
|
+
assert_equal 1, fm.size
|
830
830
|
|
831
|
-
|
831
|
+
r = fm.shift
|
832
832
|
|
833
|
-
|
834
|
-
|
835
|
-
|
833
|
+
assert_equal 0, fm.count
|
834
|
+
assert fm.empty?
|
835
|
+
assert_equal 0, fm.size
|
836
836
|
|
837
|
-
|
837
|
+
assert_equal [:def, 2], r
|
838
838
|
|
839
839
|
|
840
|
-
|
840
|
+
fm << :abc << :def << :def
|
841
841
|
|
842
|
-
|
843
|
-
|
844
|
-
|
842
|
+
assert_equal 3, fm.count
|
843
|
+
assert_not fm.empty?
|
844
|
+
assert_equal 2, fm.size
|
845
845
|
|
846
|
-
|
846
|
+
r = fm.shift
|
847
847
|
|
848
|
-
|
849
|
-
|
850
|
-
|
848
|
+
assert_equal 2, fm.count
|
849
|
+
assert_not fm.empty?
|
850
|
+
assert_equal 1, fm.size
|
851
851
|
|
852
|
-
|
852
|
+
assert_equal [:abc, 1], r
|
853
853
|
|
854
|
-
|
854
|
+
r = fm.shift
|
855
855
|
|
856
|
-
|
857
|
-
|
858
|
-
|
856
|
+
assert_equal 0, fm.count
|
857
|
+
assert fm.empty?
|
858
|
+
assert_equal 0, fm.size
|
859
859
|
|
860
|
-
|
861
|
-
|
860
|
+
assert_equal [:def, 2], r
|
861
|
+
end
|
862
862
|
|
863
|
-
|
863
|
+
def test_size
|
864
864
|
|
865
|
-
|
866
|
-
|
865
|
+
test_length_and_size
|
866
|
+
end
|
867
867
|
|
868
|
-
|
868
|
+
def test_store
|
869
869
|
|
870
|
-
|
870
|
+
fm = FrequencyMap.new
|
871
871
|
|
872
|
-
|
873
|
-
|
874
|
-
|
872
|
+
assert_equal 0, fm.count
|
873
|
+
assert fm.empty?
|
874
|
+
assert_equal 0, fm.size
|
875
875
|
|
876
|
-
|
876
|
+
fm.store :abc, 1
|
877
877
|
|
878
|
-
|
879
|
-
|
880
|
-
|
878
|
+
assert_equal 1, fm.count
|
879
|
+
assert_not fm.empty?
|
880
|
+
assert_equal 1, fm.size
|
881
881
|
|
882
|
-
|
882
|
+
fm.store :def, 2
|
883
883
|
|
884
|
-
|
885
|
-
|
886
|
-
|
884
|
+
assert_equal 3, fm.count
|
885
|
+
assert_not fm.empty?
|
886
|
+
assert_equal 2, fm.size
|
887
887
|
|
888
|
-
|
889
|
-
|
888
|
+
assert_raise(::TypeError) { fm.store :ghi, :blah }
|
889
|
+
end
|
890
890
|
|
891
|
-
|
891
|
+
def test_to_a
|
892
892
|
|
893
|
-
|
893
|
+
fm = FrequencyMap.new
|
894
894
|
|
895
|
-
|
895
|
+
assert_equal [], fm.to_a
|
896
896
|
|
897
|
-
|
897
|
+
fm << :abc << :abc
|
898
898
|
|
899
|
-
|
899
|
+
assert_equal [[:abc, 2]], fm.to_a
|
900
900
|
|
901
|
-
|
901
|
+
fm << :def << :def << :def
|
902
902
|
|
903
|
-
|
904
|
-
|
903
|
+
assert_equal [[:abc, 2], [:def, 3]], fm.to_a
|
904
|
+
end
|
905
905
|
|
906
|
-
|
906
|
+
def test_to_h
|
907
907
|
|
908
|
-
|
908
|
+
fm = FrequencyMap.new
|
909
909
|
|
910
|
-
|
910
|
+
assert_equal Hash.new, fm.to_h
|
911
911
|
|
912
|
-
|
912
|
+
fm << :abc << :abc
|
913
913
|
|
914
|
-
|
914
|
+
assert_equal ({:abc => 2}), fm.to_h
|
915
915
|
|
916
|
-
|
916
|
+
fm << :def << :def << :def
|
917
917
|
|
918
|
-
|
919
|
-
|
918
|
+
assert_equal ({:abc => 2, :def => 3}), fm.to_h
|
919
|
+
end
|
920
920
|
|
921
|
-
|
921
|
+
def test_values
|
922
922
|
|
923
|
-
|
923
|
+
fm = FrequencyMap.new
|
924
924
|
|
925
|
-
|
925
|
+
assert_equal [], fm.values
|
926
926
|
|
927
|
-
|
927
|
+
fm << :abc << :def << :def << :ghi
|
928
928
|
|
929
|
-
|
930
|
-
|
929
|
+
assert_equal [1, 2, 1], fm.values
|
930
|
+
end
|
931
931
|
end
|
932
932
|
|
933
933
|
|