more tests

This commit is contained in:
Denis Knauf 2011-12-16 12:45:22 +01:00
parent c8edcddcf6
commit 99a268a89d

View file

@ -2,13 +2,28 @@ require 'test/unit'
require 'functional' require 'functional'
class FunTest < Test::Unit::TestCase class FunTest < Test::Unit::TestCase
M = 0..100
def doit_fun m, &exe
f = m.to_fun
yield f
f.to_a
end
def test_to_fun_exists def test_to_fun_exists
assert_respond_to Object, :to_fun assert_respond_to Object, :to_fun
end end
def test_to_fun_to_a def test_to_a
assert_equal (0..100).to_a, (0..100).to_fun.to_a assert_equal M.to_a, doit_fun( M) {|x| x }
end end
def test_collect
l = lambda {|x| x*2}
assert_equal M.collect( &l), doit_fun( M) {|x| x.collect( &l) }
end
def test_inject
assert_equal M.inject( 0) {|i,j| i+j }, M.to_fun.inject( 0) {|i,j| i+j }
end
end end