veritas-optimizer 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +33 -0
- data/LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +25 -0
- data/TODO +75 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +16 -0
- data/config/site.reek +91 -0
- data/config/yardstick.yml +2 -0
- data/lib/veritas/optimizer/algebra/difference.rb +66 -0
- data/lib/veritas/optimizer/algebra/extension.rb +42 -0
- data/lib/veritas/optimizer/algebra/intersection.rb +66 -0
- data/lib/veritas/optimizer/algebra/join.rb +44 -0
- data/lib/veritas/optimizer/algebra/product.rb +70 -0
- data/lib/veritas/optimizer/algebra/projection.rb +174 -0
- data/lib/veritas/optimizer/algebra/rename.rb +396 -0
- data/lib/veritas/optimizer/algebra/restriction.rb +259 -0
- data/lib/veritas/optimizer/algebra/summarization.rb +42 -0
- data/lib/veritas/optimizer/algebra/union.rb +66 -0
- data/lib/veritas/optimizer/logic/connective/binary.rb +254 -0
- data/lib/veritas/optimizer/logic/connective/conjunction.rb +122 -0
- data/lib/veritas/optimizer/logic/connective/disjunction.rb +122 -0
- data/lib/veritas/optimizer/logic/connective/negation.rb +71 -0
- data/lib/veritas/optimizer/logic/predicate/comparable.rb +134 -0
- data/lib/veritas/optimizer/logic/predicate/enumerable.rb +141 -0
- data/lib/veritas/optimizer/logic/predicate/equality.rb +44 -0
- data/lib/veritas/optimizer/logic/predicate/exclusion.rb +53 -0
- data/lib/veritas/optimizer/logic/predicate/greater_than.rb +54 -0
- data/lib/veritas/optimizer/logic/predicate/greater_than_or_equal_to.rb +56 -0
- data/lib/veritas/optimizer/logic/predicate/inclusion.rb +53 -0
- data/lib/veritas/optimizer/logic/predicate/inequality.rb +44 -0
- data/lib/veritas/optimizer/logic/predicate/less_than.rb +54 -0
- data/lib/veritas/optimizer/logic/predicate/less_than_or_equal_to.rb +56 -0
- data/lib/veritas/optimizer/logic/predicate/match.rb +19 -0
- data/lib/veritas/optimizer/logic/predicate/no_match.rb +19 -0
- data/lib/veritas/optimizer/logic/predicate.rb +177 -0
- data/lib/veritas/optimizer/optimizable.rb +59 -0
- data/lib/veritas/optimizer/relation/materialized.rb +40 -0
- data/lib/veritas/optimizer/relation/operation/binary.rb +168 -0
- data/lib/veritas/optimizer/relation/operation/combination.rb +33 -0
- data/lib/veritas/optimizer/relation/operation/limit.rb +149 -0
- data/lib/veritas/optimizer/relation/operation/offset.rb +114 -0
- data/lib/veritas/optimizer/relation/operation/order.rb +96 -0
- data/lib/veritas/optimizer/relation/operation/reverse.rb +94 -0
- data/lib/veritas/optimizer/relation/operation/unary.rb +88 -0
- data/lib/veritas/optimizer/version.rb +7 -0
- data/lib/veritas/optimizer.rb +136 -0
- data/lib/veritas-optimizer.rb +3 -0
- data/spec/integration/veritas/algebra/difference/optimize_spec.rb +152 -0
- data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +152 -0
- data/spec/integration/veritas/algebra/join/optimize_spec.rb +110 -0
- data/spec/integration/veritas/algebra/product/optimize_spec.rb +176 -0
- data/spec/integration/veritas/algebra/projection/optimize_spec.rb +237 -0
- data/spec/integration/veritas/algebra/rename/optimize_spec.rb +440 -0
- data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +216 -0
- data/spec/integration/veritas/algebra/union/optimize_spec.rb +192 -0
- data/spec/integration/veritas/logic/connective/conjunction/optimize_spec.rb +234 -0
- data/spec/integration/veritas/logic/connective/disjunction/optimize_spec.rb +235 -0
- data/spec/integration/veritas/logic/connective/negation/optimize_spec.rb +41 -0
- data/spec/integration/veritas/logic/expression/optimize_spec.rb +42 -0
- data/spec/integration/veritas/logic/predicate/equality/optimize_spec.rb +90 -0
- data/spec/integration/veritas/logic/predicate/exclusion/optimize_spec.rb +131 -0
- data/spec/integration/veritas/logic/predicate/greater_than/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/greater_than_or_equal_to/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/inclusion/optimize_spec.rb +131 -0
- data/spec/integration/veritas/logic/predicate/inequality/optimize_spec.rb +90 -0
- data/spec/integration/veritas/logic/predicate/less_than/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/less_than_or_equal_to/optimize_spec.rb +100 -0
- data/spec/integration/veritas/relation/empty/optimize_spec.rb +11 -0
- data/spec/integration/veritas/relation/materialized/optimize_spec.rb +37 -0
- data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +140 -0
- data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +98 -0
- data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +103 -0
- data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +113 -0
- data/spec/integration/veritas/relation/optimize_spec.rb +33 -0
- data/spec/rcov.opts +6 -0
- data/spec/shared/idempotent_method_behavior.rb +5 -0
- data/spec/shared/logic_connective_binary_optimize_behavior.rb +100 -0
- data/spec/shared/optimize_method_behavior.rb +14 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/add_method_missing.rb +13 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +35 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +42 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +42 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +54 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/left_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/right_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +34 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/operand_spec.rb +12 -0
- data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_comparable/optimizable_spec.rb +58 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_equivalent/optimizable_spec.rb +58 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +29 -0
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/empty_right_operand/optimizable_spec.rb +76 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/one_right_operand/optimizable_spec.rb +76 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimizable_spec.rb +49 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimize_spec.rb +53 -0
- data/spec/unit/veritas/optimizer/logic/predicate/equality/tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/predicate/exclusion/empty_right_operand/optimize_spec.rb +43 -0
- data/spec/unit/veritas/optimizer/logic/predicate/exclusion/one_right_operand/optimize_spec.rb +63 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than/tautology/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inclusion/empty_right_operand/optimize_spec.rb +43 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inclusion/one_right_operand/optimize_spec.rb +64 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inequality/contradiction/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than/tautology/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/attribute_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/constant_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/operation_spec.rb +11 -0
- data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +32 -0
- data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/optimizable_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +30 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +30 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +34 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +35 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimizable_spec.rb +38 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +33 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +13 -0
- data/tasks/quality/ci.rake +2 -0
- data/tasks/quality/flay.rake +41 -0
- data/tasks/quality/flog.rake +45 -0
- data/tasks/quality/heckle.rake +203 -0
- data/tasks/quality/metric_fu.rake +26 -0
- data/tasks/quality/reek.rake +9 -0
- data/tasks/quality/roodi.rake +15 -0
- data/tasks/quality/yardstick.rake +23 -0
- data/tasks/spec.rake +38 -0
- data/tasks/yard.rake +9 -0
- data/veritas-optimizer.gemspec +550 -0
- metadata +613 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer, '.chain' do
|
4
|
+
let(:operation) { mock('Operation') }
|
5
|
+
let(:object) { Optimizer }
|
6
|
+
let(:noop) { object::Noop }
|
7
|
+
let(:optimizer_class) { Class.new(Optimizer) }
|
8
|
+
|
9
|
+
context 'with no optimizers' do
|
10
|
+
subject { object.chain }
|
11
|
+
|
12
|
+
it { should equal(noop) }
|
13
|
+
|
14
|
+
it 'returns a block that returns the operation' do
|
15
|
+
subject.call(operation).should equal(operation)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with an optimizer that can optimize the operation' do
|
20
|
+
subject { object.chain(optimizer_class) }
|
21
|
+
|
22
|
+
let(:optimized) { mock('Optimized') }
|
23
|
+
|
24
|
+
before do
|
25
|
+
optimized = self.optimized
|
26
|
+
optimizer_class.send(:define_method, :optimizable?) { true }
|
27
|
+
optimizer_class.send(:define_method, :optimize) { optimized }
|
28
|
+
end
|
29
|
+
|
30
|
+
it { should_not equal(noop) }
|
31
|
+
|
32
|
+
it { should be_kind_of(Proc) }
|
33
|
+
|
34
|
+
it 'returns a block that optimizes the operation' do
|
35
|
+
subject.call(operation).should equal(optimized)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with an optimizer that cannot optimize the operation' do
|
40
|
+
subject { object.chain(optimizer_class) }
|
41
|
+
|
42
|
+
before do
|
43
|
+
optimizer_class.send(:define_method, :optimizable?) { false }
|
44
|
+
end
|
45
|
+
|
46
|
+
it { should_not equal(noop) }
|
47
|
+
|
48
|
+
it { should be_kind_of(Proc) }
|
49
|
+
|
50
|
+
it 'returns a block that calls the successor (Noop) with the operation' do
|
51
|
+
subject.call(operation).should equal(operation)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::EqualOperands, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.and(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Binary)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when left and right are equivalent' do
|
15
|
+
let(:left) { attribute.eq(1) }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when left and right are not equivalent' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.ne(1) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::EqualOperands, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.eq(1) }
|
8
|
+
let(:right) { attribute.eq(1) }
|
9
|
+
let(:connective) { left.and(right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(left) }
|
17
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary, '#left' do
|
4
|
+
subject { object.left }
|
5
|
+
|
6
|
+
let(:optimized_left) { mock('Optimized Left') }
|
7
|
+
let(:optimized_right) { mock('Optimized Right') }
|
8
|
+
let(:left) { mock('Left', :optimize => optimized_left) }
|
9
|
+
let(:right) { mock('Right', :optimize => optimized_right) }
|
10
|
+
let(:connective) { mock('Connective', :left => left, :right => right) }
|
11
|
+
let(:object) { described_class.new(connective) }
|
12
|
+
|
13
|
+
it { should equal(optimized_left) }
|
14
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimizable_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::RedundantLeftOperand, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.include([ 1 ]) }
|
8
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
9
|
+
let(:object) { described_class.new(connective) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
object.operation.should be_kind_of(Logic::Connective::Binary)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when the left operand is redundant' do
|
16
|
+
let(:connective) { left.and(right).and(right) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the left operand is not redundant' do
|
22
|
+
let(:connective) { left.and(right) }
|
23
|
+
|
24
|
+
it { should be(false) }
|
25
|
+
end
|
26
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimize_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::RedundantLeftOperand, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.include([ 1 ]) }
|
8
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
9
|
+
let(:connective) { left.and(right).and(right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should be_kind_of(Logic::Connective::Conjunction) }
|
17
|
+
|
18
|
+
its(:left) { should eql(attribute.eq(1)) }
|
19
|
+
|
20
|
+
its(:right) { should eql(attribute.ne(2)) }
|
21
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimizable_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::RedundantRightOperand, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.include([ 1 ]) }
|
8
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
9
|
+
let(:object) { described_class.new(connective) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
object.operation.should be_kind_of(Logic::Connective::Binary)
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when the right operand is redundant' do
|
16
|
+
let(:connective) { left.and(left.and(right)) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the right operand is not redundant' do
|
22
|
+
let(:connective) { left.and(right) }
|
23
|
+
|
24
|
+
it { should be(false) }
|
25
|
+
end
|
26
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimize_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::RedundantRightOperand, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.include([ 1 ]) }
|
8
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
9
|
+
let(:connective) { left.and(left.and(right)) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should be_kind_of(Logic::Connective::Conjunction) }
|
17
|
+
|
18
|
+
its(:left) { should eql(attribute.eq(1)) }
|
19
|
+
|
20
|
+
its(:right) { should eql(attribute.ne(2)) }
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary, '#right' do
|
4
|
+
subject { object.right }
|
5
|
+
|
6
|
+
let(:optimized_left) { mock('Optimized Left') }
|
7
|
+
let(:optimized_right) { mock('Optimized Right') }
|
8
|
+
let(:left) { mock('Left', :optimize => optimized_left) }
|
9
|
+
let(:right) { mock('Right', :optimize => optimized_right) }
|
10
|
+
let(:connective) { mock('Connective', :left => left, :right => right) }
|
11
|
+
let(:object) { described_class.new(connective) }
|
12
|
+
|
13
|
+
it { should equal(optimized_right) }
|
14
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::UnoptimizedOperand, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.and(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Binary)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when left is optimizable' do
|
15
|
+
let(:left) { attribute.include([ 1 ]) }
|
16
|
+
let(:right) { attribute.ne(2) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is optimizable' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
24
|
+
|
25
|
+
it { should be(true) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when left and right are not optimizable' do
|
29
|
+
let(:left) { attribute.eq(1) }
|
30
|
+
let(:right) { attribute.ne(2) }
|
31
|
+
|
32
|
+
it { should be(false) }
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Binary::UnoptimizedOperand, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.include([ 1 ]) }
|
8
|
+
let(:right) { attribute.exclude([ 2 ]) }
|
9
|
+
let(:connective) { left.and(right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should be_kind_of(Logic::Connective::Conjunction) }
|
17
|
+
|
18
|
+
its(:left) { should eql(attribute.eq(1)) }
|
19
|
+
|
20
|
+
its(:right) { should eql(attribute.ne(2)) }
|
21
|
+
end
|
data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::Contradiction, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { Logic::Connective::Conjunction.new(left, right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Conjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when left is a contradiction' do
|
15
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is a contradiction' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
24
|
+
|
25
|
+
it { should be(true) }
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when left and right are equality predicates with the same attribute and constant values' do
|
29
|
+
let(:left) { attribute.eq(1) }
|
30
|
+
let(:right) { attribute.eq(2) }
|
31
|
+
|
32
|
+
it { should be(true) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when left and right are inverses' do
|
36
|
+
let(:left) { attribute.eq(1) }
|
37
|
+
let(:right) { attribute.ne(1) }
|
38
|
+
|
39
|
+
it { should be(true) }
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::Contradiction, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
8
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
9
|
+
let(:connective) { Logic::Connective::Conjunction.new(left, right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::LeftOperandTautology, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { Logic::Connective::Conjunction.new(left, right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Conjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when right is a tautology' do
|
15
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is not a tautology' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.eq(1) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::LeftOperandTautology, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
8
|
+
let(:right) { attribute.eq(1) }
|
9
|
+
let(:connective) { Logic::Connective::Conjunction.new(left, right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(right) }
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::OptimizableToExclusion, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.and(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Conjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the operands are optimizable' do
|
15
|
+
let(:left) { attribute.ne(2) }
|
16
|
+
let(:right) { attribute.ne(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the operands are not optimizable' do
|
22
|
+
let(:left) { attribute.ne(1) }
|
23
|
+
let(:right) { attribute.eq(2) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::OptimizableToExclusion, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.and(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.should be_optimizable
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the right operands are optimizable' do
|
15
|
+
let(:left) { attribute.ne(2) }
|
16
|
+
let(:right) { attribute.ne(1) }
|
17
|
+
|
18
|
+
it { should be_kind_of(Logic::Predicate::Exclusion) }
|
19
|
+
|
20
|
+
its(:left) { should equal(attribute) }
|
21
|
+
|
22
|
+
# enumerable order is normalized
|
23
|
+
its(:right) { should == [ 1, 2 ] }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the right operands are not optimizable' do
|
27
|
+
let(:left) { attribute.ne(1) }
|
28
|
+
let(:right) { attribute.ne(2) }
|
29
|
+
|
30
|
+
it { should be_kind_of(Logic::Predicate::Exclusion) }
|
31
|
+
|
32
|
+
its(:left) { should equal(attribute) }
|
33
|
+
|
34
|
+
its(:right) { should == [ 1, 2 ] }
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::RightOperandTautology, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.and(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Conjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when right is a tautology' do
|
15
|
+
let(:left) { attribute.eq(1) }
|
16
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is not a tautology' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.eq(1) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Conjunction::RightOperandTautology, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.eq(1) }
|
8
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
9
|
+
let(:connective) { left.and(right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(left) }
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::ContradictionLeftOperand, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { Logic::Connective::Disjunction.new(left, right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Disjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when right is a tautology' do
|
15
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is not a tautology' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.eq(1) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::ContradictionLeftOperand, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
8
|
+
let(:right) { attribute.eq(1) }
|
9
|
+
let(:connective) { Logic::Connective::Disjunction.new(left, right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(right) }
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::ContradictionRightOperand, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.or(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Disjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when right is a contradiction' do
|
15
|
+
let(:left) { attribute.eq(1) }
|
16
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when right is not a contradiction' do
|
22
|
+
let(:left) { attribute.eq(1) }
|
23
|
+
let(:right) { attribute.eq(1) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::ContradictionRightOperand, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:left) { attribute.eq(1) }
|
8
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
9
|
+
let(:connective) { left.or(right) }
|
10
|
+
let(:object) { described_class.new(connective) }
|
11
|
+
|
12
|
+
before do
|
13
|
+
object.should be_optimizable
|
14
|
+
end
|
15
|
+
|
16
|
+
it { should equal(left) }
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::OptimizableToInclusion, '#optimizable?' do
|
4
|
+
subject { object.optimizable? }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.or(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.operation.should be_kind_of(Logic::Connective::Disjunction)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the operands are optimizable' do
|
15
|
+
let(:left) { attribute.eq(2) }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be(true) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'when the operands are not optimizable' do
|
22
|
+
let(:left) { attribute.ne(1) }
|
23
|
+
let(:right) { attribute.eq(2) }
|
24
|
+
|
25
|
+
it { should be(false) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Optimizer::Logic::Connective::Disjunction::OptimizableToInclusion, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:connective) { left.or(right) }
|
8
|
+
let(:object) { described_class.new(connective) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
object.should be_optimizable
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'when the right operands are optimizable' do
|
15
|
+
let(:left) { attribute.eq(2) }
|
16
|
+
let(:right) { attribute.eq(1) }
|
17
|
+
|
18
|
+
it { should be_kind_of(Logic::Predicate::Inclusion) }
|
19
|
+
|
20
|
+
its(:left) { should equal(attribute) }
|
21
|
+
|
22
|
+
# enumerable order is normalized
|
23
|
+
its(:right) { should == [ 1, 2 ] }
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when the right operands are not optimizable' do
|
27
|
+
let(:left) { attribute.eq(1) }
|
28
|
+
let(:right) { attribute.eq(2) }
|
29
|
+
|
30
|
+
it { should be_kind_of(Logic::Predicate::Inclusion) }
|
31
|
+
|
32
|
+
its(:left) { should equal(attribute) }
|
33
|
+
|
34
|
+
its(:right) { should == [ 1, 2 ] }
|
35
|
+
end
|
36
|
+
end
|