Sha256: 9defea98f75d4a01f276e060b0144825cb88a0a1aa0009d7a7060ba24b916507

Contents?: true

Size: 474 Bytes

Versions: 5

Compression:

Stored size: 474 Bytes

Contents

require File.join(File.dirname(__FILE__), '..', 'helper')
require 'ludy/z_combinator'

class TestZCombinator < Test::Unit::TestCase
  include Ludy
  def test_z_combinator
    fact_ = lambda{|this|
      lambda{|n| n==1 ? 1 : n*this[n-1]}
    }
    fact = Z[fact_]
    assert_equal(3628800, fact[10])

    fib_ = lambda{|this|
      lambda{|n| n<=1 ? 1 : this[n-2]+this[n-1]}
    }
    fib = Z[fib_]
    assert_equal([1,1,2,3,5,8,13,21,34,55], (0...10).map(&fib))
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
godfat-ludy-0.1.13 test/ludy/test_z_combinator.rb
ludy-0.1.13 test/ludy/test_z_combinator.rb
ludy-0.1.10 test/ludy/test_z_combinator.rb
ludy-0.1.11 test/ludy/test_z_combinator.rb
ludy-0.1.9 test/ludy/test_z_combinator.rb