Sha256: 07cd130f63f4b2f8586b02dd0ca5b82ddcf81b3b026ad73bf28e46a2921f6a55

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |
#   |_|\___||___/\__|
#
# for lib/facets/enumerable/combination.rb

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

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

7 entries across 7 versions & 1 rubygems

Version Path
facets-2.0.5 test/unit/enumerable/test_combination.rb
facets-2.0.3 test/unit/enumerable/test_combination.rb
facets-2.0.4 test/unit/enumerable/test_combination.rb
facets-2.1.0 test/unit/enumerable/test_combination.rb
facets-2.1.1 test/unit/enumerable/test_combination.rb
facets-2.1.2 test/unit/enumerable/test_combination.rb
facets-2.1.3 test/unit/enumerable/test_combination.rb