Sha256: ec84517078c6475e863cf309fab7476ccccd6a4b159ef9b2019b615e1e02de6f

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'spec_helper'
module Alf
  class Predicate
    describe Predicate, "factory methods" do

      before do
        subject.should be_a(Predicate)
        subject.expr.should be_a(Expr)
      end

      context "tautology" do
        subject{ Predicate.tautology }

        specify{ subject.to_ruby_code.should eq("->(t){ true }") }
      end

      context "contradiction" do
        subject{ Predicate.contradiction }

        specify{ subject.to_ruby_code.should eq("->(t){ false }") }
      end

      context "identifier" do
        subject{ Predicate.identifier(:x) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x }") }
      end

      context "eq" do
        subject{ Predicate.eq(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x == 2 }") }
      end

      context "neq" do
        subject{ Predicate.neq(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x != 2 }") }
      end

      context "lt" do
        subject{ Predicate.lt(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x < 2 }") }
      end

      context "lte" do
        subject{ Predicate.lte(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x <= 2 }") }
      end

      context "gt" do
        subject{ Predicate.gt(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x > 2 }") }
      end

      context "gte" do
        subject{ Predicate.gte(:x, 2) }

        specify{ subject.to_ruby_code.should eq("->(t){ t.x >= 2 }") }
      end

      context "literal" do
        subject{ Predicate.literal(2) }

        specify{ subject.to_ruby_code.should eq("->(t){ 2 }") }
      end

      context "native" do
        subject{ Predicate.native(lambda{}) }

        specify{ subject.expr.should be_a(Native) }
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-predicate/predicate/test_factory_methods.rb