Sha256: 1a18ec4eaa4303322bfd6229b4fa2bb7257db972a982f98b3876251cb6ff9705

Contents?: true

Size: 657 Bytes

Versions: 3

Compression:

Stored size: 657 Bytes

Contents

require 'test/unit'

require 'facet/proc/%2A'
require 'facet/proc/compose'
require 'facet/proc/to_method'


class TC_Proc < Test::Unit::TestCase

  # compose

  def test_compose
    a = lambda { |x| x + 4 }
    b = lambda { |y| y / 2 }
    assert_equal( 6, (a.compose(b)).call(4) )
    assert_equal( 4, (b.compose(a)).call(4) )
    assert_equal( 6, (a * b).call(4) )
    assert_equal( 4, (b * a).call(4) )
  end
  
  # to_method
  
  def test_to_method
    a = 2
    tproc = proc { |x| x + a }  
    tmethod = tproc.to_method(:tryit)
    assert_equal( 3, tmethod.call(1) )
    assert_respond_to( self, :tryit )
    assert_equal( 3, tryit(1) )
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 test/proc/tc_proc.rb
facets-0.7.1 test/proc/tc_proc.rb
facets-0.7.2 test/proc/tc_proc.rb