ec55f85804
There are two representations of zero in IEEE 754. The negative and the positive zero. This commutis removes a mutation that causes the sign to be flipped. These mutations are very uneasy to kill. Currently only these side effects are known: 1 / -0.0 => -Infinity 1 / 0.0 => Infinity 0.0.to_s => "0.0" -0.0.to_s => "-0.0" I'm happy to readd the mutation - when someone adds more wisdom to this case ;) Closes #126
63 lines
1.3 KiB
Ruby
63 lines
1.3 KiB
Ruby
# encoding: utf-8
|
|
|
|
module Mutant
|
|
class Mutator
|
|
class Node
|
|
class Literal < self
|
|
# Mutator for float literals
|
|
class Float < self
|
|
|
|
handle(:float)
|
|
|
|
private
|
|
|
|
# Emit mutants
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def dispatch
|
|
emit_nil
|
|
emit_values(values)
|
|
emit_special_cases
|
|
emit_new { new_self(Random.float) }
|
|
end
|
|
|
|
SPECIAL = [
|
|
NodeHelpers::NAN,
|
|
NodeHelpers::NEGATIVE_INFINITY,
|
|
NodeHelpers::INFINITY
|
|
].freeze
|
|
|
|
# Emit special cases
|
|
#
|
|
# @return [undefined]
|
|
#
|
|
# @api private
|
|
#
|
|
def emit_special_cases
|
|
SPECIAL.each do |value|
|
|
emit(value)
|
|
end
|
|
end
|
|
|
|
# Return values to test against
|
|
#
|
|
# @return [Array]
|
|
#
|
|
# @api private
|
|
#
|
|
def values
|
|
original = children.first
|
|
# Work around a bug in RBX/MRI or JRUBY:
|
|
[0.0, 1.0, -original].delete_if do |value|
|
|
value.eql?(original)
|
|
end
|
|
end
|
|
|
|
end # Float
|
|
end # Literal
|
|
end # Node
|
|
end # Mutator
|
|
end # Mutant
|