From f9e9f15f211537c6ab15c3263bed78e08c8ff008 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Tue, 15 Nov 2022 11:19:36 -0500 Subject: [PATCH] Refactor code to use `penalty_factor` method Also, update documentation for the `skunk_score` method. Also, stop using byebug and start using Ruby's debugger. Update CHANGELOG.md to document #102 --- CHANGELOG.md | 1 + lib/skunk/rubycritic/analysed_module.rb | 22 +++++++++++++++------- skunk.gemspec | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40036ff..f8dddc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.2...HEAD) * +* [BUGFIX: Fix documentation and refactor `skunk_score` method](https://github.com/fastruby/skunk/pull/102) * [FEATURE: Improve main workflow](https://github.com/fastruby/skunk/pull/99) * [BUGFIX: Fix analized module test](https://github.com/fastruby/skunk/pull/98) diff --git a/lib/skunk/rubycritic/analysed_module.rb b/lib/skunk/rubycritic/analysed_module.rb index 696e89a..db0a8cc 100644 --- a/lib/skunk/rubycritic/analysed_module.rb +++ b/lib/skunk/rubycritic/analysed_module.rb @@ -10,30 +10,38 @@ class AnalysedModule # Returns a numeric value that represents the skunk_score of a module: # # If module is perfectly covered, skunk score is the same as the - # `churn_times_cost` + # `cost` # # If module has no coverage, skunk score is a penalized value of - # `churn_times_cost` + # `cost` # - # For now the skunk_score is calculated by multiplying `churn_times_cost` + # For now the skunk_score is calculated by multiplying `cost` # times the lack of coverage. # # For example: # - # When `churn_times_cost` is 100 and module is perfectly covered: + # When `cost` is 100 and module is perfectly covered: # skunk_score => 100 # - # When `churn_times_cost` is 100 and module is not covered at all: + # When `cost` is 100 and module is not covered at all: # skunk_score => 100 * 100 = 10_000 # - # When `churn_times_cost` is 100 and module is covered at 75%: + # When `cost` is 100 and module is covered at 75%: # skunk_score => 100 * 25 (percentage uncovered) = 2_500 # # @return [Float] def skunk_score return cost.round(2) if coverage == PERFECT_COVERAGE - (cost * (PERFECT_COVERAGE - coverage.to_i)).round(2) + (cost * penalty_factor).round(2) + end + + # Returns a numeric value that represents the penalty factor based + # on the lack of code coverage (not enough test cases for this module) + # + # @return [Integer] + def penalty_factor + PERFECT_COVERAGE - coverage.to_i end # Returns the value of churn times cost. diff --git a/skunk.gemspec b/skunk.gemspec index 7d34cd5..261c5bd 100644 --- a/skunk.gemspec +++ b/skunk.gemspec @@ -41,8 +41,8 @@ Gem::Specification.new do |spec| spec.add_dependency "rubycritic", ">= 4.5.2", "< 5.0" spec.add_dependency "terminal-table", "~> 1.8.0" - spec.add_development_dependency "byebug", "~> 11" spec.add_development_dependency "codecov", "~> 0.1.16" + spec.add_development_dependency "debug" spec.add_development_dependency "minitest", "~> 5.8.4" spec.add_development_dependency "minitest-around", "~> 0.5.0" spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0.2"