NumBytesToU16 and NumBytesToU32 tested

This commit is contained in:
Joshua Hoeflich 2021-08-18 17:39:59 -05:00
parent a4197d073c
commit 2672c8ed10
3 changed files with 106 additions and 36 deletions

View file

@ -1625,25 +1625,8 @@ mod gen_num {
assert_evals_to!("Num.isMultipleOf -9223372036854775808 -1", true, bool);
}
// TODO: Once we know what the function should do, let's give these real names!
#[test]
fn potato_1() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU16 bytes 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
40,
u16
);
}
#[test]
fn potato_2() {
fn bytes_to_u16_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
@ -1659,23 +1642,23 @@ mod gen_num {
}
#[test]
fn potato_3() {
fn bytes_to_u16_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
bytes = Str.toUtf8 "hello"
when Num.bytesToU32 bytes 0 is
when Num.bytesToU16 bytes 4 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
41,
u32
1,
u16
);
}
#[test]
fn potato_4() {
fn bytes_to_u32_clearly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
@ -1690,9 +1673,8 @@ mod gen_num {
);
}
#[test]
fn potato_5() {
fn bytes_to_u32_subtly_out_of_bounds() {
assert_evals_to!(
indoc!(
r#"
@ -1706,4 +1688,96 @@ mod gen_num {
u32
);
}
#[test]
fn bytes_to_u16_max_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU16 [255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
65535,
u16
);
}
#[test]
fn bytes_to_u16_min_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU16 [0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
0,
u16
);
}
#[test]
fn bytes_to_u16_random_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU16 [164, 215] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
55_204,
u16
);
}
#[test]
fn bytes_to_u32_min_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU32 [0, 0, 0, 0] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
0,
u32
);
}
#[test]
fn bytes_to_u32_max_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU32 [255, 255, 255, 255] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
4_294_967_295,
u32
);
}
#[test]
fn bytes_to_u32_random_u8s() {
assert_evals_to!(
indoc!(
r#"
when Num.bytesToU32 [252, 124, 128, 121] 0 is
Ok v -> v
Err OutOfBounds -> 1
"#
),
2_038_463_740,
u32
);
}
}