Sha256: df05f36e068f6c108cddee78773e7f5fc65b6e7283015b32d1f97d8e29d73fb2

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'compiler_helper'
module Alf
  class Compiler
    describe Default, "rank" do

      subject{
        compiler.call(expr)
      }

      let(:ordering){
        Ordering.new([[:a, :asc]])
      }

      shared_examples_for "the expected Rank::Cesure" do
        it_should_behave_like "a traceable compiled"

        it 'has a Rank::Cesure cog' do
          subject.should be_a(Engine::Rank::Cesure)
        end

        it 'has the correct parameters' do
          subject.by.should eq(AttrList[:a])
          subject.as.should eq(:foo)
        end
      end

      context 'when not sorted' do
        let(:expr){
          rank(an_operand(leaf), ordering, :foo)
        }

        it_should_behave_like "the expected Rank::Cesure"
        it_should_behave_like "a compiled based on an added sub Sort"
      end

      context 'when already sorted' do
        let(:expr){
          rank(sort(an_operand(leaf), subordering), ordering, :foo)
        }

        context 'in a compatible way' do
          let(:subordering){
            Ordering.new([[:a, :asc], [:b, :desc]])
          }

          it_should_behave_like "the expected Rank::Cesure"
          it_should_behave_like "a compiled reusing a sub Sort"
        end

        context 'in a completely different way' do
          let(:subordering){
            Ordering.new([[:name, :asc]])
          }

          it_should_behave_like "the expected Rank::Cesure"
          it_should_behave_like "a compiled not reusing a sub Sort"
        end

        context 'in incompatible way' do
          let(:subordering){
            Ordering.new([[:a, :desc]])
          }

          it_should_behave_like "the expected Rank::Cesure"
          it_should_behave_like "a compiled not reusing a sub Sort"
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-compiler/default/test_rank.rb