xqsr3 0.38.0 → 0.38.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e4daad1c3c67fdf61c583a51ba736ff81e75b80
4
- data.tar.gz: d6d61c42b272907440cd1050b24d86be9cada0b9
3
+ metadata.gz: 893916b4985f2cf4aacd3880f28d9199b3137f49
4
+ data.tar.gz: d611a888f54fc3d6bee966a040530637bdfe2423
5
5
  SHA512:
6
- metadata.gz: 3a5986a93e709f33a02cfc1c90343b0f520ab4960c8b42b97df96fc71a34debfd41932a2012e98afcd6392e5d37b2b694bc7f6fc4fcefbd9c25b6a3587c8d5dc
7
- data.tar.gz: 0d7d35382e452b1f104d04da69c7113e9f59e157357ff78efbaa0c9cb9f3a92c181122792b8fafcbb9ac5c6c6cb9c7da2e2ca432d02b1e55c5e4c93616baaa5e
6
+ metadata.gz: 222348a3e0621835acbb5df342e2625eb6f6c7d355b59e9aded4e105e3acdbfe27a13cff0af939964ecde0eab65f16a5bebd8560afb71781a653c98ba981cc0b
7
+ data.tar.gz: efd82ceb69653fcc88954b3fb03267d3719e00642de1c7a2de564fe008751e0476be9625da6037af8bdcc1aecbf242ceced924f29403858a9d5a3b8eff861391
@@ -285,9 +285,13 @@ class FrequencyMap
285
285
  # keys must be created and sorted from which enumeration is directed
286
286
  def each_by_key
287
287
 
288
- @elements.keys.sort.each do |key|
288
+ sorted_elements = @elements.sort { |a, b| a[0] <=> b[0] }
289
289
 
290
- yield key, @elements[key]
290
+ return sorted_elements.each unless block_given?
291
+
292
+ sorted_elements.each do |k, v|
293
+
294
+ yield k, v
291
295
  end
292
296
  end
293
297
 
@@ -298,22 +302,13 @@ class FrequencyMap
298
302
  # and map all entries into it in order to achieve the ordering
299
303
  def each_by_frequency
300
304
 
301
- tm = {}
302
- @elements.each do |element, frequency|
303
-
304
- tm[frequency] = [] unless tm.has_key?(frequency)
305
+ ar = @elements.to_a.sort { |a, b| b[1] <=> a[1] }
305
306
 
306
- tm[frequency].push element
307
- end
308
-
309
- keys = tm.keys.sort.reverse
310
- keys.each do |frequency|
307
+ return ar.each unless block_given?
311
308
 
312
- elements = tm[frequency].sort
313
- elements.each do |element|
309
+ ar.each do |k, v|
314
310
 
315
- yield element, frequency
316
- end
311
+ yield k, v
317
312
  end
318
313
  end
319
314
 
data/lib/xqsr3/version.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for Xqsr3 library
6
6
  #
7
7
  # Created: 3rd April 2016
8
- # Updated: 25th July 2022
8
+ # Updated: 26th July 2022
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/xqsr3
11
11
  #
@@ -51,7 +51,7 @@
51
51
  module Xqsr3
52
52
 
53
53
  # Current version of the Xqsr3 library
54
- VERSION = '0.38.0'
54
+ VERSION = '0.38.1'
55
55
 
56
56
  private
57
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -335,7 +335,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
335
335
  assert_eql fm1, fm3
336
336
  end
337
337
 
338
- def test_each
338
+ def test_each_WITH_BLOCK
339
339
 
340
340
  fm = FrequencyMap.new
341
341
 
@@ -358,7 +358,25 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
358
358
  assert_equal [:ghi, 2], r[2]
359
359
  end
360
360
 
361
- def test_each_by_key
361
+ def test_each_WITHOUT_BLOCK
362
+
363
+ fm = FrequencyMap.new
364
+
365
+ fm << :def
366
+ fm << :abc << :abc << :abc << :abc
367
+ fm << :ghi << :ghi
368
+
369
+ r = fm.each.to_a
370
+
371
+ r.sort! { |a, b| a[0] <=> b[0] }
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
378
+
379
+ def test_each_by_key_WITH_BLOCK
362
380
 
363
381
  fm = FrequencyMap.new
364
382
 
@@ -379,7 +397,23 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
379
397
  assert_equal [:ghi, 2], r[2]
380
398
  end
381
399
 
382
- def test_each_by_frequency
400
+ def test_each_by_key_WITHOUT_BLOCK
401
+
402
+ fm = FrequencyMap.new
403
+
404
+ fm << :def
405
+ fm << :abc << :abc << :abc << :abc
406
+ fm << :ghi << :ghi
407
+
408
+ r = fm.each_by_key.to_a
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
415
+
416
+ def test_each_by_frequency_WITH_BLOCK
383
417
 
384
418
  fm = FrequencyMap.new
385
419
 
@@ -400,7 +434,23 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
400
434
  assert_equal [:def, 1], r[2]
401
435
  end
402
436
 
403
- def each_value
437
+ def test_each_by_frequency_WITHOUT_BLOCK
438
+
439
+ fm = FrequencyMap.new
440
+
441
+ fm << :def
442
+ fm << :abc << :abc << :abc << :abc
443
+ fm << :ghi << :ghi
444
+
445
+ r = fm.each_by_frequency.to_a
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
452
+
453
+ def test_each_value_WITH_BLOCK
404
454
 
405
455
  fm = FrequencyMap.new
406
456
 
@@ -412,7 +462,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
412
462
 
413
463
  fm.each_value do |v|
414
464
 
415
- r << [v]
465
+ r << v
416
466
  end
417
467
 
418
468
  r.sort!
@@ -421,7 +471,7 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
421
471
  assert_equal [1, 2, 4], r
422
472
  end
423
473
 
424
- def each_with_index
474
+ def test_each_value_WITHOUT_BLOCK
425
475
 
426
476
  fm = FrequencyMap.new
427
477
 
@@ -429,19 +479,37 @@ class Test_Xqsr3_Containers_FrequencyMap < Test::Unit::TestCase
429
479
  fm << :abc << :abc << :abc << :abc
430
480
  fm << :ghi << :ghi
431
481
 
432
- fm.each_with_index do |k, v, index|
433
-
434
- case index
435
- when 0
436
- assert_equal :abc, k
437
- assert_equal 2, v
438
- when 1
439
- assert_equal :def, k
440
- assert_equal 1, v
441
- else
442
- assert false, "should never get here"
443
- end
482
+ r = fm.each_value.to_a
483
+
484
+ r.sort!
485
+
486
+ assert_equal 3, r.size
487
+ assert_equal [1, 2, 4], r
488
+ end
489
+
490
+ def test_each_with_index_WITH_BLOCK
491
+
492
+ fm = FrequencyMap.new
493
+
494
+ fm << :def
495
+ fm << :abc << :abc << :abc << :abc
496
+ fm << :ghi << :ghi
497
+
498
+ indexes = []
499
+ kvs = {}
500
+
501
+ fm.each_with_index do |kv, index|
502
+
503
+ k = kv[0]
504
+ v = kv[1]
505
+
506
+ indexes << index
507
+
508
+ kvs[k] = v
444
509
  end
510
+
511
+ assert_equal [ 0, 1, 2 ], indexes
512
+ assert_equal Hash[ :abc, 4, :def, 1, :ghi, 2 ], kvs
445
513
  end
446
514
 
447
515
  def test_empty
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xqsr3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.38.0
4
+ version: 0.38.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-25 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  eXtensions by fine Quantum for Standard Ruby and 3rd-party libraries is a