Sha256: e87aea92712940da80d7ae98b1945426051ad3d398fb7ed3a192b8284e0b4f67

Contents?: true

Size: 1.06 KB

Versions: 12

Compression:

Stored size: 1.06 KB

Contents

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

require 'hamster/hash'

describe Hamster::Hash do

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

    describe "##{method}" do

      describe "when empty" do

        before do
          @original = Hamster.hash
          @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.hash("A" => "aye", "B" => "bee", "C" => "see")
        end

        describe "with a block" do

          before do
            @result = @original.send(method, 0) { |memo, key, value| 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

12 entries across 12 versions & 1 rubygems

Version Path
hamster-0.3.6 spec/hamster/hash/reduce_spec.rb
hamster-0.3.5 spec/hamster/hash/reduce_spec.rb
hamster-0.3.4 spec/hamster/hash/reduce_spec.rb
hamster-0.3.3 spec/hamster/hash/reduce_spec.rb
hamster-0.3.2 spec/hamster/hash/reduce_spec.rb
hamster-0.3.1 spec/hamster/hash/reduce_spec.rb
hamster-0.3.0 spec/hamster/hash/reduce_spec.rb
hamster-0.2.13 spec/hamster/hash/reduce_spec.rb
hamster-0.2.12 spec/hamster/hash/reduce_spec.rb
hamster-0.2.11 spec/hamster/hash/reduce_spec.rb
hamster-0.2.9 spec/hamster/hash/reduce_spec.rb
hamster-0.2.8 spec/hamster/hash/reduce_spec.rb