fedora-migrator /vendor/gems/facets-2.4.5/test/core/array/test_combination.rb

Language Ruby Lines 30
MD5 Hash 3e4ccaa0ccc386c27dd69eb5d86baf8a Estimated Cost $352 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
Back to Top