big_int/
test_utils.rs

1//! Various utility macros for testing.
2
3/// Create a list of pairs of randomly generated ints, constrained
4/// by the sizes of the associated int types passed.
5#[macro_export(local_inner_macros)]
6macro_rules! test_pairs {
7    ($([$t:ty; $n:literal]),*) => {
8        {
9            ::std::iter::empty()$(.chain((0..$n).map(|_| (
10                ::rand::random::<$t>() as i128,
11                ::rand::random::<$t>() as i128
12            ))))*
13        }
14    };
15}
16
17/// Create a list of randomly generated ints, constrained
18/// by the sizes of the associated int types passed.
19#[macro_export(local_inner_macros)]
20macro_rules! test_values {
21    ($([$t:ty; $n:literal]),*) => {
22        {
23            ::std::iter::empty()$(.chain((0..$n).map(|_|
24                ::rand::random::<$t>() as i128,
25            )))*
26        }
27    };
28}
29
30/// Format out a vec of bytes as a list of binary numbers.
31#[macro_export(local_inner_macros)]
32macro_rules! bytestr {
33    ($d:expr) => {
34        $d.iter()
35            .map(|d| format!("{d:08b}"))
36            .collect::<Vec<_>>()
37            .join(" ");
38    };
39}
40
41/// dbg! but don't multiline-print
42#[macro_export(local_inner_macros)]
43macro_rules! sdbg {
44    ($val:expr) => {
45        match $val {
46            tmp => {
47                ::std::eprintln!(
48                    "[{}:{}] {} = {:?}",
49                    ::std::file!(),
50                    ::std::line!(),
51                    ::std::stringify!($val),
52                    &tmp
53                );
54                tmp
55            }
56        }
57    };
58}