Sha256: afe7fa6807dcc360e78dfe4ae567dcd921a9f617613ad4bb24b64e3b68e22ebc

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# Test for facets/enumerable/combination.rb

require 'facets/enumerable/combination.rb'
require 'test/unit'

class TestEnumerableCombination < Test::Unit::TestCase

  def test_combinations
    a = [1,2]
    b = [3,4]
    z = Enumerable.combinations(a,b)
    r = [[1,3],[1,4],[2,3],[2,4]]
    assert_equal( r, z )
  end

  def test_combinations_of_three
    a = %w|a b|
    b = %w|a x|
    c = %w|x y|
    z = Enumerable.combinations(a, b, c)
    r = [ ["a", "a", "x"],
          ["a", "a", "y"],
          ["a", "x", "x"],
          ["a", "x", "y"],
          ["b", "a", "x"],
          ["b", "a", "y"],
          ["b", "x", "x"],
          ["b", "x", "y"] ]
    assert_equal( r, z )
  end

  def test_each_combination
    r = []
    a = [1,2,3,4]
    a.each_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

3 entries across 3 versions & 1 rubygems

Version Path
facets-2.2.0 test/unit/enumerable/test_combination.rb
facets-2.2.1 test/unit/enumerable/test_combination.rb
facets-2.3.0 test/core/enumerable/test_combination.rb