Class: Henitai::EquivalenceDetector::OperandPredicates

Inherits:
Object
  • Object
show all
Defined in:
lib/henitai/equivalence_detector/operand_predicates.rb

Overview

Recognizes the arithmetic operators and neutral operands that make a mutation provably equivalent to its original -- x + 0, x * 1 and friends.

Extracted from EquivalenceDetector because these decisions are load-bearing for scoring: a mutant marked equivalent leaves both sides of the mutation score, so a false positive quietly changes the reported number. They deserve tests of their own rather than being reached through the detector's private interface.

Constant Summary collapse

ADDITIVE =
%i[+ -].freeze
MULTIPLICATIVE =
%i[* / **].freeze

Instance Method Summary collapse

Instance Method Details

#additive_operator?(operator) ⇒ Boolean

Returns:

  • (Boolean)


20
# File 'lib/henitai/equivalence_detector/operand_predicates.rb', line 20

def additive_operator?(operator) = ADDITIVE.include?(operator)

#multiplicative_operator?(operator) ⇒ Boolean

Returns:

  • (Boolean)


22
# File 'lib/henitai/equivalence_detector/operand_predicates.rb', line 22

def multiplicative_operator?(operator) = MULTIPLICATIVE.include?(operator)

#one_operand?(node) ⇒ Boolean

Multiplicative identity: x * 1, x / 1 and x ** 1 all reduce to x.

Returns:

  • (Boolean)


28
# File 'lib/henitai/equivalence_detector/operand_predicates.rb', line 28

def one_operand?(node) = numeric_operand?(node, 1)

#zero_operand?(node) ⇒ Boolean

Additive identity: x + 0 and x - 0 both reduce to x.

Returns:

  • (Boolean)


25
# File 'lib/henitai/equivalence_detector/operand_predicates.rb', line 25

def zero_operand?(node) = numeric_operand?(node, 0)