PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/array/test_product.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 58 lines | 32 code | 10 blank | 16 comment | 0 complexity | c7a75e5a5626c8e7b49567561b21744f MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/array/product'
  2. require 'test/unit'
  3. class TC_Array_Product < Test::Unit::TestCase
  4. def test_product
  5. a = %w|a b|
  6. b = %w|a x|
  7. c = %w|x y|
  8. z = a.product(b, c)
  9. r = [ ["a", "a", "x"],
  10. ["a", "a", "y"],
  11. ["a", "x", "x"],
  12. ["a", "x", "y"],
  13. ["b", "a", "x"],
  14. ["b", "a", "y"],
  15. ["b", "x", "x"],
  16. ["b", "x", "y"] ]
  17. assert_equal( r, z )
  18. end
  19. def test_op_product
  20. a = [1,2,3] ** [4,5,6]
  21. assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
  22. end
  23. #def test_product_01
  24. # i = [[1,2], [4], ["apple", "banana"]]
  25. # o = [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
  26. # assert_equal( o, Enumerable.product(*i) )
  27. #end
  28. def test_product_02
  29. a = [1,2,3].product([4,5,6])
  30. assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
  31. end
  32. def test_product_03
  33. a = []
  34. [1,2,3].product([4,5,6]) {|elem| a << elem }
  35. assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
  36. end
  37. # def test_op_mod
  38. # a = [:A,:B,:C]
  39. # assert_equal( a[1], a/1 )
  40. # assert_equal( :B, a/1 )
  41. # end
  42. #
  43. # def test_op_div
  44. # a = [:A,:B,:C]
  45. # assert_equal( a[1], a/1 )
  46. # assert_equal( :B, a/1 )
  47. # end
  48. end