Class: Evilution::Equivalent::Heuristic::ArithmeticIdentity Private
- Inherits:
-
Object
- Object
- Evilution::Equivalent::Heuristic::ArithmeticIdentity
- Defined in:
- lib/evilution/equivalent/heuristic/arithmetic_identity.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- ADDITIVE_IDENTITY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Patterns where the original expression is an arithmetic identity operation. "x + 0" is identity (equals x), so mutating the 0 to something else means the original was a no-op — if the test doesn't catch it, it's likely equivalent.
/[\w)\].]+\s*[+-]\s*0\b|\b0\s*\+\s*[\w(\[]/- MULTIPLICATIVE_IDENTITY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%r{[\w)\].]+\s*[*/]\s*1\b|\b1\s*\*\s*[\w(\[]}- EXPONENT_IDENTITY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/[\w)\].]+\s*\*\*\s*1\b/
Instance Method Summary collapse
- #match?(mutation) ⇒ Boolean private
Instance Method Details
#match?(mutation) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/evilution/equivalent/heuristic/arithmetic_identity.rb', line 13 def match?(mutation) return false unless mutation.operator_name == "integer_literal" removed = diff_line(mutation.diff, "- ") return false unless removed content = removed.sub(/^- /, "") content.match?(ADDITIVE_IDENTITY) || content.match?(MULTIPLICATIVE_IDENTITY) || content.match?(EXPONENT_IDENTITY) end |