Merge pull request #303 from mbj/fix/kill-float-coverage

Kill floats for coverage calculations
This commit is contained in:
Markus Schirp 2015-03-08 17:48:15 +00:00
commit 21c08e2a93
8 changed files with 101 additions and 11 deletions

View file

@ -1,3 +1,3 @@
---
threshold: 18
total_score: 1220
total_score: 1215

View file

@ -1,2 +1,2 @@
---
threshold: 30.6
threshold: 30.9

View file

@ -238,7 +238,7 @@ module Mutant
reporter: Reporter::CLI.build($stdout),
zombie: false,
jobs: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : ::Parallel.processor_count,
expected_coverage: 100.0
expected_coverage: Rational(1)
)
end # Config
end # Mutant

View file

@ -134,7 +134,7 @@ module Mutant
raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
end
# Add options
# Add mutation options
#
# @param [OptionParser] opts
#
@ -147,7 +147,7 @@ module Mutant
opts.separator('Options:')
opts.on('--score COVERAGE', 'Fail unless COVERAGE is not reached exactly') do |coverage|
update(expected_coverage: Float(coverage))
update(expected_coverage: Rational(coverage, 100))
end
opts.on('--use STRATEGY', 'Use STRATEGY for killing mutations', &method(:setup_integration))
end

View file

@ -203,7 +203,7 @@ module Mutant
info 'Mutant configuration:'
info 'Matcher: %s', object.matcher.inspect
info 'Integration: %s', object.integration.name
info 'Expect Coverage: %0.2f%%', object.expected_coverage.inspect
info 'Expect Coverage: %0.2f%%', (object.expected_coverage * 100)
info 'Jobs: %d', object.jobs
info 'Includes: %s', object.includes.inspect
info 'Requires: %s', object.requires.inspect
@ -245,7 +245,7 @@ module Mutant
info 'Killtime: %0.2fs', killtime
info 'Overhead: %0.2f%%', overhead_percent
status 'Coverage: %0.2f%%', coverage_percent
status 'Expected: %0.2f%%', env.config.expected_coverage
status 'Expected: %0.2f%%', (env.config.expected_coverage * 100)
self
end
@ -258,7 +258,7 @@ module Mutant
# @api private
#
def coverage_percent
coverage * 100
(coverage * 100).to_f
end
# Return overhead percent

View file

@ -94,7 +94,7 @@ module Mutant
# @api private
#
def success?
(coverage * 100).to_f.round(COVERAGE_PRECISION).eql?(env.config.expected_coverage.round(COVERAGE_PRECISION))
coverage.eql?(env.config.expected_coverage)
end
memoize :success?

View file

@ -197,12 +197,12 @@ Options:
end
context 'with score flag' do
let(:flags) { %w[--score 99.5] }
let(:flags) { %w[--score 50.0] }
it_should_behave_like 'a cli parser'
it 'configures expected coverage' do
expect(subject.config.expected_coverage).to eql(99.5)
expect(subject.config.expected_coverage).to eql(Rational(1, 2))
end
end

View file

@ -0,0 +1,90 @@
RSpec.describe Mutant::Result::Env do
let(:object) do
described_class.new(
runtime: double('Runtime'),
env: env,
subject_results: [subject_result]
)
end
let(:env) do
double(
'Env',
config: config,
subjects: [double('Subject')],
mutations: [double('Mutation')]
)
end
let(:config) do
double(
'Config',
expected_coverage: Rational(1, 1)
)
end
let(:subject_result) do
double(
'Subject Result',
amount_mutation_results: results,
amount_mutations_killed: killed,
success?: true
)
end
let(:results) { 1 }
let(:killed) { 0 }
describe '#success?' do
subject { object.success? }
context 'when coverage matches expectation' do
let(:killed) { 1 }
it { should be(true) }
end
context 'when coverage does not match expectation' do
it { should be(false) }
end
end
describe '#failed_subject_results' do
subject { object.failed_subject_results }
it { should eql([]) }
end
describe '#coverage' do
subject { object.coverage }
context 'when there are no results' do
let(:results) { 0 }
it { should eql(Rational(0)) }
end
context 'when there are no kills' do
it { should eql(Rational(0)) }
end
context 'when there are kills' do
let(:killed) { 1 }
let(:results) { 2 }
it { should eql(Rational(1, 2)) }
end
end
describe '#amount_mutations' do
subject { object.amount_mutations }
it { should eql(1) }
end
describe '#amount_subjects' do
subject { object.amount_subjects }
it { should eql(1) }
end
end