Sha256: 67cd5597d268a20a904d19423c5a50f63ea776c8dc85498ad46e9bdf55feff23

Contents?: true

Size: 631 Bytes

Versions: 2

Compression:

Stored size: 631 Bytes

Contents

require 'facets/ruby'
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

2 entries across 2 versions & 1 rubygems

Version Path
facets-2.4.0 test/test_ruby/array/test_combination.rb
facets-2.4.1 test/test_ruby/array/test_combination.rb