Sha256: 32ada8517894250f8d5117b32fe000a92843643dd1a5f4766e48feed2c6c6dce

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require "spec_helper"
require "hamster/sorted_set"

describe Hamster::SortedSet do
  [:map, :collect].each do |method|
    describe "##{method}" do
      context "when empty" do
        it "returns self" do
          SS.empty.send(method) {}.should equal(SS.empty)
        end
      end

      context "when not empty" do
        let(:sorted_set) { SS["A", "B", "C"] }

        context "with a block" do
          it "preserves the original values" do
            sorted_set.send(method, &:downcase)
            sorted_set.should eql(SS["A", "B", "C"])
          end

          it "returns a new set with the mapped values" do
            sorted_set.send(method, &:downcase).should eql(SS["a", "b", "c"])
          end
        end

        context "with no block" do
          it "returns an Enumerator" do
            sorted_set.send(method).class.should be(Enumerator)
            sorted_set.send(method).each(&:downcase).should == SS['a', 'b', 'c']
          end
        end
      end

      context "on a set ordered by a comparator" do
        let(:sorted_set) { SS.new(["A", "B", "C"]) { |a,b| b <=> a }}

        it "returns a new set with the mapped values" do
          sorted_set.send(method, &:downcase).should == ['c', 'b', 'a']
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/sorted_set/map_spec.rb
hamster-3.0.0 spec/lib/hamster/sorted_set/map_spec.rb
hamster-2.0.0 spec/lib/hamster/sorted_set/map_spec.rb