Sha256: aa9363463061631fb52512c2e5d0a737beb50eed53b278b74e8dee83eef75b7f

Contents?: true

Size: 466 Bytes

Versions: 1

Compression:

Stored size: 466 Bytes

Contents

require './test/helper'
require 'ludy/y_combinator'

include Ludy # why should this be here?

class TestYCombinator < Test::Unit::TestCase
  def test_y_combinator
    fact_ = lambda{|this|
      lambda{|n| n==1 ? 1 : n*this[n-1]}
    }
    fact = Y[fact_]
    assert_equal(3628800, fact[10])

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ludy-0.1.15 test/ludy/test_y_combinator.rb