mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
fix progress 0/0 panic
This commit is contained in:
parent
47ff93734e
commit
62ea1dea04
1 changed files with 7 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ impl ProgressPercent {
|
|||
pub fn new(current: usize, total: usize) -> Self {
|
||||
let total = f64::conv(cmp::max(current, total));
|
||||
let progress = f64::conv(current) / total * 100.0;
|
||||
let progress = u8::conv_nearest(progress);
|
||||
let progress = u8::try_conv_nearest(progress).unwrap_or(100);
|
||||
Self { progress }
|
||||
}
|
||||
///
|
||||
|
|
@ -39,6 +39,12 @@ mod tests {
|
|||
assert_eq!(prog.progress, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_progress_zero_all() {
|
||||
let prog = ProgressPercent::new(0, 0);
|
||||
assert_eq!(prog.progress, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_progress_rounding() {
|
||||
let prog = ProgressPercent::new(2, 10);
|
||||
|
|
|
|||
Loading…
Reference in a new issue