add acceptance test 88

This commit is contained in:
microproofs
2023-08-07 11:55:25 -04:00
committed by Kasey
parent f7d278a472
commit 6254eeb2ed
4 changed files with 53 additions and 32 deletions

View File

@@ -0,0 +1,32 @@
use aiken/math/rational.{Rational}
use aiken/option
pub fn div_by_int_orig(rat: Rational, token_2_amount: Int) -> Option<Int> {
rational.div(
rat,
token_2_amount
|> rational.from_int,
)
|> option.map(rational.truncate)
}
pub fn div_by_int_fixed(rat: Rational, token_2_amount: Int) -> Option<Int> {
when
rational.div(
rat,
token_2_amount
|> rational.from_int,
)
is {
Some(rat) -> Some(rational.truncate(rat))
None -> None
}
}
test sale_failing_test() {
div_by_int_orig(100 |> rational.from_int, 100) == Some(1)
}
test sale_fixed_test() {
div_by_int_fixed(100 |> rational.from_int, 100) == Some(1)
}