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

Fix division by zero when calculating counter percentage #5

Merged
merged 1 commit into from
Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/swift-dcov/Supporting Types/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ struct Counter {
var total: Int { hits + misses }

var percentage: Double {
Double(hits) / Double(total) * 100.0
guard total > 0 else { return 0 }
return Double(hits) / Double(total) * 100.0
}

init(hits: Int = 0, misses: Int = 0) {
Expand Down