#-- # $Id: tc_higher.rb 17 2006-09-17 18:03:15Z prelude $ # # # This file is part of the Prelude library that provides tools to # enable Haskell style functional programming in Ruby. # # http://prelude.rubyforge.org # # Copyright (C) 2006 APP Design, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #++ class TestHigher < Test::Unit::TestCase def setup # Nothing end # setup def teardown # Nothing end # teardown # # Test higher functions # def test_curry_proc add5 = (proc {|x,y,z| x+y+z}).curry(5) result = add5[3, 2] expect = 10 assert_equal(expect, result) result = add5.call(3, 2) expect = 10 assert_equal(expect, result) end def test_curry_symbol add5 = :+.curry(5) result = add5.call(3) expect = 8 assert_equal(expect, result) result = add5[4] expect = 9 assert_equal(expect, result) end def test_composition add5 = proc {|x| x+5} add6 = proc {|x,y| x+y+6} add11 = add5 ** add6 result = add11[1, 2] expect = 14 assert_equal(expect, result) result = add5 ** 1 expect = 6 assert_equal(expect, result) result = add5 ** add6 ** [1, 2] expect = 14 assert_equal(expect, result) end end # TestHigher