Skip to content

Commit

Permalink
Handle out-of-bound values (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 10, 2022
1 parent e009784 commit c645770
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,22 @@ pub(crate) fn run(n: u64) -> Result {
println!("shiny");
}

mined += subsidy(block);
let subsidy = subsidy(block);

if subsidy == 0 {
println!("block:∞");
break;
}

mined += subsidy;

if mined > n {
println!("block:{}", block);
break;
}

block += 1;
}
println!("block:{}", block);

Ok(())
}
2 changes: 2 additions & 0 deletions tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ fn block() -> Result {
assert!(traits(50 * 100_000_000 - 1)?.contains("block:0"));
assert!(traits(50 * 100_000_000)?.contains("block:1"));
assert!(traits(50 * 100_000_000 + 1)?.contains("block:1"));
assert!(traits(2099999997689999)?.contains("block:6929999"));
assert!(traits(2099999997690000)?.contains("block:∞"));
Ok(())
}

Expand Down

0 comments on commit c645770

Please sign in to comment.