Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit e25778b

Browse files
committed
Fix division by zero when calculating counter percentage
1 parent 71d80fd commit e25778b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/swift-dcov/Supporting Types/Counter.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ struct Counter {
55
var total: Int { hits + misses }
66

77
var percentage: Double {
8-
Double(hits) / Double(total) * 100.0
8+
guard total > 0 else { return 0 }
9+
return Double(hits) / Double(total) * 100.0
910
}
1011

1112
init(hits: Int = 0, misses: Int = 0) {

0 commit comments

Comments
 (0)