xqsr3 0.38.2 → 0.39.2

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