PageRenderTime 143ms CodeModel.GetById 61ms app.highlight 17ms RepoModel.GetById 63ms 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
 1require 'facets/array/product'
 2require 'test/unit'
 3
 4class TC_Array_Product < Test::Unit::TestCase
 5
 6  def test_product
 7    a = %w|a b|
 8    b = %w|a x|
 9    c = %w|x y|
10    z = a.product(b, c)
11    r = [ ["a", "a", "x"],
12          ["a", "a", "y"],
13          ["a", "x", "x"],
14          ["a", "x", "y"],
15          ["b", "a", "x"],
16          ["b", "a", "y"],
17          ["b", "x", "x"],
18          ["b", "x", "y"] ]
19    assert_equal( r, z )
20  end
21
22  def test_op_product
23    a = [1,2,3] ** [4,5,6]
24    assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
25  end
26
27  #def test_product_01
28  #  i = [[1,2], [4], ["apple", "banana"]]
29  #  o = [[1, 4, "apple"], [1, 4, "banana"], [2, 4, "apple"], [2, 4, "banana"]]
30  #  assert_equal( o, Enumerable.product(*i) )
31  #end
32
33  def test_product_02
34    a = [1,2,3].product([4,5,6])
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
38  def test_product_03
39    a = []
40    [1,2,3].product([4,5,6]) {|elem| a << elem }
41    assert_equal( [[1, 4],[1, 5],[1, 6],[2, 4],[2, 5],[2, 6],[3, 4],[3, 5],[3, 6]], a )
42  end
43
44  #     def test_op_mod
45  #       a = [:A,:B,:C]
46  #       assert_equal( a[1], a/1 )
47  #       assert_equal( :B, a/1 )
48  #     end
49  #
50  #     def test_op_div
51  #       a = [:A,:B,:C]
52  #       assert_equal( a[1], a/1 )
53  #       assert_equal( :B, a/1 )
54  #     end
55
56end
57
58