Merge pull request #303 from mbj/fix/kill-float-coverage
Kill floats for coverage calculations
This commit is contained in:
commit
21c08e2a93
8 changed files with 101 additions and 11 deletions
|
@ -1,3 +1,3 @@
|
||||||
---
|
---
|
||||||
threshold: 18
|
threshold: 18
|
||||||
total_score: 1220
|
total_score: 1215
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
---
|
---
|
||||||
threshold: 30.6
|
threshold: 30.9
|
||||||
|
|
|
@ -238,7 +238,7 @@ module Mutant
|
||||||
reporter: Reporter::CLI.build($stdout),
|
reporter: Reporter::CLI.build($stdout),
|
||||||
zombie: false,
|
zombie: false,
|
||||||
jobs: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : ::Parallel.processor_count,
|
jobs: Mutant.ci? ? CI_DEFAULT_PROCESSOR_COUNT : ::Parallel.processor_count,
|
||||||
expected_coverage: 100.0
|
expected_coverage: Rational(1)
|
||||||
)
|
)
|
||||||
end # Config
|
end # Config
|
||||||
end # Mutant
|
end # Mutant
|
||||||
|
|
|
@ -134,7 +134,7 @@ module Mutant
|
||||||
raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
|
raise Error, "Could not load integration #{name.inspect} (you may want to try installing the gem mutant-#{name})"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add options
|
# Add mutation options
|
||||||
#
|
#
|
||||||
# @param [OptionParser] opts
|
# @param [OptionParser] opts
|
||||||
#
|
#
|
||||||
|
@ -147,7 +147,7 @@ module Mutant
|
||||||
opts.separator('Options:')
|
opts.separator('Options:')
|
||||||
|
|
||||||
opts.on('--score COVERAGE', 'Fail unless COVERAGE is not reached exactly') do |coverage|
|
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
|
end
|
||||||
opts.on('--use STRATEGY', 'Use STRATEGY for killing mutations', &method(:setup_integration))
|
opts.on('--use STRATEGY', 'Use STRATEGY for killing mutations', &method(:setup_integration))
|
||||||
end
|
end
|
||||||
|
|
|
@ -203,7 +203,7 @@ module Mutant
|
||||||
info 'Mutant configuration:'
|
info 'Mutant configuration:'
|
||||||
info 'Matcher: %s', object.matcher.inspect
|
info 'Matcher: %s', object.matcher.inspect
|
||||||
info 'Integration: %s', object.integration.name
|
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 'Jobs: %d', object.jobs
|
||||||
info 'Includes: %s', object.includes.inspect
|
info 'Includes: %s', object.includes.inspect
|
||||||
info 'Requires: %s', object.requires.inspect
|
info 'Requires: %s', object.requires.inspect
|
||||||
|
@ -245,7 +245,7 @@ module Mutant
|
||||||
info 'Killtime: %0.2fs', killtime
|
info 'Killtime: %0.2fs', killtime
|
||||||
info 'Overhead: %0.2f%%', overhead_percent
|
info 'Overhead: %0.2f%%', overhead_percent
|
||||||
status 'Coverage: %0.2f%%', coverage_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
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def coverage_percent
|
def coverage_percent
|
||||||
coverage * 100
|
(coverage * 100).to_f
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return overhead percent
|
# Return overhead percent
|
||||||
|
|
|
@ -94,7 +94,7 @@ module Mutant
|
||||||
# @api private
|
# @api private
|
||||||
#
|
#
|
||||||
def success?
|
def success?
|
||||||
(coverage * 100).to_f.round(COVERAGE_PRECISION).eql?(env.config.expected_coverage.round(COVERAGE_PRECISION))
|
coverage.eql?(env.config.expected_coverage)
|
||||||
end
|
end
|
||||||
memoize :success?
|
memoize :success?
|
||||||
|
|
||||||
|
|
|
@ -197,12 +197,12 @@ Options:
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with score flag' do
|
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_should_behave_like 'a cli parser'
|
||||||
|
|
||||||
it 'configures expected coverage' do
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
Loading…
Reference in a new issue