Sha256: 35efb13526eb0643a287aa613c0dd6b8670512db3600f050200f0f6f512f514b

Contents?: true

Size: 1.47 KB

Versions: 2

Compression:

Stored size: 1.47 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

require 'hamster/list'

describe Hamster::List do

  [:minimum, :min].each do |method|

    describe "##{method}" do

      describe "doesn't run out of stack space on a really big" do

        it "stream" do
          @list = Hamster.interval(0, STACK_OVERFLOW_DEPTH)
        end

        it "list" do
          @list = (0...STACK_OVERFLOW_DEPTH).reduce(Hamster.list) { |list, i| list.cons(i) }
        end

        after do
          @list.send(method)
        end

      end

      describe "with a block" do

        [
          [[], nil],
          [["A"], "A"],
          [["A", "B", "C"], "C"],
        ].each do |values, expected|

          describe "on #{values.inspect}" do

            before do
              @list = Hamster.list(*values)
            end

            it "returns #{expected.inspect}" do
              @list.send(method) { |minimum, item| minimum <=> item }.should == expected
            end

          end

        end

      end

      describe "without a block" do

        [
          [[], nil],
          [["A"], "A"],
          [["A", "B", "C"], "A"],
        ].each do |values, expected|

          describe "on #{values.inspect}" do

            before do
              @list = Hamster.list(*values)
            end

            it "returns #{expected.inspect}" do
              @list.send(method).should == expected
            end

          end

        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.1.21 spec/hamster/list/minimum_spec.rb
hamster-0.1.20 spec/hamster/list/minimum_spec.rb