minitest-cc 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f0eeacbc8612187f1e09acf48af6bbe01dc408ae645fc34baff37d469791f93
4
- data.tar.gz: 0b8dc1f33f412392782265b63919b305d1d5f9154327242d627769225aff3d42
3
+ metadata.gz: 3057b7420f4eb647e697cfa3e2fb9a0d9586665dfe577b1fc5f5552af8b7b6e8
4
+ data.tar.gz: 57173dbf03435603affd8e078faf958cbe53b227ffbc13e7989e37647e3e17f5
5
5
  SHA512:
6
- metadata.gz: 5807504cf8912e3253123e166fd961cbdceb403d9e4cf7ddaf3a03620b2355070358ddf678b7d75fc8fba676ea5fa8d6072daf7cea3c91127ab7f1c4467477cb
7
- data.tar.gz: 5e825e40992f750669825a5d823f5fcc68ceec3aa420c4d37b813c9b45f6b16062f80eb7e1e5c741785bfc5094cddcc7cd57a4f2e86c3ca50fb09e2331435bec
6
+ metadata.gz: 72bb82508786ca90a692c3812d33a78147282fc2667fda08274feb43ba3dbd88759b079e46237aecdc2a572043de207e2a307f5b71e06ed6e6c814f491e62529
7
+ data.tar.gz: '08d491e36ad409f5b0e827b7631ee55d2aa7f1236fee5631a326bb279ffeecea36019517c04b1a669cdbaf3ae48d42314098d6dc9759a5445735256b65505239'
@@ -6,35 +6,47 @@ module Minitest
6
6
  class FileArray < Array
7
7
  ##
8
8
  # Calculate the lines average of the self array
9
- # @return [Integer] percent of lines executed
9
+ # @return [Float] percent of lines executed
10
10
  def lines_average
11
11
  lines = reduce(0) { |sum, v| sum + v.lines.to_i }
12
+
13
+ return 0.0 if lines.zero?
14
+
12
15
  lines_executed = reduce(0) { |sum, v| sum + v.lines_executed.to_i }
13
- lines_executed * 100 / lines
14
- rescue ZeroDivisionError
15
- 0
16
+ lines_executed * 100.0 / lines
16
17
  end
17
18
 
18
19
  ##
19
20
  # Calculate the branches average of the self array
20
- # @return [Integer] percent of branches executed
21
+ # @return [Float] percent of branches executed
21
22
  def branches_average
22
23
  branches = reduce(0) { |sum, v| sum + v.branches.to_i }
24
+
25
+ return 0.0 if branches.zero?
26
+
23
27
  branches_executed = reduce(0) { |sum, v| sum + v.branches_executed.to_i }
24
- branches_executed * 100 / branches
25
- rescue ZeroDivisionError
26
- 0
28
+ branches_executed * 100.0 / branches
27
29
  end
28
30
 
29
31
  ##
30
32
  # Calculate the methods average of the self array
31
- # @return [Integer] percent of methods executed
33
+ # @return [Float] percent of methods executed
32
34
  def methods_average
33
35
  methods = reduce(0) { |sum, v| sum + v.methods.to_i }
36
+
37
+ return 0.0 if methods.zero?
38
+
34
39
  methods_executed = reduce(0) { |sum, v| sum + v.methods_executed.to_i }
35
- methods_executed * 100 / methods
40
+ methods_executed * 100.0 / methods
41
+ end
42
+
43
+ ##
44
+ # Calculate total average of coverage
45
+ # @return [Float] percent of coverage
46
+ def total_coverage_percent
47
+ (lines_average + branches_average + methods_average) / 3
36
48
  rescue ZeroDivisionError
37
- 0
49
+ 0.0
38
50
  end
39
51
  end
40
52
  end
@@ -154,9 +154,9 @@ module Minitest
154
154
  # @return [Integer] percent of coverage. executed lines / total lines
155
155
  #
156
156
  def lines_percent
157
- lines_executed * 100 / lines
158
- rescue ZeroDivisionError
159
- 0
157
+ return 0.0 if lines.zero?
158
+
159
+ lines_executed * 100.0 / lines
160
160
  end
161
161
 
162
162
  ##
@@ -164,9 +164,9 @@ module Minitest
164
164
  # @return [Integer] percent of coverage. executed branches / total branches
165
165
  #
166
166
  def branches_percent
167
- branches_executed * 100 / branches
168
- rescue ZeroDivisionError
169
- 0
167
+ return 0.0 if branches.zero?
168
+
169
+ branches_executed * 100.0 / branches
170
170
  end
171
171
 
172
172
  ##
@@ -174,9 +174,9 @@ module Minitest
174
174
  # @return [Integer] percent of coverage. executed methods / total methods
175
175
  #
176
176
  def methods_percent
177
- methods_executed * 100 / methods
178
- rescue ZeroDivisionError
179
- 0
177
+ return 0.0 if methods.zero?
178
+
179
+ methods_executed * 100.0 / methods
180
180
  end
181
181
  end
182
182
  end
@@ -3,6 +3,6 @@
3
3
  module Minitest
4
4
  module Cc
5
5
  # plugin version
6
- VERSION = '0.2.0'
6
+ VERSION = '1.0.0'
7
7
  end
8
8
  end
data/lib/minitest/cc.rb CHANGED
@@ -69,6 +69,7 @@ module Minitest
69
69
  else
70
70
  puts resume
71
71
  end
72
+ puts "\nAverage: #{@files.total_coverage_percent.round(2).to_s_color}%"
72
73
  end
73
74
 
74
75
  ##
@@ -97,9 +98,9 @@ module Minitest
97
98
  # @return [String] String with averages
98
99
  def resume
99
100
  str = ''
100
- str += "lines: #{@files.lines_average.to_s_color}%\t" if coverage_mode.include? :lines
101
- str += "branches: #{@files.branches_average.to_s_color}%\t" if coverage_mode.include? :branches
102
- str += "methods: #{@files.methods_average.to_s_color}%\t" if coverage_mode.include? :methods
101
+ str += "Lines: #{@files.lines_average.round(2).to_s_color}%\t" if coverage_mode.include? :lines
102
+ str += "Branches: #{@files.branches_average.round(2).to_s_color}%\t" if coverage_mode.include? :branches
103
+ str += "Methods: #{@files.methods_average.round(2).to_s_color}%\t" if coverage_mode.include? :methods
103
104
  str
104
105
  end
105
106
  end
@@ -120,14 +121,14 @@ class String # :nodoc:
120
121
  end
121
122
  end
122
123
 
123
- class Integer # :nodoc:
124
+ class Float # :nodoc:
124
125
  def to_s_color
125
126
  case self
126
- when 1..33
127
+ when 1.0..33.0
127
128
  to_s.red
128
- when 34..66
129
+ when 33.1..66.0
129
130
  to_s.yellow
130
- when 67..100
131
+ when 66.1..100.0
131
132
  to_s.green
132
133
  else
133
134
  to_s
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-cc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - a-chacon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Plugin for minitest. It provides minimal information about code coverage. '
14
14
  email: