PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/enumerable/test_each_by.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 55 lines | 46 code | 9 blank | 0 comment | 0 complexity | a9214a830465fd3fee0f8e7f73ab921d MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/enumerable/each_by'
  2. require 'test/unit'
  3. class TC_Enumerable_EachBy < Test::Unit::TestCase
  4. def test_each_by_01
  5. x = []
  6. [1,2,3,4].each_by{ |a,b| x << [a,b] }
  7. o = [[1,2],[3,4]]
  8. assert_equal( o, x )
  9. end
  10. def test_each_by_02
  11. x = []
  12. [1,2,3,4,5].each_by{ |a,b,c| x << [a,b,c] }
  13. o = [[1,2,3],[4,5,nil]]
  14. assert_equal( o, x )
  15. end
  16. def test_each_by_03
  17. x = []
  18. [1,2,3,4].each_by(2){ |a,b| x << [a,b] }
  19. o = [[1,2],[3,4]]
  20. assert_equal( o, x )
  21. end
  22. def test_each_by_04
  23. x = []
  24. [1,2,3,4,5,6,7,8].each_by(4){ |*a| x << a }
  25. o = [ [[1,2,3,4]],[[5,6,7,8]] ]
  26. assert_equal( o, x )
  27. end
  28. def test_each_by_05
  29. x = []
  30. [1,2,3,4,5,6].each_by(3){ |*a| x << a }
  31. o = [ [[1,2,3]],[[4,5,6]] ]
  32. assert_equal( o, x )
  33. end
  34. def test_each_by_06
  35. a = [1,2,3,4,5,6]
  36. r = []
  37. a.each_by(2){ |x,y| r << [x,y] }
  38. assert_equal( [[1,2],[3,4],[5,6]], r )
  39. end
  40. def test_each_by_07
  41. a = [1,2,3,4,5,6]
  42. r = []
  43. a.each_by(3){ |*e| r << e }
  44. assert_equal( [ [[1,2,3]], [[4,5,6]] ], r )
  45. end
  46. end