Sha256: 95dd99d0c278d54ac6cd84fa16274fec6957d55ed3632b62a9c03720a18015ad

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

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

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

2 entries across 2 versions & 1 rubygems

Version Path
hamster-0.2.7 spec/hamster/set/sorting_spec.rb
hamster-0.2.6 spec/hamster/set/sorting_spec.rb