require 'test/unit' $:.unshift File.join(File.dirname(__FILE__), "..", "lib") require 'cartesian' class TestCartesian < Test::Unit::TestCase def test_arrays foo = [1,2,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) end def test_ranges foo = 1..3 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) end 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) end end