Sha256: 3ff0aa8b8c1a6b6b69262f562ce3fc53dcdf4acf6bdbd12c9fd016b08d472015

Contents?: true

Size: 1.82 KB

Versions: 5

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'
module Alf
  module Operator::NonRelational
    describe Sort do

      let(:operator_class){ Sort }
      it_should_behave_like("An operator class")

      let(:input) {[
        {:first => "a", :second => 20,  :third => true},
        {:first => "b", :second => 10, :third => false},
        {:first => "a", :second => 1,  :third => true},
      ]}

      let(:expected){[
        {:first => "a", :second => 1,  :third => true},
        {:first => "a", :second => 20, :third => true},
        {:first => "b", :second => 10, :third => false},
      ]}

      subject{ operator.to_a }

      context "with Lispy" do 
        let(:operator){ Lispy.sort(input, [[:first, :asc], [:second, :asc]]) }
        it{ should eq(expected) }
      end

      context "with one arg" do 
        let(:operator){ Lispy.sort(input, [[:second, :asc]]) }
        let(:expected){[
          {:first => "a", :second => 1,  :third => true},
          {:first => "b", :second => 10, :third => false},
          {:first => "a", :second => 20, :third => true},
        ]}
        it{ should eq(expected) }
      end

      context "with two args" do 
        let(:operator){ Lispy.sort(input, [[:second, :asc], [:first, :asc]]) }
        let(:expected){[
          {:first => "a", :second => 1,  :third => true},
          {:first => "b", :second => 10, :third => false},
          {:first => "a", :second => 20, :third => true},
        ]}
        it{ should eq(expected) }
      end

      context "in descending order" do 
        let(:operator){ Lispy.sort(input, [[:second, :desc]]) }
        let(:expected){[
          {:first => "a", :second => 20, :third => true},
          {:first => "b", :second => 10, :third => false},
          {:first => "a", :second => 1,  :third => true},
        ]}
        it{ should eq(expected) }
      end

    end 
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
alf-0.12.2 spec/unit/alf-core/operator/non_relational/test_sort.rb
alf-0.12.1 spec/unit/alf-core/operator/non_relational/test_sort.rb
alf-0.12.0 spec/unit/alf-core/operator/non_relational/test_sort.rb
alf-0.11.1 spec/unit/alf-core/operator/non_relational/test_sort.rb
alf-0.11.0 spec/unit/alf-core/operator/non_relational/test_sort.rb