Sha256: edbad87eda6a047f2bf35ca97ecd591c32c80a33c5de702d5cd8669decbef543

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

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

require 'hamster/set'

describe Hamster::Set do

  [:reduce, :inject, :fold].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

13 entries across 13 versions & 1 rubygems

Version Path
hamster-0.2.3 spec/hamster/set/reduce_spec.rb
hamster-0.2.2 spec/hamster/set/reduce_spec.rb
hamster-0.2.1 spec/hamster/set/reduce_spec.rb
hamster-0.2.0 spec/hamster/set/reduce_spec.rb
hamster-0.1.23 spec/hamster/set/reduce_spec.rb
hamster-0.1.22 spec/hamster/set/reduce_spec.rb
hamster-0.1.21 spec/hamster/set/reduce_spec.rb
hamster-0.1.20 spec/hamster/set/reduce_spec.rb
hamster-0.1.19 spec/hamster/set/reduce_spec.rb
hamster-0.1.18 spec/hamster/set/reduce_spec.rb
hamster-0.1.17 spec/hamster/set/reduce_spec.rb
hamster-0.1.16 spec/hamster/set/reduce_spec.rb
hamster-0.1.15 spec/hamster/set/reduce_spec.rb