test/test_cartesian.rb in cartesian-0.5.3 vs test/test_cartesian.rb in cartesian-0.6.0

- old
+ new

@@ -17,10 +17,30 @@ bar = 4..6 expected = [[1, 4], [1, 5], [1, 6], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6]] assert(foo.x(bar).to_a == expected) assert(Cartesian.product(foo,bar) == expected) + end + + def test_other_existing_enumerable + if RUBY_DESCRIPTION =~ /rubinius/i # Work around a Rubinius bug I found and [reported][1] and whose + foo = [0.0, 0.6] # [fix][2] has not yet been merged to HEAD (Jan 1st, 2011). + else # [1]: https://github.com/evanphx/rubinius/issues/issue/650 + foo = 0.step(1, 0.6) # [2]: https://github.com/evanphx/rubinius/commit/9ad78eaaf66dac6615baa06a712594a95b1a7bea + end + bar = { :x => 42, :y => 43 } + expected = foo.to_a.x(bar.to_a).to_a + actual = foo.x(bar).to_a + assert_equal expected, actual + end + + def test_other_new_enumerable + String.class_eval "alias each each_line ; include Enumerable" + foo = "foo\nbar" + bar = [1, 2] + expected = [["foo\n", 1], ["foo\n", 2], ["bar", 1], ["bar", 2]] + assert_equal expected, foo.x(bar).to_a end def test_product c = [1].x([2]) c.x([3]) @@ -42,23 +62,26 @@ def test_mixed foo = 1..3 bar = %w{a b c} expected = [[1, "a"], [1, "b"], [1, "c"], [2, "a"], [2, "b"], - [2, "c"], [3, "a"], [3, "b"], [3, "c"]] - assert(foo.x(bar).to_a == expected) - assert(Cartesian.product(foo,bar) == expected) ################## + [2, "c"], [3, "a"], [3, "b"], [3, "c"]] + actual = foo.x(bar).to_a + assert_equal expected, actual + actual = Cartesian.product(foo,bar) + assert_equal expected, actual end def test_power ary = [1,2,3] assert_raise(ArgumentError) { ary**(-1) } assert_equal [], ary**0 assert_equal ary, ary**1 expected = [[0, 0, 0], [0, 0, 1], [0, 1, 0],\ [0, 1, 1], [1, 0, 0], [1, 0, 1],\ - [1, 1, 0], [1, 1, 1]] - assert_equal expected, ([0,1]**3).to_a + [1, 1, 0], [1, 1, 1]] + actual = ([0,1]**3).to_a + assert_equal expected, actual end def test_joined_cartesian assert_equal ["1A", "1B", "2A", "2B"], [1,2].joined_cartesian(%w<A B>) end