Sha256: b7e98e4ccb1d291e22ccf13639f9ba40742324f25defd0c6994bde069540351c

Contents?: true

Size: 827 Bytes

Versions: 4

Compression:

Stored size: 827 Bytes

Contents

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

describe Hamster::List do

  describe "#map" do

    it "initially returns self" do
      list = Hamster::List.new
      list.map {}.should equal(list)
    end

    describe "when not empty" do

      before do
        @original = Hamster::List.new.cons(1).cons(2).cons(3).cons(4)
        @copy = @original.map { |i| i + 5 }
      end

      it "returns a modified copy" do
        @copy.should_not equal(@original)
      end

      describe "the original" do

        it "has the original values" do
          @original.to_enum.to_a.should == [4, 3, 2, 1]
        end

      end

      describe "the modified copy" do

        it "has the mapped values" do
          @copy.to_enum.to_a.should == [9, 8, 7, 6]
        end

      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hamster-0.1.8 spec/hamster/list/map_spec.rb
hamster-0.1.7 spec/hamster/list/map_spec.rb
hamster-0.1.6 spec/hamster/list/map_spec.rb
hamster-0.1.5 spec/hamster/list/map_spec.rb