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