Sha256: 0c0f03324fff1e876c1500a2e2ab1ec39f1cda479a80c616bdabdcd58f1a99eb

Contents?: true

Size: 604 Bytes

Versions: 16

Compression:

Stored size: 604 Bytes

Contents

require 'facets/enumerable/cluster_by'
require 'test/unit'

class TC_Enumerable_Prime < Test::Unit::TestCase

  def test_cluster_by
    a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    r = [[0, 2, 4, 6, 8], [1, 3, 5, 7, 9]]
    assert_equal(r, a.cluster_by{|e| e%2}.each{|a| a.sort!})
    h = {0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9}
    r = [[[0, 0], [2, 2], [4, 4], [6, 6], [8, 8]], [[1, 1], [3, 3], [5, 5], [7, 7], [9, 9]]]
    assert_equal(r, h.cluster_by{|k, v| v%2}.each{|a| a.sort!})
  end

  def test_cluster_by_empty
    r = [].cluster_by{ |a| a }
    assert_equal([], r)
  end

end


Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/enumerable/test_cluster_by.rb
facets-2.8.3 test/core/enumerable/test_cluster_by.rb
facets-2.8.2 test/core/enumerable/test_cluster_by.rb
facets-2.8.1 test/core/enumerable/test_cluster_by.rb
facets-2.8.0 test/core/enumerable/test_cluster_by.rb
facets-2.7.0 test/core/enumerable/test_cluster_by.rb
facets-2.6.0 test/core/enumerable/test_cluster_by.rb
facets-2.4.0 test/enumerable/test_cluster_by.rb
facets-2.4.1 test/enumerable/test_cluster_by.rb
facets-2.4.4 test/core/enumerable/test_cluster_by.rb
facets-2.4.3 test/core/enumerable/test_cluster_by.rb
facets-2.4.2 test/core/enumerable/test_cluster_by.rb
facets-2.5.1 test/core/enumerable/test_cluster_by.rb
facets-2.5.0 test/core/enumerable/test_cluster_by.rb
facets-2.4.5 test/core/enumerable/test_cluster_by.rb
facets-2.5.2 test/core/enumerable/test_cluster_by.rb