test/tc_monad.rb in prelude-0.0.3 vs test/tc_monad.rb in prelude-0.0.5

- old
+ new

@@ -1,7 +1,7 @@ #-- -# $Id: tc_monad.rb 13 2006-09-11 05:19:16Z prelude $ +# $Id: tc_monad.rb 31 2006-12-28 02:28:28Z prelude $ # # # This file is part of the Prelude library that provides tools to # enable Haskell style functional programming in Ruby. # @@ -22,14 +22,17 @@ # 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 #++ +require 'prelude' + # A test class representing a genesis of a possible cloned animal class Cloned - include Monad + include Prelude::Monad + attr_reader :name, :mother, :father def initialize(n, m, f) @name = n @mother = m @@ -49,11 +52,11 @@ mother ? (mother.father ? mother.father.father : nil) : nil end # Monadic versions def m_maternalGrandfather - wrap << :mother << :father << unwrap + wrap >> :mother >> :father >> unwrap end def m_mothersPaternalGrandfather wrap.bind(:mother).bind(:father).bind(:father).unwrap end @@ -91,55 +94,32 @@ expect = nil assert_equal(expect, result) end - def test_bind1 - result = @sheep.m_maternalGrandfather + def test_bind + # Wrap and >> + result = @sheep.wrap >> :mother >> :father >> @sheep.unwrap expect = @grandpa assert_equal(expect, result) - end - def test_bind2 - result = @sheep.m_mothersPaternalGrandfather + # Wrap and bind + result = @sheep.wrap.bind(:mother).bind(:father).bind(:father).unwrap expect = nil assert_equal(expect, result) - end - def aaa(one, two=222, *args, &block) - puts 'aaa: ' - puts 'one=' + one.inspect - puts 'two=' + two.inspect - args.each{|x| puts 'p= '+x.inspect} - puts 'b= '+block.inspect - bbb - end + # Auto-wrap and >> + result = @sheep >> :mother >> :father >> @sheep.unwrap + expect = @grandpa + + assert_equal(expect, result) - def bbb - puts 'AAA: '+caller_method.inspect - puts 'Arity: '+caller_method.to_proc.arity.inspect + # Auto-wrap and bind + result = @sheep.bind(:mother).bind(:father).bind(:father).unwrap + expect = nil + + assert_equal(expect, result) end -# def test_method -# p = proc {} -# # aaa() -# aaa(1) -# aaa(1, "aaa") -# # aaa(){|x| x+1} -# aaa(1){|x| x+1} -# aaa(1, 2, 3){|x| x+1} -# aaa(1, 2, :aaa, 3){|x| x+1} -# aaa(1, proc {|x| x+1}, :aaa, 3){|x| x+1} -# aaa(proc {|x| x+1}) -# aaa([1, 2, 3]) -# aaa([1, 2, 3]) -# aaa(*[1, 2, 3, p]) -# aaa(*[1, 2, 3, p], &p) -# end - -# def test_misc -# puts "this: "+ this_method.inspect -# puts "caller: "+caller_method.inspect -# end end # TestMonad