Sha256: 5822c4f6fbe8cd8b7b69fc1ff30f339f7bbe295ea4a27fd1313eb0a5262dc1cf

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

require 'minitest/autorun'
require 'matilda-function'

describe "recursive" do
  it "creates a recursive function" do
    func = recursive { |this, i|
      if i < 1
        i
      else
        this.call(i - 1)
      end
    }

    func.call(10).must_equal(0)
  end

  it "returns an instance of Proc" do
    func = recursive { |this| this.call }
    func.kind_of?(Proc).must_equal true
  end
end

describe "Proc" do
  describe "#<<" do
    it "returns a new Proc" do
      func = Proc.new {} << Proc.new {}
      func.kind_of?(Proc).must_equal true
    end

    it "executing the result chains argument and receiver" do
      sort = Proc.new { |array| array.sort }
      reverse = Proc.new { |array| array.reverse }

      (sort << reverse).call([1,4,2,3]).must_equal [4,3,2,1]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
matilda-function-0.2.0 spec/function_spec.rb