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