/vendor/gems/facets-2.4.5/test/core/array/test_combination.rb
https://bitbucket.org/mediashelf/fedora-migrator · Ruby · 29 lines · 16 code · 6 blank · 7 comment · 0 complexity · 3e4ccaa0ccc386c27dd69eb5d86baf8a MD5 · raw file
- 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