Sha256: 60a7b7cf3fc95fb038356091c3e0d7c568883152d3297dd4ed9d8f4fb10c767b
Contents?: true
Size: 1.13 KB
Versions: 5
Compression:
Stored size: 1.13 KB
Contents
#!/usr/bin/env ruby # Copyright (c) 2007, Lin Jen-Shin(a.k.a. godfat 真常) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'test/unit' require(File.join(File.dirname(__FILE__), '..', 'lib', 'ludy')) 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 & 1 rubygems
Version | Path |
---|---|
ludy-0.0.6 | test/tc_z_combinator.rb |
ludy-0.0.9 | test/tc_z_combinator.rb |
ludy-0.0.5 | test/tc_z_combinator.rb |
ludy-0.0.7 | test/tc_z_combinator.rb |
ludy-0.0.8 | test/tc_z_combinator.rb |