/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

  1. require 'facets/array/combination'
  2. require 'test/unit'
  3. class TestEnumerableCombination < Test::Unit::TestCase
  4. def test_combination
  5. a = [1,2,3,4]
  6. z = a.combination(2).to_a
  7. r = [[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]]
  8. assert_equal( r, z )
  9. end
  10. def test_combination_with_block
  11. r = []
  12. a = [1,2,3,4]
  13. a.combination(2){ |a,b| r << [a,b] }
  14. assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
  15. end
  16. # DEPRECATED
  17. # def test_each_unique_pair
  18. # r = []
  19. # a = [1,2,3,4]
  20. # a.each_unique_pair{ |a,b| r << [a,b] }
  21. # assert_equal( [[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]], r )
  22. # end
  23. end