Skip to content

Commit

Permalink
Testing checked_div in walkthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-cichocki committed Oct 11, 2023
1 parent 17bbfcc commit 65de7ea
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/walkthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ mod walkthrough {
let result = percentage.checked_sub(Percentage::new(10));
assert_eq!(result, Ok(Percentage::new(90)));
}
// checked_div
{
let result = Price::from_integer(99).checked_div(Price::from_scale(5, 1));
assert_eq!(result, Ok(Price::from_integer(198)));
}
// checked big div
{
let price = Price::max_instance().checked_big_div(Price::new(50000));
assert_eq!(price, Ok(Price::new(68056473384187692692674921486353642291)));
assert_eq!(
price,
Ok(Price::new(68056473384187692692674921486353642291))
);
}

// checked_from_scale
{
let overflow_err =
Expand All @@ -109,7 +116,8 @@ mod walkthrough {
}
// checked_from_scale_to_value
{
let result = Price::checked_from_scale_to_value(max_price_value, price_scale - 1).unwrap();
let result =
Price::checked_from_scale_to_value(max_price_value, price_scale - 1).unwrap();
assert_eq!(
result,
U256::from_dec_str("3402823669209384634633746074317682114550").unwrap()
Expand All @@ -125,7 +133,7 @@ mod walkthrough {
}
// checked_from_decimal_to_value
{
let result = Price::checked_from_decimal_to_value(Price::max_instance()).unwrap();
let result = Price::checked_from_decimal_to_value(Price::max_instance()).unwrap();
assert_eq!(result, U256::from(Price::max_value()));
}
// checked_big_div_by_number & checked_big_div_by_number_up
Expand Down

0 comments on commit 65de7ea

Please sign in to comment.