class Crispr::Mutations::Numeric

such as incrementing, decrementing, zeroing, or negating the value.
It generates alternative integer nodes by applying small transformations,
The Numeric class defines mutations for integer literals.

def mutations_for(node)

Returns:
  • (Array) - an array of mutated nodes

Parameters:
  • node (Parser::AST::Node) -- the node to mutate
def mutations_for(node)
  return [] unless node.type == :int
  value = node.children[0]
  # Generate a set of numeric mutations
  mutations = []
  mutations << replace(node, value + 1)
  mutations << replace(node, value - 1)
  mutations << replace(node, 0) unless value.zero?
  mutations << replace(node, -value) unless value.zero?
  mutations
end

def replace(node, new_value)

Returns:
  • (Parser::AST::Node) - the mutated node

Parameters:
  • new_value (Integer) -- the new integer value
  • node (Parser::AST::Node) -- the original node
def replace(node, new_value)
  Parser::AST::Node.new(:int, [new_value], location: node.location)
end