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
use crate::reactor::*;
macro_rules! impl_reactor_for_array {
() => {};
( $head:ident $(, $tail:ident )* $(,)? ) => {
dedupe_docs!(($( $tail, )*),
impl<S, T> Reactor<S> for [T; count!($( $tail, )*)]
where
T: Reactor<S>,
{
type Output = [T::Output; count!($( $tail, )*)];
fn react(&self, _state: &S) -> Self::Output {
let [$( $tail, )*] = self;
[$( $tail.react(_state), )*]
}
}
);
impl_reactor_for_array!($($tail, )*);
};
}
impl_reactor_for_array!(
_32, _31, _30, _29, _28, _27, _26, _25, _24, _23, _22, _21, _20, _19, _18, _17, _16, _15, _14,
_13, _12, _11, _10, _09, _08, _07, _06, _05, _04, _03, _02, _01, _00
);
#[cfg(test)]
mod tests {
use super::*;
use crate::mock::*;
use proptest::*;
macro_rules! test_reactor_for_array {
() => {};
( $head:ident $(, $tail:ident )* $(,)? ) => {
proptest!(|(states: Vec<u8>)| {
let reactors: [Mock<_>; count!($( $tail, )*)] = Default::default();
for (_i, state) in states.iter().enumerate() {
assert_eq!(reactors.react(state), [Ok(()); count!($( $tail, )*)]);
assert_eq!(reactors, [$( always!($tail, Mock::new(&states[0..=_i])), )*]);
}
});
test_reactor_for_array!($( $tail, )*);
};
}
#[allow(clippy::cognitive_complexity)]
#[test]
fn react() {
test_reactor_for_array!(
_32, _31, _30, _29, _28, _27, _26, _25, _24, _23, _22, _21, _20, _19, _18, _17, _16,
_15, _14, _13, _12, _11, _10, _09, _08, _07, _06, _05, _04, _03, _02, _01, _00
);
}
}