Sha256: e617cce4af1aca3b957f89a804373d5940279ef3641c58665947877af2a1676a

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

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

require 'hamster/set'

describe Hamster::Set do

  [
    [:sort, lambda { |left, right| left.length <=> right.length }],
    [:sort_by, lambda { |item| item.length }],
  ].each do |method, comparator|

    describe "##{method}" do

      [
        [[], []],
        [["A"], ["A"]],
        [["Ichi", "Ni", "San"], ["Ni", "San", "Ichi"]],
      ].each do |values, expected|

        describe "on #{values.inspect}" do

          before do
            @original = Hamster.set(*values)
          end

          describe "with a block" do

            before do
              @result = @original.send(method, &comparator)
            end

            it "returns #{expected.inspect}" do
              @result.should == Hamster.list(*expected)
            end

          end

          describe "without a block" do

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

            it "returns #{expected.sort.inspect}" do
              @result.should == Hamster.list(*expected.sort)
            end

          end

        end

      end

    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hamster-0.2.5 spec/hamster/set/sorting_spec.rb
hamster-0.2.4 spec/hamster/set/sorting_spec.rb
hamster-0.2.3 spec/hamster/set/sorting_spec.rb
hamster-0.2.2 spec/hamster/set/sorting_spec.rb
hamster-0.2.1 spec/hamster/set/sorting_spec.rb
hamster-0.2.0 spec/hamster/set/sorting_spec.rb
hamster-0.1.23 spec/hamster/set/sorting_spec.rb
hamster-0.1.22 spec/hamster/set/sorting_spec.rb