test: adds tests for mulCheck and mulWrap

This commit is contained in:
Celso Bonutti Filho 2020-12-23 13:43:34 -03:00
parent f3bd5368f0
commit c98d554328
2 changed files with 72 additions and 0 deletions

View file

@ -270,6 +270,11 @@ mod repl_eval {
expect_success("Num.subWrap Num.minInt 1", "9223372036854775807 : I64");
}
#[test]
fn num_mul_wrap() {
expect_success("Num.mulWrap Num.maxInt 2", "-2 : I64");
}
#[test]
fn list_concat() {
expect_success(

View file

@ -894,4 +894,71 @@ mod gen_num {
f64
);
}
#[test]
fn int_mul_wrap() {
assert_evals_to!(
indoc!(
r#"
Num.mulWrap Num.maxInt 2
"#
),
-2,
i64
);
}
#[test]
fn int_mul_checked() {
assert_evals_to!(
indoc!(
r#"
when Num.mulChecked 20 2 is
Ok v -> v
_ -> -1
"#
),
40,
i64
);
assert_evals_to!(
indoc!(
r#"
when Num.mulChecked Num.maxInt 2 is
Err Overflow -> -1
Ok v -> v
"#
),
-1,
i64
);
}
#[test]
fn float_mul_checked() {
assert_evals_to!(
indoc!(
r#"
when Num.mulChecked 20.0 2.0 is
Ok v -> v
Err Overflow -> -1.0
"#
),
40.0,
f64
);
assert_evals_to!(
indoc!(
r#"
when Num.mulChecked 1.7976931348623157e308 2 is
Err Overflow -> -1
Ok v -> v
"#
),
-1.0,
f64
);
}
}