Sha256: d44b4dcc47cdc95a0f963f265419fe86a3d45997adbff2a9803b0497a658081a

Contents?: true

Size: 644 Bytes

Versions: 14

Compression:

Stored size: 644 Bytes

Contents

require 'facets/array/combination'
require 'test/unit'

class TestEnumerableCombination < Test::Unit::TestCase

  def test_combination
    a = [1,2,3,4]
    z = a.combination(2).to_a
    r = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
    assert_equal( r, z )
  end

  def test_combination_with_block
    r = []
    a = [1,2,3,4]
    a.combination(2){ |a,b| r << [a,b] }
    assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
  end

#   DEPRECATED
#   def test_each_unique_pair
#     r = []
#     a = [1,2,3,4]
#     a.each_unique_pair{ |a,b| r << [a,b] }
#     assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
#   end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/array/test_combination.rb
facets-2.8.3 test/core/array/test_combination.rb
facets-2.8.2 test/core/array/test_combination.rb
facets-2.8.1 test/core/array/test_combination.rb
facets-2.8.0 test/core/array/test_combination.rb
facets-2.7.0 test/core/array/test_combination.rb
facets-2.6.0 test/core/array/test_combination.rb
facets-2.4.2 test/core/array/test_combination.rb
facets-2.4.3 test/core/array/test_combination.rb
facets-2.4.4 test/core/array/test_combination.rb
facets-2.5.0 test/core/array/test_combination.rb
facets-2.5.1 test/core/array/test_combination.rb
facets-2.4.5 test/core/array/test_combination.rb
facets-2.5.2 test/core/array/test_combination.rb