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
extern crate fuzzcheck;
use fuzzcheck::Mutator;

#[derive(Clone)]
pub struct BoolMutator {}

impl Default for BoolMutator {
    fn default() -> Self {
        BoolMutator {}
    }
}

impl Mutator for BoolMutator {
    type Value = bool;
    type Cache = ();
    type MutationStep = bool; // true if it has been mutated, false otherwise
    type UnmutateToken = ();

    fn cache_from_value(&self, _value: &Self::Value) -> Self::Cache {}

    fn mutation_step_from_value(&self, _value: &Self::Value) -> Self::MutationStep {
        false
    }

    fn arbitrary(&mut self, seed: usize, _max_cplx: f64) -> (Self::Value, Self::Cache) {
        let value = seed % 2 == 0;
        (value, ())
    }

    fn max_complexity(&self) -> f64 {
        1.0
    }

    fn min_complexity(&self) -> f64 {
        1.0
    }

    fn complexity(&self, _value: &Self::Value, _cache: &Self::Cache) -> f64 {
        1.0
    }

    fn mutate(
        &mut self,
        value: &mut Self::Value,
        _cache: &mut Self::Cache,
        step: &mut Self::MutationStep,
        _max_cplx: f64,
    ) -> Self::UnmutateToken {
        *value = !*value;
        *step = true;
    }

    fn unmutate(&self, value: &mut Self::Value, _cache: &mut Self::Cache, _t: Self::UnmutateToken) {
        *value = !*value;
    }
}