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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
//! This crate provides powerful macros to derive traits from the core crate.
//! It also provides macros to automatically construct AuxStorage structs
//! used to store intermediate data for running update steps and Communicator
//! struct to send messages between threads running the simulation.
//!
//! All macros are documented in the core crate unless their functionality can be
//! displayed without any additional dependencies.
/// Inserts as many blanks as generics were used to create the communicator struct by
/// [build_communicator!].
/// Run a particularly structured test multiple times for combinations of aspects
///
/// The tests which we would like to run are macros that will
/// be given as one argument to this `proc_macro`.
/// These tests need to adhere to a strict format.
/// ```
/// macro_rules! some_test(
/// (
/// name:$test_name:ident,
/// aspects:[$($asp:ident),*]
/// ) => {
/// // Any code can be run here.
/// // For example, we can create a docstring test by using
///
/// /// ```
/// /// assert_eq!(0_usize, 10_usize - 10_usize);
/// $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// /// ```
/// fn $test_name () {}
/// }
/// );
///
/// // This is how you would call the test by hand
///
/// some_test!(
/// name:my_test_name,
/// aspects: [Mechanics, Interaction]
/// );
/// ```
///
/// In the next step, we can use `run_test_for_aspects` to run this automatically generated
/// docstring test for every combination of aspects that we specify.
///
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// # use cellular_raza_core_proc_macro::run_test_for_aspects;
/// run_test_for_aspects!(
/// test: some_test,
/// aspects: [Mechanics, Interaction]
/// );
/// ```
/// This will have generated the following code:
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// some_test!(
/// name:mechanics,
/// aspects: [Mechanics]
/// );
/// some_test!(
/// name:interaction,
/// aspects: [Interaction]
/// );
/// some_test!(
/// name:mechanics_interaction,
/// aspects: [Mechanics, Interaction]
/// );
/// some_test!(
/// name:interaction_mechanics,
/// aspects: [Interaction, Mechanics]
/// );
/// ```
///
/// # Minimum Combinations
/// It is possible to specify a minimum number of combinations to test.
/// This means if we specify N aspects but only want to test combinations of M (where M<N)
/// different aspects, we can set the `min_combinations` variable of this macro.
///
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// # use cellular_raza_core_proc_macro::run_test_for_aspects;
/// run_test_for_aspects!(
/// test: some_test,
/// aspects: [Mechanics, Interaction, Cycle, Reactions],
/// min_combinations: 3,
/// );
/// ```
///
/// # Unsorted Combinations
/// By default all generated combinations of simulation aspects are sorted and will thus not
/// produce different tests when being reordered.
/// This means we assume that `aspects: [Mechanics, Interaction]` is identical to `aspects:
/// [Interaction, Mechanics]`.
/// In the case where we also want to test the unsorted cases, we can specify the `sorted` keyword.
///
/// ```
/// # macro_rules! some_test(
/// # (
/// # name:$test_name:ident,
/// # aspects:[$($asp:ident),*]
/// # ) => {
/// # // Any code can be run here.
/// # // For example, we can create a docstring test by using
/// #
/// # /// ```
/// # /// assert_eq!(0_usize, 10_usize - 10_usize);
/// # $(#[doc = concat!("println!(\"", stringify!($asp), "\")")])*
/// # /// ```
/// # fn $test_name () {}
/// # }
/// # );
/// # use cellular_raza_core_proc_macro::run_test_for_aspects;
/// run_test_for_aspects!(
/// test: some_test,
/// aspects: [Mechanics, Interaction],
/// sorted: false,
/// );
/// ```
/// Construct, test and run a full simulation.
///
/// # Arguments
// TODO use link when compiler error is fixed: https://github.com/rust-lang/rust/issues/123019
/// The `KwargsSim` struct contains all required and optional
/// arguments for this macro.
///
/// # Internals
/// This macro calls [prepare_types!], [test_compatibility!] and [run_main!] one after
/// another with identical arguments (where possible) and thus yields results for a full
/// simulation.
/// Prepares communicator and auxiliary storage types with [build_communicator!] and
/// [build_aux_storage!].
/// Checks if defined types and concepts are compatible before actually executing the simulation.
///
/// This macro only serves the purpose for easy-to-read compiler errors.
/// It has no runtime-overhead since it will be fully optimized away.