This repository was archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathtest.rs
More file actions
111 lines (99 loc) · 3 KB
/
test.rs
File metadata and controls
111 lines (99 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
use crate::binary::encode_unsigned_1::result;
use crate::test::with_process;
use crate::test::*;
use liblumen_alloc::erts::term::prelude::*;
use num_bigint::{BigInt, ToBigInt};
use proptest::strategy::Just;
// 1> binary:encode_unsigned(11111111).
// <<169,138,199>>
#[test]
fn otp_doctest() {
with_process(|process| {
assert_eq!(
result(process, process.integer(11111111)),
Ok(process.binary_from_bytes(&[169, 138, 199]))
)
});
}
#[test]
fn smallest_big_int() {
let largest_small_int_as_big_int: BigInt = SmallInteger::MAX_VALUE.into();
let smallest_big_int: BigInt = largest_small_int_as_big_int + 1;
// 1> binary:encode_unsigned(70368744177664).
// <<64,0,0,0,0,0>>
with_process(|process| {
assert_eq!(
result(process, process.integer(smallest_big_int)),
Ok(process.binary_from_bytes(&[64, 0, 0, 0, 0, 0]))
)
});
}
#[test]
fn big_int_with_middle_zeros() {
let largest_small_int_as_big_int: BigInt = SmallInteger::MAX_VALUE.into();
let big_int_with_middle_zeros: BigInt = largest_small_int_as_big_int + 2;
// 1> binary:encode_unsigned(70368744177665).
// <<64,0,0,0,0,1>>
with_process(|process| {
assert_eq!(
result(process, process.integer(big_int_with_middle_zeros)),
Ok(process.binary_from_bytes(&[64, 0, 0, 0, 0, 1]))
)
});
}
#[test]
fn small_int_with_middle_zeros() {
// 1> binary:encode_unsigned(11075783).
// <<169,0,199>>
let largest_small_int_as_big_int: BigInt = SmallInteger::MAX_VALUE.into();
assert!(11075783.to_bigint().unwrap() < largest_small_int_as_big_int);
with_process(|process| {
assert_eq!(
result(process, process.integer(11075783)),
Ok(process.binary_from_bytes(&[169, 0, 199]))
)
});
}
#[test]
fn small_int_with_trailing_zeros() {
// 1> binary:encode_unsigned(16777216).
// <<1,0,0,0>>
let largest_small_int_as_big_int: BigInt = SmallInteger::MAX_VALUE.into();
assert!(16777216.to_bigint().unwrap() < largest_small_int_as_big_int);
with_process(|process| {
assert_eq!(
result(process, process.integer(16777216)),
Ok(process.binary_from_bytes(&[1, 0, 0, 0]))
)
});
}
#[test]
fn negative_integer() {
run!(
|arc_process| {
(
Just(arc_process.clone()),
strategy::term::integer::negative(arc_process.clone()),
)
},
|(arc_process, non_int)| {
prop_assert_badarg!(result(&arc_process, non_int), "invalid integer conversion");
Ok(())
},
);
}
#[test]
fn not_integer() {
run!(
|arc_process| {
(
Just(arc_process.clone()),
strategy::term::is_not_integer(arc_process.clone()),
)
},
|(arc_process, non_int)| {
prop_assert_badarg!(result(&arc_process, non_int), "invalid integer conversion");
Ok(())
},
);
}