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
use crate::reactor::*;
impl<S, T> Reactor<S> for Option<T>
where
T: Reactor<S>,
{
type Output = Option<T::Output>;
fn react(&self, state: &S) -> Self::Output {
match self {
Some(r) => Some(r.react(state)),
None => None,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::mock::*;
use proptest::*;
proptest! {
#[test]
fn some(states: Vec<u8>) {
let reactor = Some(Mock::default());
for (i, state) in states.iter().enumerate() {
assert_eq!(reactor.react(state), Some(Ok(())));
assert_eq!(reactor, Some(Mock::new(&states[0..=i])))
}
}
}
proptest! {
#[test]
fn none(states: Vec<u8>) {
let reactor: Option<Mock<_>> = None;
for state in states {
assert_eq!(reactor.react(&state), None);
assert_eq!(reactor, None);
}
}
}
}