Do not emit mutations if signed zero float/double
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
This commit is contained in:
parent
d7992ef8ae
commit
ec55f85804
2 changed files with 56 additions and 17 deletions
|
@ -49,7 +49,11 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def values
|
||||
[0.0, 1.0, -children.first]
|
||||
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
|
||||
|
|
|
@ -3,25 +3,60 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator::Node::Literal, 'float' do
|
||||
let(:source) { '10.0' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '0.0'
|
||||
mutations << '1.0'
|
||||
mutations << random_float.to_s
|
||||
mutations << '(0.0 / 0.0)'
|
||||
mutations << '(1.0 / 0.0)'
|
||||
mutations << '(-1.0 / 0.0)'
|
||||
mutations << '-10.0'
|
||||
end
|
||||
|
||||
let(:random_float) { 7.123 }
|
||||
|
||||
before do
|
||||
Mutant::Random.stub(float: random_float)
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
let(:random_float) { 7.123 }
|
||||
|
||||
context 'positive number' do
|
||||
let(:source) { '10.0' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '0.0'
|
||||
mutations << '1.0'
|
||||
mutations << random_float.to_s
|
||||
mutations << '(0.0 / 0.0)'
|
||||
mutations << '(1.0 / 0.0)'
|
||||
mutations << '(-1.0 / 0.0)'
|
||||
mutations << '-10.0'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context '0.0' do
|
||||
let(:source) { '0.0' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '1.0'
|
||||
mutations << random_float.to_s
|
||||
mutations << '(0.0 / 0.0)'
|
||||
mutations << '(1.0 / 0.0)'
|
||||
mutations << '(-1.0 / 0.0)'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
context '-0.0' do
|
||||
let(:source) { '-0.0' }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'nil'
|
||||
mutations << '1.0'
|
||||
mutations << random_float.to_s
|
||||
mutations << '(0.0 / 0.0)'
|
||||
mutations << '(1.0 / 0.0)'
|
||||
mutations << '(-1.0 / 0.0)'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue