Skip to content

Commit f9e9f15

Browse files
committed
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
1 parent a4ed251 commit f9e9f15

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## main [(unreleased)](https://github.com/fastruby/skunk/compare/v0.5.2...HEAD)
99

1010
* <INSERT YOUR FEATURE OR BUGFIX HERE>
11+
* [BUGFIX: Fix documentation and refactor `skunk_score` method](https://github.com/fastruby/skunk/pull/102)
1112
* [FEATURE: Improve main workflow](https://github.com/fastruby/skunk/pull/99)
1213
* [BUGFIX: Fix analized module test](https://github.com/fastruby/skunk/pull/98)
1314

lib/skunk/rubycritic/analysed_module.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,38 @@ class AnalysedModule
1010
# Returns a numeric value that represents the skunk_score of a module:
1111
#
1212
# If module is perfectly covered, skunk score is the same as the
13-
# `churn_times_cost`
13+
# `cost`
1414
#
1515
# If module has no coverage, skunk score is a penalized value of
16-
# `churn_times_cost`
16+
# `cost`
1717
#
18-
# For now the skunk_score is calculated by multiplying `churn_times_cost`
18+
# For now the skunk_score is calculated by multiplying `cost`
1919
# times the lack of coverage.
2020
#
2121
# For example:
2222
#
23-
# When `churn_times_cost` is 100 and module is perfectly covered:
23+
# When `cost` is 100 and module is perfectly covered:
2424
# skunk_score => 100
2525
#
26-
# When `churn_times_cost` is 100 and module is not covered at all:
26+
# When `cost` is 100 and module is not covered at all:
2727
# skunk_score => 100 * 100 = 10_000
2828
#
29-
# When `churn_times_cost` is 100 and module is covered at 75%:
29+
# When `cost` is 100 and module is covered at 75%:
3030
# skunk_score => 100 * 25 (percentage uncovered) = 2_500
3131
#
3232
# @return [Float]
3333
def skunk_score
3434
return cost.round(2) if coverage == PERFECT_COVERAGE
3535

36-
(cost * (PERFECT_COVERAGE - coverage.to_i)).round(2)
36+
(cost * penalty_factor).round(2)
37+
end
38+
39+
# Returns a numeric value that represents the penalty factor based
40+
# on the lack of code coverage (not enough test cases for this module)
41+
#
42+
# @return [Integer]
43+
def penalty_factor
44+
PERFECT_COVERAGE - coverage.to_i
3745
end
3846

3947
# Returns the value of churn times cost.

skunk.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Gem::Specification.new do |spec|
4141
spec.add_dependency "rubycritic", ">= 4.5.2", "< 5.0"
4242
spec.add_dependency "terminal-table", "~> 1.8.0"
4343

44-
spec.add_development_dependency "byebug", "~> 11"
4544
spec.add_development_dependency "codecov", "~> 0.1.16"
45+
spec.add_development_dependency "debug"
4646
spec.add_development_dependency "minitest", "~> 5.8.4"
4747
spec.add_development_dependency "minitest-around", "~> 0.5.0"
4848
spec.add_development_dependency "minitest-stub_any_instance", "~> 1.0.2"

0 commit comments

Comments
 (0)