Sha256: c0f3217659ddba645346118ef0f6b212eac59daf9d883b17612502c9c1fa27aa

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

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

require 'hamster/set'

describe Hamster::Set do

  [:reduce, :inject, :fold, :foldr].each do |method|

    describe "##{method}" do

      describe "when empty" do

        before do
          @original = Hamster.set
          @result = @original.send(method, "ABC") {}
        end

        it "returns the memo" do
          @result.should == "ABC"
        end

      end

      describe "when not empty" do

        before do
          @original = Hamster.set("A", "B", "C")
        end

        describe "with a block" do

          before do
            @result = @original.send(method, 0) { |memo, item| memo + 1 }
          end

          it "returns the final memo" do
            @result.should == 3
          end

        end

        describe "with no block" do

          before do
            @result = @original.send(method, "ABC")
          end

          it "returns the memo" do
            @result.should == "ABC"
          end

        end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.7 spec/hamster/set/reduce_spec.rb
hamster-0.2.6 spec/hamster/set/reduce_spec.rb