maelstrom_test/
lib.rs

1#[macro_export]
2macro_rules! cjid {
3    [$n:expr] => {
4        maelstrom_base::ClientJobId::from($n)
5    };
6}
7
8#[macro_export]
9macro_rules! cid {
10    [$n:expr] => { maelstrom_base::ClientId::from($n) };
11}
12
13#[macro_export]
14macro_rules! wid {
15    [$n:expr] => { maelstrom_base::WorkerId::from($n) };
16}
17
18#[macro_export]
19macro_rules! mid {
20    [$n:expr] => { maelstrom_base::MonitorId::from($n) };
21}
22
23#[macro_export]
24macro_rules! jid {
25    [$n:expr] => {
26        jid!($n, $n)
27    };
28    [$cid:expr, $cjid:expr] => {
29        maelstrom_base::JobId{cid: $crate::cid![$cid], cjid: $crate::cjid![$cjid]}
30    };
31}
32
33#[macro_export]
34macro_rules! spec {
35    (1 $($field:tt)*) => {
36        maelstrom_base::job_spec! {
37            "test_1",
38            [maelstrom_base::tar_digest!(1)]
39            $($field)*
40        }
41    };
42    (2 $($field:tt)*) => {
43        maelstrom_base::job_spec! {
44            "test_2",
45            [maelstrom_base::tar_digest!(2)],
46            arguments: ["arg_1"]
47            $($field)*
48        }
49    };
50    (3 $($field:tt)*) => {
51        maelstrom_base::job_spec! {
52            "test_3",
53            [maelstrom_base::tar_digest!(3)],
54            arguments: ["arg_1", "arg_2"]
55            $($field)*
56        }
57    };
58    (4 $($field:tt)*) => {
59        maelstrom_base::job_spec! {
60            "test_4",
61            [maelstrom_base::tar_digest!(4)],
62            arguments: ["arg_1", "arg_2", "arg_3"]
63            $($field)*
64        }
65    };
66    ($n:literal $($field:tt)*) => {
67        maelstrom_base::job_spec! {
68            concat!("test_", stringify!($n)),
69            [maelstrom_base::tar_digest!($n)],
70            arguments: ["arg_1"]
71            $($field)*
72        }
73    };
74}
75
76#[macro_export]
77macro_rules! completed {
78    [1] => {
79        maelstrom_base::JobCompleted {
80            status: maelstrom_base::JobTerminationStatus::Exited(0),
81            effects: maelstrom_base::JobEffects {
82                stdout: maelstrom_base::JobOutputResult::None,
83                stderr: maelstrom_base::JobOutputResult::None,
84                duration: std::time::Duration::from_secs(1),
85            }
86        }
87    };
88    [2] => {
89        maelstrom_base::JobCompleted {
90            status: maelstrom_base::JobTerminationStatus::Exited(1),
91            effects: maelstrom_base::JobEffects {
92                stdout: maelstrom_base::JobOutputResult::None,
93                stderr: maelstrom_base::JobOutputResult::None,
94                duration: std::time::Duration::from_secs(1),
95            }
96        }
97    };
98    [3] => {
99        maelstrom_base::JobCompleted {
100            status: maelstrom_base::JobTerminationStatus::Signaled(15),
101            effects: maelstrom_base::JobEffects {
102                stdout: maelstrom_base::JobOutputResult::None,
103                stderr: maelstrom_base::JobOutputResult::None,
104                duration: std::time::Duration::from_secs(1),
105            }
106        }
107    };
108    [$n:expr] => {
109        maelstrom_base::JobCompleted {
110            status: maelstrom_base::JobTerminationStatus::Exited($n),
111            effects: maelstrom_base::JobEffects {
112                stdout: maelstrom_base::JobOutputResult::None,
113                stderr: maelstrom_base::JobOutputResult::None,
114                duration: std::time::Duration::from_secs(1),
115            }
116        }
117    };
118}
119
120#[macro_export]
121macro_rules! outcome {
122    [1] => { maelstrom_base::JobOutcome::Completed($crate::completed![1]) };
123    [2] => { maelstrom_base::JobOutcome::Completed($crate::completed![2]) };
124    [3] => { maelstrom_base::JobOutcome::Completed($crate::completed![3]) };
125    [$n:expr] => { maelstrom_base::JobOutcome::Completed($crate::completed![$n]) };
126}
127
128#[macro_export]
129macro_rules! path_buf {
130    ($e:expr) => {
131        std::path::Path::new($e).to_path_buf()
132    };
133}
134
135#[macro_export]
136macro_rules! utf8_path_buf {
137    ($e:expr) => {
138        maelstrom_base::Utf8PathBuf::from($e)
139    };
140}
141
142#[macro_export]
143macro_rules! boxed_u8 {
144    ($n:expr) => {
145        $n.to_vec().into_boxed_slice()
146    };
147}
148
149#[macro_export]
150macro_rules! string {
151    ($e:expr) => {
152        $e.to_string()
153    };
154}
155
156#[macro_export]
157macro_rules! string_vec {
158    [$($e:expr),*] => {
159        vec![$($e.to_string()),*]
160    };
161    [$($e:expr),*,] => {
162        vec![$($e.to_string()),*]
163    };
164}
165
166#[macro_export]
167macro_rules! millis {
168    ($millis:expr) => {
169        Duration::from_millis($millis)
170    };
171}