xqsr3 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +27 -0
  3. data/README.md +26 -0
  4. data/lib/xqsr3/command_line_utilities/map_option_string.rb +137 -0
  5. data/lib/xqsr3/containers/frequency_map.rb +473 -0
  6. data/lib/xqsr3/containers/multi_map.rb +383 -0
  7. data/lib/xqsr3/diagnostics/exception_utilities.rb +216 -0
  8. data/lib/xqsr3/doc_.rb +116 -0
  9. data/lib/xqsr3/extensions/enumerable.rb +4 -0
  10. data/lib/xqsr3/extensions/enumerable/collect_with_index.rb +71 -0
  11. data/lib/xqsr3/extensions/enumerable/unique.rb +102 -0
  12. data/lib/xqsr3/extensions/io.rb +3 -0
  13. data/lib/xqsr3/extensions/io/writelines.rb +66 -0
  14. data/lib/xqsr3/extensions/kernel.rb +3 -0
  15. data/lib/xqsr3/extensions/kernel/raise_with_options.rb +68 -0
  16. data/lib/xqsr3/extensions/string.rb +5 -0
  17. data/lib/xqsr3/extensions/string/ends_with.rb +8 -0
  18. data/lib/xqsr3/extensions/string/map_option_string.rb +8 -0
  19. data/lib/xqsr3/extensions/string/starts_with.rb +8 -0
  20. data/lib/xqsr3/extensions/string/to_symbol.rb +8 -0
  21. data/lib/xqsr3/extensions/test/unit.rb +5 -0
  22. data/lib/xqsr3/extensions/test/unit/assert_eql.rb +18 -0
  23. data/lib/xqsr3/extensions/test/unit/assert_not.rb +18 -0
  24. data/lib/xqsr3/extensions/test/unit/assert_not_eql.rb +18 -0
  25. data/lib/xqsr3/io/writelines.rb +192 -0
  26. data/lib/xqsr3/quality/parameter_checking.rb +343 -0
  27. data/lib/xqsr3/string_utilities/ends_with.rb +134 -0
  28. data/lib/xqsr3/string_utilities/starts_with.rb +127 -0
  29. data/lib/xqsr3/string_utilities/to_symbol.rb +145 -0
  30. data/lib/xqsr3/version.rb +68 -0
  31. data/test/unit/command_line_utilities/tc_map_option_string.rb +39 -0
  32. data/test/unit/command_line_utilities/ts_all.rb +13 -0
  33. data/test/unit/containers/tc_frequency_map.rb +738 -0
  34. data/test/unit/containers/tc_multi_map.rb +640 -0
  35. data/test/unit/containers/ts_all.rb +13 -0
  36. data/test/unit/diagnostics/tc_exception_utilities.rb +221 -0
  37. data/test/unit/diagnostics/ts_all.rb +13 -0
  38. data/test/unit/extensions/enumerable/tc_collect_with_index.rb +36 -0
  39. data/test/unit/extensions/enumerable/tc_unique.rb +47 -0
  40. data/test/unit/extensions/enumerable/ts_all.rb +13 -0
  41. data/test/unit/extensions/io/tc_writelines.rb +110 -0
  42. data/test/unit/extensions/io/ts_all.rb +13 -0
  43. data/test/unit/extensions/kernel/tc_raise_with_options.rb +239 -0
  44. data/test/unit/extensions/kernel/ts_all.rb +13 -0
  45. data/test/unit/extensions/string/tc_ends_with.rb +70 -0
  46. data/test/unit/extensions/string/tc_map_option_string.rb +37 -0
  47. data/test/unit/extensions/string/tc_starts_with.rb +70 -0
  48. data/test/unit/extensions/string/tc_to_symbol.rb +51 -0
  49. data/test/unit/extensions/string/ts_all.rb +13 -0
  50. data/test/unit/extensions/ts_all.rb +13 -0
  51. data/test/unit/io/tc_writelines.rb +200 -0
  52. data/test/unit/io/ts_all.rb +13 -0
  53. data/test/unit/quality/tc_parameter_checking.rb +181 -0
  54. data/test/unit/quality/ts_all.rb +13 -0
  55. data/test/unit/tc_version.rb +37 -0
  56. data/test/unit/ts_all.rb +13 -0
  57. metadata +101 -0
@@ -0,0 +1,39 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/command_line_utilities/map_option_string'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+ include ::Xqsr3::CommandLineUtilities
11
+
12
+ class Test_Xqsr3_CommandLineUtilities_map_option_string < Test::Unit::TestCase
13
+
14
+ def test_simple_uses
15
+
16
+ assert_nil MapOptionString.map_option_string_from_string 'abc', [ 'option-1', 'option-2' ]
17
+
18
+ assert_equal :abc, MapOptionString.map_option_string_from_string('abc', [ 'abc' ])
19
+
20
+ assert_equal :option_1, MapOptionString.map_option_string_from_string('option-1', [ 'option-1', 'option-2' ])
21
+ end
22
+
23
+ def test_shortcuts
24
+
25
+ option_strings = [ '[n]ame-only', '[f]ull-[p]ath' ]
26
+
27
+ assert_equal :name_only, MapOptionString.map_option_string_from_string('name-only', option_strings)
28
+ assert_equal :full_path, MapOptionString.map_option_string_from_string('full-path', option_strings)
29
+
30
+ assert_equal :name_only, MapOptionString.map_option_string_from_string('n', option_strings)
31
+ assert_equal :full_path, MapOptionString.map_option_string_from_string('fp', option_strings)
32
+
33
+ %w{ a m e - o l y u l p a t h }.each do |shortcut|
34
+
35
+ assert_nil MapOptionString.map_option_string_from_string(shortcut, option_strings)
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,13 @@
1
+ #! /usr/bin/ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_file = File.expand_path(__FILE__)
6
+ this_dir = File.expand_path(File.dirname(__FILE__))
7
+
8
+ # all tc_*rb in current directory
9
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
10
+
11
+ # all ts_*rb in immediate sub-directories
12
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
13
+
@@ -0,0 +1,738 @@
1
+ #! /usr/bin/ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../../lib')
4
+
5
+ require 'xqsr3/containers/frequency_map'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+ require 'test/unit'
9
+
10
+ include ::Xqsr3::Containers
11
+
12
+ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
13
+
14
+ def test_class_operator_subscript_1
15
+
16
+ fm1 = FrequencyMap[]
17
+
18
+ assert_equal 0, fm1.count
19
+ assert fm1.empty?
20
+ assert_equal 0, fm1.size
21
+ end
22
+
23
+ def test_class_operator_subscript_2
24
+
25
+ fm2 = FrequencyMap[ abc: 1, def: 2 ]
26
+
27
+ assert_equal 3, fm2.count
28
+ assert_not fm2.empty?
29
+ assert_equal 2, fm2.size
30
+ end
31
+
32
+ def test_class_operator_subscript_3
33
+
34
+ fm3 = FrequencyMap[ [ [ :abc, 1 ], [ :def, 2 ] ] ]
35
+
36
+ assert_equal 3, fm3.count
37
+ assert_not fm3.empty?
38
+ assert_equal 2, fm3.size
39
+
40
+ assert_raise(::TypeError) { FrequencyMap[ [ [ :abc, 1 ], [ :def, '2' ] ] ] }
41
+ assert_raise(::ArgumentError) { FrequencyMap[ [ [ :abc, 1 ], [ :def ] ] ] }
42
+ end
43
+
44
+ def test_class_operator_subscript_4
45
+
46
+ fm3 = FrequencyMap[ [ :abc, 1, :def, 2 ] ]
47
+
48
+ assert_equal 3, fm3.count
49
+ assert_not fm3.empty?
50
+ assert_equal 2, fm3.size
51
+
52
+ fm4 = FrequencyMap[ [] ]
53
+
54
+ assert_equal 0, fm4.count
55
+ assert fm4.empty?
56
+ assert_equal 0, fm4.size
57
+
58
+ assert_raise(::ArgumentError) { FrequencyMap[ [ :abc, 1, :def, '2' ] ] }
59
+ assert_raise(::ArgumentError) { FrequencyMap[ [ :abc, 1, :def ] ] }
60
+ end
61
+
62
+ def test_class_operator_subscript_5
63
+
64
+ assert_raise(::ArgumentError) { FrequencyMap[ [ :abc ] ] }
65
+ end
66
+
67
+ def test_class_operator_subscript_6
68
+
69
+ assert_raise(::TypeError) { FrequencyMap[ :abc ] }
70
+ end
71
+
72
+ def test_class_operator_subscript_7
73
+
74
+ fm3 = FrequencyMap[ :abc, 1, :def, 2 ]
75
+
76
+ assert_equal 3, fm3.count
77
+ assert_not fm3.empty?
78
+ assert_equal 2, fm3.size
79
+
80
+ fm4 = FrequencyMap[]
81
+
82
+ assert_equal 0, fm4.count
83
+ assert fm4.empty?
84
+ assert_equal 0, fm4.size
85
+
86
+ assert_raise(::ArgumentError) { FrequencyMap[ :abc, 1, :def, '2' ] }
87
+ assert_raise(::ArgumentError) { FrequencyMap[ :abc, 1, :def ] }
88
+ end
89
+
90
+ def test_class_operator_subscript_8
91
+
92
+ fm = FrequencyMap::ByElement[ :abc, :def, :abc, 1, :ghi, 'jkl', :abc, 1, 'jkl' ]
93
+
94
+ assert_equal 9, fm.count
95
+ assert_not fm.empty?
96
+ assert_equal 5, fm.size
97
+
98
+ assert_equal 3, fm[:abc]
99
+ assert_equal 1, fm[:def]
100
+ assert_equal 2, fm[1]
101
+ assert_equal 1, fm[:ghi]
102
+ assert_equal 2, fm['jkl']
103
+ end
104
+
105
+ def test_instance_operator_equals
106
+
107
+ fm1 = FrequencyMap.new
108
+ fm2 = FrequencyMap.new
109
+
110
+ assert fm1 == fm1
111
+ assert fm2 == fm2
112
+ assert fm1 == fm2
113
+
114
+ fm1 << :abc << :def
115
+
116
+ assert fm1 == fm1
117
+ assert fm2 == fm2
118
+ assert_not fm1 == fm2
119
+
120
+ fm2 << :def << :abc
121
+
122
+ assert fm1 == fm1
123
+ assert fm2 == fm2
124
+ assert fm1 == fm2
125
+
126
+ # can compare against Hash
127
+
128
+ fm1 = FrequencyMap.new
129
+ fm2 = Hash.new
130
+
131
+ assert fm1 == fm1
132
+ assert fm2 == fm2
133
+ assert fm1 == fm2
134
+
135
+ fm1 << :abc << :def
136
+
137
+ assert_not fm1 == fm2
138
+ assert fm1 == fm1
139
+ assert fm2 == fm2
140
+
141
+ fm2[:abc] = 1
142
+ fm2[:def] = 1
143
+
144
+ assert fm1 == fm1
145
+ assert fm2 == fm2
146
+ assert fm1 == fm2
147
+ end
148
+
149
+ def test_instance_operator_subscript
150
+
151
+ fm = FrequencyMap.new
152
+
153
+ assert_nil fm[:abc]
154
+ assert_nil fm[:def]
155
+
156
+ fm << :abc
157
+
158
+ assert_equal 1, fm[:abc]
159
+ assert_nil fm[:def]
160
+
161
+ fm << :def << :def << :def
162
+
163
+ assert_equal 1, fm[:abc]
164
+ assert_equal 3, fm[:def]
165
+ end
166
+
167
+ def test_instance_operator_subscript_assign
168
+
169
+ fm = FrequencyMap.new
170
+
171
+ fm[:abc] = 1
172
+
173
+ assert_equal 1, fm[:abc]
174
+
175
+ fm[:def] = 3
176
+
177
+ assert_equal 3, fm[:def]
178
+
179
+ fm[:abc] = 2
180
+
181
+ assert_equal 2, fm[:abc]
182
+ end
183
+
184
+ def test_assoc
185
+
186
+ fm = FrequencyMap.new
187
+
188
+ assert_nil fm.assoc :abc
189
+
190
+ fm << :abc
191
+
192
+ assert_equal [:abc, 1], fm.assoc(:abc)
193
+
194
+ fm << :abc
195
+
196
+ assert_equal [:abc, 2], fm.assoc(:abc)
197
+ end
198
+
199
+ def test_clear
200
+
201
+ fm = FrequencyMap.new
202
+
203
+ assert_nil fm['abc']
204
+ assert_equal 0, fm.count
205
+ assert fm.empty?
206
+ assert_equal 0, fm.size
207
+
208
+ fm << 'abc'
209
+
210
+ assert_not_nil fm['abc']
211
+ assert_equal 1, fm.count
212
+ assert_not fm.empty?
213
+ assert_equal 1, fm.size
214
+
215
+ fm.clear
216
+
217
+ assert_nil fm['abc']
218
+ assert_equal 0, fm.count
219
+ assert fm.empty?
220
+ assert_equal 0, fm.size
221
+ end
222
+
223
+ def test_count_and_delete
224
+
225
+ fm = FrequencyMap.new
226
+
227
+ assert_equal 0, fm.count
228
+
229
+ fm << :abc
230
+
231
+ assert_equal 1, fm.count
232
+
233
+ fm << :abc
234
+
235
+ assert_equal 2, fm.count
236
+
237
+ fm << :def
238
+
239
+ assert_equal 3, fm.count
240
+
241
+ fm.delete :ghi
242
+
243
+ assert_equal 3, fm.count
244
+
245
+ fm.delete :abc
246
+
247
+ assert_equal 1, fm.count
248
+ end
249
+
250
+ def test_count
251
+
252
+ test_count_and_delete
253
+ end
254
+
255
+ def test_default
256
+
257
+ fm = FrequencyMap.new
258
+
259
+ assert_nil fm.default
260
+ end
261
+
262
+ def test_delete
263
+
264
+ test_count_and_delete
265
+ end
266
+
267
+ def test_dup
268
+
269
+ fm1 = FrequencyMap.new
270
+ fm2 = fm1.dup
271
+
272
+ assert_equal fm1, fm2
273
+ assert_eql fm1, fm2
274
+
275
+ fm1 << :abc
276
+
277
+ assert_not_equal fm1, fm2
278
+ assert_not_eql fm1, fm2
279
+
280
+ fm3 = fm1.dup
281
+
282
+ assert_equal fm1, fm3
283
+ assert_eql fm1, fm3
284
+ end
285
+
286
+ def test_each
287
+
288
+ fm = FrequencyMap.new
289
+
290
+ fm << :def
291
+ fm << :abc << :abc << :abc << :abc
292
+ fm << :ghi << :ghi
293
+
294
+ r = []
295
+
296
+ fm.each do |k, v|
297
+
298
+ r << [k, v]
299
+ end
300
+
301
+ r.sort! { |a, b| a[0] <=> b[0] }
302
+
303
+ assert_equal 3, r.size
304
+ assert_equal [:abc, 4], r[0]
305
+ assert_equal [:def, 1], r[1]
306
+ assert_equal [:ghi, 2], r[2]
307
+ end
308
+
309
+ def test_each_by_frequency
310
+
311
+ fm = FrequencyMap.new
312
+
313
+ fm << :def
314
+ fm << :abc << :abc << :abc << :abc
315
+ fm << :ghi << :ghi
316
+
317
+ r = []
318
+
319
+ fm.each_by_frequency do |k, v|
320
+
321
+ r << [k, v]
322
+ end
323
+
324
+ assert_equal 3, r.size
325
+ assert_equal [:abc, 4], r[0]
326
+ assert_equal [:ghi, 2], r[1]
327
+ assert_equal [:def, 1], r[2]
328
+ end
329
+
330
+ def each_value
331
+
332
+ fm = FrequencyMap.new
333
+
334
+ fm << :def
335
+ fm << :abc << :abc << :abc << :abc
336
+ fm << :ghi << :ghi
337
+
338
+ r = []
339
+
340
+ fm.each_value do |v|
341
+
342
+ r << [v]
343
+ end
344
+
345
+ r.sort!
346
+
347
+ assert_equal 3, r.size
348
+ assert_equal [1, 2, 4], r
349
+ end
350
+
351
+ def each_with_index
352
+
353
+ fm = FrequencyMap.new
354
+
355
+ fm << :def
356
+ fm << :abc << :abc << :abc << :abc
357
+ fm << :ghi << :ghi
358
+
359
+ fm.each_with_index do |k, v, index|
360
+
361
+ case index
362
+ when 0
363
+ assert_equal :abc, k
364
+ assert_equal 2, v
365
+ when 1
366
+ assert_equal :def, k
367
+ assert_equal 1, v
368
+ else
369
+ assert false, "should never get here"
370
+ end
371
+ end
372
+ end
373
+
374
+ def test_empty
375
+
376
+ fm = FrequencyMap.new
377
+
378
+ assert fm.empty?
379
+
380
+ fm << :def
381
+
382
+ assert_not fm.empty?
383
+ assert_equal 1, fm.size
384
+ assert_equal 1, fm.count
385
+
386
+ fm.clear
387
+
388
+ assert fm.empty?
389
+
390
+ assert_equal 0, fm.size
391
+ assert_equal 0, fm.count
392
+ end
393
+
394
+ def test_eql?
395
+
396
+ fm1 = FrequencyMap.new
397
+ fm2 = FrequencyMap.new
398
+
399
+ assert fm1.eql? fm1
400
+ assert fm2.eql? fm2
401
+ assert fm1.eql? fm2
402
+
403
+ fm1 << :abc << :def
404
+
405
+ assert fm1.eql? fm1
406
+ assert fm2.eql? fm2
407
+ assert_not fm1.eql? fm2
408
+
409
+ fm2 << :def << :abc
410
+
411
+ assert fm1.eql? fm1
412
+ assert fm2.eql? fm2
413
+ assert fm1.eql? fm2
414
+
415
+ assert_equal 2, fm1.size
416
+ assert_equal 2, fm1.count
417
+ end
418
+
419
+ def test_fetch
420
+
421
+ fm = FrequencyMap.new
422
+
423
+ assert_raise(::KeyError) { fm.fetch(:does_not_exist) }
424
+ assert_equal 2, fm.fetch(:does_not_exist, 2)
425
+ assert_raise(::TypeError) { fm.fetch(:does_not_exist, :wrong_type) }
426
+ assert_equal 33, fm.fetch(:does_not_exist) { |k| 33 }
427
+ assert_equal 34, fm.fetch(:does_not_exist) { 34 }
428
+
429
+ fm << :abc << :abc << :abc
430
+
431
+ assert_equal 3, fm.fetch(:abc)
432
+ assert_equal 3, fm.fetch(:abc, 1)
433
+ assert_equal 3, (fm.fetch(:abc) { |k| 33 })
434
+
435
+ assert_equal 1, fm.size
436
+ assert_equal 3, fm.count
437
+ end
438
+
439
+ def test_flatten
440
+
441
+ fm = FrequencyMap.new
442
+
443
+ assert_equal [], fm.flatten
444
+
445
+ fm << :def
446
+
447
+ assert_equal [:def, 1], fm.flatten
448
+
449
+ fm << :def
450
+
451
+ assert_equal [:def, 2], fm.flatten
452
+
453
+ fm << :abc
454
+
455
+ assert_equal [:def, 2, :abc, 1], fm.flatten
456
+ end
457
+
458
+ def test_has_key?
459
+
460
+ fm = FrequencyMap.new
461
+
462
+ assert_not fm.has_key? nil
463
+ assert_not fm.has_key? :abc
464
+ assert_not fm.has_key? 'abc'
465
+
466
+ fm << :abc
467
+
468
+ assert_not fm.has_key? nil
469
+ assert fm.has_key? :abc
470
+ assert_not fm.has_key? 'abc'
471
+
472
+ fm << 'abc'
473
+
474
+ assert_not fm.has_key? nil
475
+ assert fm.has_key? :abc
476
+ assert fm.has_key? 'abc'
477
+ end
478
+
479
+ def test_has_value?
480
+
481
+ fm = FrequencyMap.new
482
+
483
+ assert_not fm.has_value? 1
484
+ assert_not fm.has_value? 2
485
+ assert_raise(::TypeError) { fm.has_value? 1.1 }
486
+
487
+ fm << :abc
488
+
489
+ assert fm.has_value? 1
490
+ assert_not fm.has_value? 2
491
+
492
+ fm << :abc
493
+
494
+ assert_not fm.has_value? 1
495
+ assert fm.has_value? 2
496
+ end
497
+
498
+ def test_key
499
+
500
+ fm = FrequencyMap.new
501
+
502
+ assert_nil fm.key 1
503
+ assert_nil fm.key 2
504
+ assert_raise(::TypeError) { fm.key 1.1 }
505
+
506
+ fm << :abc
507
+
508
+ assert_equal :abc, fm.key(1)
509
+ assert_not_equal :abc, fm.key(2)
510
+
511
+ fm << :abc
512
+
513
+ assert_not_equal :abc, fm.key(1)
514
+ assert_equal :abc, fm.key(2)
515
+ end
516
+
517
+ def test_length_and_size
518
+
519
+ fm = FrequencyMap.new
520
+
521
+ assert_equal 0, fm.length
522
+ assert_equal 0, fm.size
523
+
524
+ fm << :abc
525
+
526
+ assert_equal 1, fm.length
527
+ assert_equal 1, fm.size
528
+
529
+ fm << :abc
530
+
531
+ assert_equal 1, fm.length
532
+ assert_equal 1, fm.size
533
+
534
+ fm << :def
535
+
536
+ assert_equal 2, fm.length
537
+ assert_equal 2, fm.size
538
+
539
+ fm.delete :abc
540
+
541
+ assert_equal 1, fm.length
542
+ assert_equal 1, fm.size
543
+ end
544
+
545
+ def test_length
546
+
547
+ test_length_and_size
548
+ end
549
+
550
+ def test_merge
551
+
552
+ fm1 = FrequencyMap.new
553
+ fm2 = FrequencyMap.new
554
+
555
+ fm1 << :abc << :def << :ghi << :ghi
556
+ fm2 << :abc << :ghi << :jkl << :jkl
557
+
558
+ fm3 = fm1.merge fm2
559
+
560
+ assert_equal 8, fm3.count
561
+ assert_equal 4, fm3.size
562
+
563
+ assert_equal 2, fm3[:abc]
564
+ assert_equal 1, fm3[:def]
565
+ assert_equal 3, fm3[:ghi]
566
+ assert_equal 2, fm3[:jkl]
567
+ end
568
+
569
+ def test_merge!
570
+
571
+ fm1 = FrequencyMap.new
572
+ fm2 = FrequencyMap.new
573
+
574
+ fm1 << :abc << :def << :ghi << :ghi
575
+ fm2 << :abc << :ghi << :jkl << :jkl
576
+
577
+ fm1.merge! fm2
578
+
579
+ assert_equal 8, fm1.count
580
+ assert_equal 4, fm1.size
581
+
582
+ assert_equal 2, fm1[:abc]
583
+ assert_equal 1, fm1[:def]
584
+ assert_equal 3, fm1[:ghi]
585
+ assert_equal 2, fm1[:jkl]
586
+ end
587
+
588
+ def test_push
589
+
590
+ fm = FrequencyMap.new
591
+
592
+ assert fm.empty?
593
+
594
+ fm.push :abc
595
+ fm.push :def, 2
596
+ fm.push :ghi, 1
597
+ fm.push :ghi, 0
598
+ fm.push :ghi, 1
599
+
600
+ assert_equal 5, fm.count
601
+ assert_not fm.empty?
602
+ assert_equal 3, fm.size
603
+
604
+ assert_equal 1, fm[:abc]
605
+ assert_equal 2, fm[:def]
606
+ assert_equal 2, fm[:ghi]
607
+ end
608
+
609
+ def test_shift
610
+
611
+ fm = FrequencyMap.new
612
+
613
+ assert_nil fm.shift
614
+
615
+
616
+ fm << :abc
617
+
618
+ assert_equal 1, fm.count
619
+ assert_not fm.empty?
620
+ assert_equal 1, fm.size
621
+
622
+ r = fm.shift
623
+
624
+ assert_equal 0, fm.count
625
+ assert fm.empty?
626
+ assert_equal 0, fm.size
627
+
628
+ assert_equal [:abc, 1], r
629
+
630
+
631
+ fm << :def << :def
632
+
633
+ assert_equal 2, fm.count
634
+ assert_not fm.empty?
635
+ assert_equal 1, fm.size
636
+
637
+ r = fm.shift
638
+
639
+ assert_equal 0, fm.count
640
+ assert fm.empty?
641
+ assert_equal 0, fm.size
642
+
643
+ assert_equal [:def, 2], r
644
+
645
+
646
+ fm << :abc << :def << :def
647
+
648
+ assert_equal 3, fm.count
649
+ assert_not fm.empty?
650
+ assert_equal 2, fm.size
651
+
652
+ r = fm.shift
653
+
654
+ assert_equal 2, fm.count
655
+ assert_not fm.empty?
656
+ assert_equal 1, fm.size
657
+
658
+ assert_equal [:abc, 1], r
659
+
660
+ r = fm.shift
661
+
662
+ assert_equal 0, fm.count
663
+ assert fm.empty?
664
+ assert_equal 0, fm.size
665
+
666
+ assert_equal [:def, 2], r
667
+ end
668
+
669
+ def test_size
670
+
671
+ test_length_and_size
672
+ end
673
+
674
+ def test_store
675
+
676
+ fm = FrequencyMap.new
677
+
678
+ assert_equal 0, fm.count
679
+ assert fm.empty?
680
+ assert_equal 0, fm.size
681
+
682
+ fm.store :abc, 1
683
+
684
+ assert_equal 1, fm.count
685
+ assert_not fm.empty?
686
+ assert_equal 1, fm.size
687
+
688
+ fm.store :def, 2
689
+
690
+ assert_equal 3, fm.count
691
+ assert_not fm.empty?
692
+ assert_equal 2, fm.size
693
+
694
+ assert_raise(::TypeError) { fm.store :ghi, :blah }
695
+ end
696
+
697
+ def test_to_a
698
+
699
+ fm = FrequencyMap.new
700
+
701
+ assert_equal [], fm.to_a
702
+
703
+ fm << :abc << :abc
704
+
705
+ assert_equal [[:abc, 2]], fm.to_a
706
+
707
+ fm << :def << :def << :def
708
+
709
+ assert_equal [[:abc, 2], [:def, 3]], fm.to_a
710
+ end
711
+
712
+ def test_to_h
713
+
714
+ fm = FrequencyMap.new
715
+
716
+ assert_equal Hash.new, fm.to_h
717
+
718
+ fm << :abc << :abc
719
+
720
+ assert_equal ({:abc => 2}), fm.to_h
721
+
722
+ fm << :def << :def << :def
723
+
724
+ assert_equal ({:abc => 2, :def => 3}), fm.to_h
725
+ end
726
+
727
+ def test_values
728
+
729
+ fm = FrequencyMap.new
730
+
731
+ assert_equal [], fm.values
732
+
733
+ fm << :abc << :def << :def << :ghi
734
+
735
+ assert_equal [1, 2, 1], fm.values
736
+ end
737
+ end
738
+