Skip to content

Commit

Permalink
fix: avoid NaN accuracy when nothing is typed
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyak2 committed Feb 4, 2024
1 parent c15f8f5 commit ccddff2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl ToipeResults {

/// Percentage of letters that were typed correctly.
pub fn accuracy(&self) -> f64 {
if self.total_chars_typed == 0 {
return 0.0;
}

(self.total_chars_typed as isize - self.total_char_errors as isize) as f64
/ self.total_chars_typed as f64
}
Expand Down

0 comments on commit ccddff2

Please sign in to comment.