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
use strategy::*;
use test_runner::*;
use rand::Rng;
#[derive(Clone, Copy, Debug)]
pub struct Any(());
pub const ANY: Any = Any(());
impl Strategy for Any {
type Value = BoolValueTree;
fn new_value(&self, runner: &mut TestRunner) -> NewTree<Self> {
Ok(BoolValueTree(runner.rng().gen()))
}
}
pub fn weighted(probability: f64) -> Weighted {
Weighted(probability)
}
#[derive(Clone, Copy, Debug)]
pub struct Weighted(f64);
impl Strategy for Weighted {
type Value = BoolValueTree;
fn new_value(&self, runner: &mut TestRunner) -> NewTree<Self> {
Ok(BoolValueTree(runner.rng().next_f64() < self.0))
}
}
#[derive(Clone, Copy, Debug)]
pub struct BoolValueTree(bool);
impl ValueTree for BoolValueTree {
type Value = bool;
fn current(&self) -> bool { self.0 }
fn simplify(&mut self) -> bool {
let r = self.0;
self.0 = false;
r
}
fn complicate(&mut self) -> bool {
let r = self.0;
self.0 = true;
!r
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_sanity() {
check_strategy_sanity(ANY, None);
}
}