dkubb/axiom-optimizer

View on GitHub
lib/axiom/optimizer/function/predicate/greater_than.rb

Summary

Maintainability
A
1 hr
Test Coverage
# encoding: utf-8

module Axiom
  class Optimizer
    module Function
      class Predicate

        # Abstract base class representing GreaterThan optimizations
        class GreaterThan < self
          include Comparable

          # Optimize when the operands are a contradiction
          class Contradiction < self
            include Predicate::Contradiction

            # Test if the operands are a contradiction
            #
            # @return [Boolean]
            #
            # @api private
            def optimizable?
              left.equal?(right) ||
              GreaterThanOrEqualTo::Contradiction.new(operation).optimizable?
            end

          end # class Contradiction

          # Optimize when the operands are a tautology
          class Tautology < self
            include Predicate::Tautology

            # Test if the operands are a tautology
            #
            # @return [Boolean]
            #
            # @api private
            def optimizable?
              operation.class.call(Util.min(left), Util.max(right))
            end

          end # class Tautology

          Axiom::Function::Predicate::GreaterThan.optimizer = chain(
            ConstantOperands,
            Contradiction,
            Tautology,
            NormalizableOperands,
            UnoptimizedOperands
          )

        end # class GreaterThan
      end # class Predicate
    end # module Function
  end # class Optimizer
end # module Axiom