tests/tc_cartesian.rb in Cartesian-0.1.0 vs tests/tc_cartesian.rb in Cartesian-0.2.1
- old
+ new
@@ -1,23 +1,30 @@
-require '../lib/cartesian'
-require 'benchmark'
+require 'test/unit'
-MULTIPLIER = 3
-letras = ("a"*MULTIPLIER.."z"*MULTIPLIER).to_a
-numeros = (0..10**1).to_a
+$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
+require 'cartesian'
-Benchmark.bmbm do |x|
- x.report("product") { Cartesian.product(letras, numeros) }
- x.report("productZip") { Cartesian.productZip(letras, numeros) }
-end
+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 Cartesian.productZip(first, second)
- #~ result = []
- #~ first.each do |a|
- #~ aaa = Array.new(second.size) { a }
- #~ result += aaa.zip(second)
- #~ end
- #~ result
- #~ 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