Sha256: 1a2d6a12e1dd56d1fad80f7ecd776236f8c9b43b89d7ad21fc8ecb52fd82868d

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Optimizer::Function::Connective::Disjunction::OptimizableToInclusion, '#optimizable?' do
  subject { object.optimizable? }

  let(:attribute)  { Attribute::Integer.new(:id)     }
  let(:connective) { left.or(right)                  }
  let(:object)     { described_class.new(connective) }

  before do
    object.operation.should be_kind_of(Function::Connective::Disjunction)
  end

  context 'when the operands are optimizable' do
    context 'when the left and right are equality predicates' do
      let(:left)  { attribute.eq(2) }
      let(:right) { attribute.eq(1) }

      it { should be(true) }
    end

    context 'when the left is an equality predicate and the right is an inclusion predicate' do
      let(:left)  { attribute.eq(2)             }
      let(:right) { attribute.include([ 1, 3 ]) }

      it { should be(true) }
    end

    context 'when the left is an inclusion predicate and the right is an equality predicate' do
      let(:left)  { attribute.include([ 2, 3 ]) }
      let(:right) { attribute.eq(1)             }

      it { should be(true) }
    end

    context 'when the left and right are inclusion predicatess' do
      let(:left)  { attribute.include([ 2, 3 ]) }
      let(:right) { attribute.include([ 1, 3 ]) }

      it { should be(true) }
    end
  end

  context 'when the operands are not optimizable' do
    context 'when the left is an inequality predicate and the right is an equality predicate' do
      let(:left)  { attribute.ne(1) }
      let(:right) { attribute.eq(2) }

      it { should be(false) }
    end

    context 'when the left is an exclusion predicate and the right is an equality predicate' do
      let(:left)  { attribute.exclude([ 1, 3 ]) }
      let(:right) { attribute.eq(2)             }

      it { should be(false) }
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
axiom-optimizer-0.1.0 spec/unit/axiom/optimizer/function/connective/disjunction/optimizable_to_inclusion/optimizable_predicate_spec.rb
veritas-optimizer-0.0.7 spec/unit/veritas/optimizer/function/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb
veritas-optimizer-0.0.6 spec/unit/veritas/optimizer/function/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb
veritas-optimizer-0.0.5 spec/unit/veritas/optimizer/function/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb