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,192 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Algebra::Union, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:header) { [ [ :id, Integer ] ] }
|
7
|
+
let(:left_body) { [ [ 1 ] ].each }
|
8
|
+
let(:right_body) { [ [ 2 ] ].each }
|
9
|
+
let(:original_left) { Relation.new(header, left_body) }
|
10
|
+
let(:original_right) { Relation.new(header, right_body) }
|
11
|
+
let(:object) { described_class.new(left, right) }
|
12
|
+
|
13
|
+
context 'left is an empty relation' do
|
14
|
+
let(:left) { Relation::Empty.new(header) }
|
15
|
+
let(:right) { original_right }
|
16
|
+
|
17
|
+
it { should equal(right) }
|
18
|
+
|
19
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
20
|
+
should == object
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not execute left_body#each' do
|
24
|
+
left_body.should_not_receive(:each)
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not execute right_body#each' do
|
29
|
+
right_body.should_not_receive(:each)
|
30
|
+
subject
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like 'an optimize method'
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'right is an empty relation' do
|
37
|
+
let(:left) { original_left }
|
38
|
+
let(:right) { Relation::Empty.new(header) }
|
39
|
+
|
40
|
+
it { should equal(left) }
|
41
|
+
|
42
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
43
|
+
should == object
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'does not execute left_body#each' do
|
47
|
+
left_body.should_not_receive(:each)
|
48
|
+
subject
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'does not execute right_body#each' do
|
52
|
+
right_body.should_not_receive(:each)
|
53
|
+
subject
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like 'an optimize method'
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'left is an empty relation when optimized' do
|
60
|
+
let(:left) { Algebra::Restriction.new(original_left, Logic::Proposition::Contradiction.instance) }
|
61
|
+
let(:right) { original_right }
|
62
|
+
|
63
|
+
it { should equal(right) }
|
64
|
+
|
65
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
66
|
+
should == object
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'does not execute left_body#each' do
|
70
|
+
left_body.should_not_receive(:each)
|
71
|
+
subject
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'does not execute right_body#each' do
|
75
|
+
right_body.should_not_receive(:each)
|
76
|
+
subject
|
77
|
+
end
|
78
|
+
|
79
|
+
it_should_behave_like 'an optimize method'
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'right is an empty relation when optimized' do
|
83
|
+
let(:left) { original_left }
|
84
|
+
let(:right) { Algebra::Restriction.new(original_right, Logic::Proposition::Contradiction.instance) }
|
85
|
+
|
86
|
+
it { should equal(left) }
|
87
|
+
|
88
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
89
|
+
should == object
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does not execute left_body#each' do
|
93
|
+
left_body.should_not_receive(:each)
|
94
|
+
subject
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'does not execute right_body#each' do
|
98
|
+
right_body.should_not_receive(:each)
|
99
|
+
subject
|
100
|
+
end
|
101
|
+
|
102
|
+
it_should_behave_like 'an optimize method'
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'left and right are equivalent relations' do
|
106
|
+
let(:left_body) { [ [ 1 ] ].each }
|
107
|
+
let(:right_body) { [ [ 1 ] ].each }
|
108
|
+
let(:left) { original_left }
|
109
|
+
let(:right) { original_right }
|
110
|
+
|
111
|
+
it { should equal(left) }
|
112
|
+
|
113
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
114
|
+
should == object
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'does not execute left_body#each' do
|
118
|
+
pending 'TODO: should only compare left and right with #eql? if they are materialized' do
|
119
|
+
left_body.should_not_receive(:each)
|
120
|
+
subject
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'does not execute right_body#each' do
|
125
|
+
pending 'TODO: should only compare left and right with #eql? if they are materialized' do
|
126
|
+
right_body.should_not_receive(:each)
|
127
|
+
subject
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it_should_behave_like 'an optimize method'
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'left and right are equivalent materialized relations' do
|
135
|
+
let(:left_body) { [ [ 1 ] ] }
|
136
|
+
let(:right_body) { [ [ 1 ] ] }
|
137
|
+
let(:left) { original_left }
|
138
|
+
let(:right) { original_right }
|
139
|
+
|
140
|
+
it { should equal(left) }
|
141
|
+
|
142
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
143
|
+
should == object
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'executes left_body#each' do
|
147
|
+
pending 'only receive #each once'
|
148
|
+
left_body.should_receive(:each)
|
149
|
+
subject
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'executes right_body#each' do
|
153
|
+
pending 'only receive #each once'
|
154
|
+
right_body.should_receive(:each)
|
155
|
+
subject
|
156
|
+
end
|
157
|
+
|
158
|
+
it_should_behave_like 'an optimize method'
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'left and right are not empty relations' do
|
162
|
+
let(:left) { original_left }
|
163
|
+
let(:right) { original_right }
|
164
|
+
|
165
|
+
it { should equal(object) }
|
166
|
+
|
167
|
+
it 'executes left_body#each' do
|
168
|
+
left_body.should_receive(:each)
|
169
|
+
subject
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'executes right_body#each' do
|
173
|
+
right_body.should_receive(:each)
|
174
|
+
subject
|
175
|
+
end
|
176
|
+
|
177
|
+
it_should_behave_like 'an optimize method'
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'left and right are materialized relations' do
|
181
|
+
let(:left) { Relation.new(header, [ [ 1 ], [ 2 ] ]) }
|
182
|
+
let(:right) { Relation.new(header, [ [ 1 ] ]) }
|
183
|
+
|
184
|
+
it { should eql(Relation::Materialized.new(header, [ [ 1 ], [ 2 ] ])) }
|
185
|
+
|
186
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
187
|
+
should == object
|
188
|
+
end
|
189
|
+
|
190
|
+
it_should_behave_like 'an optimize method'
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logic::Connective::Conjunction, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:object) { described_class.new(left, right) }
|
8
|
+
|
9
|
+
it_should_behave_like 'Logic::Connective::Binary#optimize'
|
10
|
+
|
11
|
+
context 'left and right are predicates' do
|
12
|
+
let(:left) { attribute.gt(1) }
|
13
|
+
let(:right) { attribute.lt(3) }
|
14
|
+
|
15
|
+
it { should equal(object) }
|
16
|
+
|
17
|
+
it_should_behave_like 'an optimize method'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'left and right are inverse predicates' do
|
21
|
+
let(:left) { Logic::Connective::Negation.new(attribute.gt(1)) }
|
22
|
+
let(:right) { Logic::Connective::Negation.new(attribute.lt(3)) }
|
23
|
+
|
24
|
+
it { should_not equal(object) }
|
25
|
+
|
26
|
+
it 'reverses the operands' do
|
27
|
+
should eql(described_class.new(attribute.lte(1), attribute.gte(3)))
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like 'an optimize method'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'left and right are the same' do
|
34
|
+
let(:left) { attribute.gt(1) }
|
35
|
+
let(:right) { attribute.gt(1) }
|
36
|
+
|
37
|
+
it { should eql(left) }
|
38
|
+
|
39
|
+
it_should_behave_like 'an optimize method'
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'left and right are tautologys' do
|
43
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
44
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
45
|
+
|
46
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
47
|
+
|
48
|
+
it_should_behave_like 'an optimize method'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'left and right are contradictions' do
|
52
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
53
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
54
|
+
|
55
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
56
|
+
|
57
|
+
it_should_behave_like 'an optimize method'
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'right is a tautology' do
|
61
|
+
let(:left) { attribute.gt(1) }
|
62
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
63
|
+
|
64
|
+
it { should equal(left) }
|
65
|
+
|
66
|
+
it_should_behave_like 'an optimize method'
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'left is a tautology' do
|
70
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
71
|
+
let(:right) { attribute.lt(3) }
|
72
|
+
|
73
|
+
it { should equal(right) }
|
74
|
+
|
75
|
+
it_should_behave_like 'an optimize method'
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'right is a contradiction' do
|
79
|
+
let(:left) { attribute.gt(1) }
|
80
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
81
|
+
|
82
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
83
|
+
|
84
|
+
it_should_behave_like 'an optimize method'
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'left is a contradiction' do
|
88
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
89
|
+
let(:right) { attribute.lt(3) }
|
90
|
+
|
91
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
92
|
+
|
93
|
+
it_should_behave_like 'an optimize method'
|
94
|
+
end
|
95
|
+
|
96
|
+
context 'left and right are Equality predicates for the same attribute and different values' do
|
97
|
+
let(:left) { attribute.eq(1) }
|
98
|
+
let(:right) { attribute.eq(3) }
|
99
|
+
|
100
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
101
|
+
|
102
|
+
it_should_behave_like 'an optimize method'
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'left and right are Inequality predicates for the same attribute and different values' do
|
106
|
+
let(:left) { attribute.ne(1) }
|
107
|
+
let(:right) { attribute.ne(3) }
|
108
|
+
|
109
|
+
it { should eql(attribute.exclude([ 1, 3 ])) }
|
110
|
+
|
111
|
+
it_should_behave_like 'an optimize method'
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'left is an Equality and right is an Inequality predicate for the same attribute and value' do
|
115
|
+
let(:left) { attribute.eq(1) }
|
116
|
+
let(:right) { attribute.ne(1) }
|
117
|
+
|
118
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
119
|
+
|
120
|
+
it_should_behave_like 'an optimize method'
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'left is an Inequality and right is an Equality predicate for the same attribute and value' do
|
124
|
+
let(:left) { attribute.ne(1) }
|
125
|
+
let(:right) { attribute.eq(1) }
|
126
|
+
|
127
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
128
|
+
|
129
|
+
it_should_behave_like 'an optimize method'
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'left is an Inclusion and right is an Exclusion predicate for the same attribute and value' do
|
133
|
+
let(:left) { attribute.include([ 1, 2 ]) }
|
134
|
+
let(:right) { attribute.exclude([ 1, 2 ]) }
|
135
|
+
|
136
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
137
|
+
|
138
|
+
it_should_behave_like 'an optimize method'
|
139
|
+
end
|
140
|
+
|
141
|
+
context 'left is an Exclusion and right is an Inclusion predicate for the same attribute and value' do
|
142
|
+
let(:left) { attribute.exclude([ 1, 2 ]) }
|
143
|
+
let(:right) { attribute.include([ 1, 2 ]) }
|
144
|
+
|
145
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
146
|
+
|
147
|
+
it_should_behave_like 'an optimize method'
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'left is a GreaterThan and right is a LessThanOrEqualTo predicate for the same attribute and value' do
|
151
|
+
let(:left) { attribute.gt(1) }
|
152
|
+
let(:right) { attribute.lte(1) }
|
153
|
+
|
154
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
155
|
+
|
156
|
+
it_should_behave_like 'an optimize method'
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'left is an LessThanOrEqualTo and right is an GreaterThan predicate for the same attribute and value' do
|
160
|
+
let(:left) { attribute.lte(1) }
|
161
|
+
let(:right) { attribute.gt(1) }
|
162
|
+
|
163
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
164
|
+
|
165
|
+
it_should_behave_like 'an optimize method'
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'left is a GreaterThanOrEqualTo and right is a LessThan predicate for the same attribute and value' do
|
169
|
+
let(:left) { attribute.gte(1) }
|
170
|
+
let(:right) { attribute.lt(1) }
|
171
|
+
|
172
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
173
|
+
|
174
|
+
it_should_behave_like 'an optimize method'
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'left is an LessThan and right is an GreaterThanOrEqualTo predicate for the same attribute and value' do
|
178
|
+
let(:left) { attribute.lt(1) }
|
179
|
+
let(:right) { attribute.gte(1) }
|
180
|
+
|
181
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
182
|
+
|
183
|
+
it_should_behave_like 'an optimize method'
|
184
|
+
end
|
185
|
+
|
186
|
+
context 'left is a Match and right is a NoMatch predicate for the same attribute and value' do
|
187
|
+
let(:attribute) { Attribute::String.new(:name) }
|
188
|
+
let(:left) { attribute.match(/Dan Kubb/) }
|
189
|
+
let(:right) { attribute.no_match(/Dan Kubb/) }
|
190
|
+
|
191
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
192
|
+
|
193
|
+
it_should_behave_like 'an optimize method'
|
194
|
+
end
|
195
|
+
|
196
|
+
context 'left is an NoMatch and right is an Match predicate for the same attribute and value' do
|
197
|
+
let(:attribute) { Attribute::String.new(:name) }
|
198
|
+
let(:left) { attribute.no_match(/Dan Kubb/) }
|
199
|
+
let(:right) { attribute.match(/Dan Kubb/) }
|
200
|
+
|
201
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
202
|
+
|
203
|
+
it_should_behave_like 'an optimize method'
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'left and right are predicates for the same attribute and the same values' do
|
207
|
+
let(:left) { attribute.eq(1) }
|
208
|
+
let(:right) { attribute.eq(1) }
|
209
|
+
|
210
|
+
it { should eql(attribute.eq(1)) }
|
211
|
+
|
212
|
+
it_should_behave_like 'an optimize method'
|
213
|
+
end
|
214
|
+
|
215
|
+
context 'left and right are predicates for the same attribute, but left.right is an attribute' do
|
216
|
+
let(:other) { Attribute::Integer.new(:other_id) }
|
217
|
+
let(:left) { attribute.eq(other) }
|
218
|
+
let(:right) { attribute.eq(1) }
|
219
|
+
|
220
|
+
it { should equal(object) }
|
221
|
+
|
222
|
+
it_should_behave_like 'an optimize method'
|
223
|
+
end
|
224
|
+
|
225
|
+
context 'left and right are predicates for the same attribute, but right.right is an attribute' do
|
226
|
+
let(:other) { Attribute::Integer.new(:other_id) }
|
227
|
+
let(:left) { attribute.eq(1) }
|
228
|
+
let(:right) { attribute.eq(other) }
|
229
|
+
|
230
|
+
it { should equal(object) }
|
231
|
+
|
232
|
+
it_should_behave_like 'an optimize method'
|
233
|
+
end
|
234
|
+
end
|
@@ -0,0 +1,235 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logic::Connective::Disjunction, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:object) { described_class.new(left, right) }
|
8
|
+
|
9
|
+
it_should_behave_like 'Logic::Connective::Binary#optimize'
|
10
|
+
|
11
|
+
context 'left and right are predicates' do
|
12
|
+
let(:left) { attribute.gt(1) }
|
13
|
+
let(:right) { attribute.lt(3) }
|
14
|
+
|
15
|
+
it { should equal(object) }
|
16
|
+
|
17
|
+
it_should_behave_like 'an optimize method'
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'left and right are inverse predicates' do
|
21
|
+
let(:left) { Logic::Connective::Negation.new(attribute.gt(1)) }
|
22
|
+
let(:right) { Logic::Connective::Negation.new(attribute.lt(3)) }
|
23
|
+
|
24
|
+
it { should_not equal(object) }
|
25
|
+
|
26
|
+
it 'reverses the operands' do
|
27
|
+
should eql(Logic::Connective::Disjunction.new(attribute.lte(1), attribute.gte(3)))
|
28
|
+
end
|
29
|
+
|
30
|
+
it_should_behave_like 'an optimize method'
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'left and right are the same' do
|
34
|
+
let(:left) { attribute.gt(1) }
|
35
|
+
let(:right) { attribute.gt(1) }
|
36
|
+
|
37
|
+
it { should equal(left) }
|
38
|
+
|
39
|
+
it_should_behave_like 'an optimize method'
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'left and right are tautologys' do
|
43
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
44
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
45
|
+
|
46
|
+
it { should equal(left) }
|
47
|
+
|
48
|
+
it_should_behave_like 'an optimize method'
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'left and right are contradictions' do
|
52
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
53
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
54
|
+
|
55
|
+
|
56
|
+
it { should equal(left) }
|
57
|
+
|
58
|
+
it_should_behave_like 'an optimize method'
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'right is a tautology' do
|
62
|
+
let(:left) { attribute.gt(1) }
|
63
|
+
let(:right) { Logic::Proposition::Tautology.instance }
|
64
|
+
|
65
|
+
it { should equal(right) }
|
66
|
+
|
67
|
+
it_should_behave_like 'an optimize method'
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'left is a tautology' do
|
71
|
+
let(:left) { Logic::Proposition::Tautology.instance }
|
72
|
+
let(:right) { attribute.lt(3) }
|
73
|
+
|
74
|
+
it { should equal(left) }
|
75
|
+
|
76
|
+
it_should_behave_like 'an optimize method'
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'right is a contradiction' do
|
80
|
+
let(:left) { attribute.gt(1) }
|
81
|
+
let(:right) { Logic::Proposition::Contradiction.instance }
|
82
|
+
|
83
|
+
it { should equal(left) }
|
84
|
+
|
85
|
+
it_should_behave_like 'an optimize method'
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'left is a contradiction' do
|
89
|
+
let(:left) { Logic::Proposition::Contradiction.instance }
|
90
|
+
let(:right) { attribute.lt(3) }
|
91
|
+
|
92
|
+
it { should equal(right) }
|
93
|
+
|
94
|
+
it_should_behave_like 'an optimize method'
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'left and right are Equality predicates for the same attribute and different values' do
|
98
|
+
let(:left) { attribute.eq(1) }
|
99
|
+
let(:right) { attribute.eq(3) }
|
100
|
+
|
101
|
+
it { should eql(attribute.include([ 1, 3 ])) }
|
102
|
+
|
103
|
+
it_should_behave_like 'an optimize method'
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'left and right are Inequality predicates for the same attribute and different values' do
|
107
|
+
let(:left) { attribute.ne(1) }
|
108
|
+
let(:right) { attribute.ne(3) }
|
109
|
+
|
110
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
111
|
+
|
112
|
+
it_should_behave_like 'an optimize method'
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'left is an Equality and right is an Inequality predicate for the same attribute and value' do
|
116
|
+
let(:left) { attribute.eq(1) }
|
117
|
+
let(:right) { attribute.ne(1) }
|
118
|
+
|
119
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
120
|
+
|
121
|
+
it_should_behave_like 'an optimize method'
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'left is an Inequality and right is an Equality predicate for the same attribute and value' do
|
125
|
+
let(:left) { attribute.ne(1) }
|
126
|
+
let(:right) { attribute.eq(1) }
|
127
|
+
|
128
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
129
|
+
|
130
|
+
it_should_behave_like 'an optimize method'
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'left is an Inclusion and right is an Exclusion predicate for the same attribute and value' do
|
134
|
+
let(:left) { attribute.include([ 1, 2 ]) }
|
135
|
+
let(:right) { attribute.exclude([ 1, 2 ]) }
|
136
|
+
|
137
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
138
|
+
|
139
|
+
it_should_behave_like 'an optimize method'
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'left is an Exclusion and right is an Inclusion predicate for the same attribute and value' do
|
143
|
+
let(:left) { attribute.exclude([ 1, 2 ]) }
|
144
|
+
let(:right) { attribute.include([ 1, 2 ]) }
|
145
|
+
|
146
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
147
|
+
|
148
|
+
it_should_behave_like 'an optimize method'
|
149
|
+
end
|
150
|
+
|
151
|
+
context 'left is a GreaterThan and right is a LessThanOrEqualTo predicate for the same attribute and value' do
|
152
|
+
let(:left) { attribute.gt(1) }
|
153
|
+
let(:right) { attribute.lte(1) }
|
154
|
+
|
155
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
156
|
+
|
157
|
+
it_should_behave_like 'an optimize method'
|
158
|
+
end
|
159
|
+
|
160
|
+
context 'left is an LessThanOrEqualTo and right is an GreaterThan predicate for the same attribute and value' do
|
161
|
+
let(:left) { attribute.lte(1) }
|
162
|
+
let(:right) { attribute.gt(1) }
|
163
|
+
|
164
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
165
|
+
|
166
|
+
it_should_behave_like 'an optimize method'
|
167
|
+
end
|
168
|
+
|
169
|
+
context 'left is a GreaterThanOrEqualTo and right is a LessThan predicate for the same attribute and value' do
|
170
|
+
let(:left) { attribute.gte(1) }
|
171
|
+
let(:right) { attribute.lt(1) }
|
172
|
+
|
173
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
174
|
+
|
175
|
+
it_should_behave_like 'an optimize method'
|
176
|
+
end
|
177
|
+
|
178
|
+
context 'left is an LessThan and right is an GreaterThanOrEqualTo predicate for the same attribute and value' do
|
179
|
+
let(:left) { attribute.lt(1) }
|
180
|
+
let(:right) { attribute.gte(1) }
|
181
|
+
|
182
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
183
|
+
|
184
|
+
it_should_behave_like 'an optimize method'
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'left is a Match and right is a NoMatch predicate for the same attribute and value' do
|
188
|
+
let(:attribute) { Attribute::String.new(:name) }
|
189
|
+
let(:left) { attribute.match(/Dan Kubb/) }
|
190
|
+
let(:right) { attribute.no_match(/Dan Kubb/) }
|
191
|
+
|
192
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
193
|
+
|
194
|
+
it_should_behave_like 'an optimize method'
|
195
|
+
end
|
196
|
+
|
197
|
+
context 'left is an NoMatch and right is an Match predicate for the same attribute and value' do
|
198
|
+
let(:attribute) { Attribute::String.new(:name) }
|
199
|
+
let(:left) { attribute.no_match(/Dan Kubb/) }
|
200
|
+
let(:right) { attribute.match(/Dan Kubb/) }
|
201
|
+
|
202
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
203
|
+
|
204
|
+
it_should_behave_like 'an optimize method'
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'left and right are predicates for the same attribute and the same values' do
|
208
|
+
let(:left) { attribute.eq(1) }
|
209
|
+
let(:right) { attribute.eq(1) }
|
210
|
+
|
211
|
+
it { should eql(attribute.eq(1)) }
|
212
|
+
|
213
|
+
it_should_behave_like 'an optimize method'
|
214
|
+
end
|
215
|
+
|
216
|
+
context 'left and right are predicates for the same attribute, but left.right is an attribute' do
|
217
|
+
let(:other) { Attribute::Integer.new(:other_id) }
|
218
|
+
let(:left) { attribute.eq(other) }
|
219
|
+
let(:right) { attribute.eq(1) }
|
220
|
+
|
221
|
+
it { should equal(object) }
|
222
|
+
|
223
|
+
it_should_behave_like 'an optimize method'
|
224
|
+
end
|
225
|
+
|
226
|
+
context 'left and right are predicates for the same attribute, but right.right is an attribute' do
|
227
|
+
let(:other) { Attribute::Integer.new(:other_id) }
|
228
|
+
let(:left) { attribute.eq(1) }
|
229
|
+
let(:right) { attribute.eq(other) }
|
230
|
+
|
231
|
+
it { should equal(object) }
|
232
|
+
|
233
|
+
it_should_behave_like 'an optimize method'
|
234
|
+
end
|
235
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logic::Connective::Negation, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id) }
|
7
|
+
let(:object) { described_class.new(operand) }
|
8
|
+
|
9
|
+
context 'operand is a predicate' do
|
10
|
+
let(:operand) { attribute.gt(1) }
|
11
|
+
|
12
|
+
it { should eql(attribute.lte(1)) }
|
13
|
+
|
14
|
+
it_should_behave_like 'an optimize method'
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'operand is a objected predicate' do
|
18
|
+
let(:predicate) { attribute.gt(1) }
|
19
|
+
let(:operand) { described_class.new(predicate) }
|
20
|
+
|
21
|
+
it { should eql(predicate) }
|
22
|
+
|
23
|
+
it_should_behave_like 'an optimize method'
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'operand is a tautology' do
|
27
|
+
let(:operand) { Logic::Proposition::Tautology.instance }
|
28
|
+
|
29
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
30
|
+
|
31
|
+
it_should_behave_like 'an optimize method'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'operand is a contradiction' do
|
35
|
+
let(:operand) { Logic::Proposition::Contradiction.instance }
|
36
|
+
|
37
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
38
|
+
|
39
|
+
it_should_behave_like 'an optimize method'
|
40
|
+
end
|
41
|
+
end
|