pub struct UniqueMutator<T, TH, Focus, M> where
T: Clone + 'static,
TH: Hash,
M: Mutator<T>,
Focus: Fn(&T) -> &TH, { /* private fields */ }
Expand description
Experimental mutator which tries to prevent duplicate values to be tested, using a bloom filter
Important: this mutator cannot be used as a submutator.
Implementations
sourceimpl<T, TH, Focus, M> UniqueMutator<T, TH, Focus, M> where
T: Clone + 'static,
TH: Hash,
M: Mutator<T>,
Focus: Fn(&T) -> &TH,
impl<T, TH, Focus, M> UniqueMutator<T, TH, Focus, M> where
T: Clone + 'static,
TH: Hash,
M: Mutator<T>,
Focus: Fn(&T) -> &TH,
sourcepub fn new(mutator: M, focus: Focus) -> Self
pub fn new(mutator: M, focus: Focus) -> Self
Create a new UniqueMutator
by wrapping another mutator.
The Focus
closure points to the hashable part of the value. This should almost always
be the identity function. But there is an exception when we don’t care about some part
of the generated value. For example, a grammar-based mutator implements Mutator<(AST, String)>
,
but it is very likely that the test function will only operate on the String and not the AST.
In that case, the Focus
closure is |x| &x.1
.
Trait Implementations
sourceimpl<T, TH, Focus, M> Mutator<T> for UniqueMutator<T, TH, Focus, M> where
T: Clone + 'static,
TH: Hash,
M: Mutator<T>,
Focus: Fn(&T) -> &TH,
Self: 'static,
impl<T, TH, Focus, M> Mutator<T> for UniqueMutator<T, TH, Focus, M> where
T: Clone + 'static,
TH: Hash,
M: Mutator<T>,
Focus: Fn(&T) -> &TH,
Self: 'static,
type Cache = <M as Mutator<T>>::Cache
type Cache = <M as Mutator<T>>::Cache
Accompanies each value to help compute its complexity and mutate it efficiently.
type MutationStep = <M as Mutator<T>>::MutationStep
type MutationStep = <M as Mutator<T>>::MutationStep
Contains information about what mutations have already been tried.
type ArbitraryStep = <M as Mutator<T>>::ArbitraryStep
type ArbitraryStep = <M as Mutator<T>>::ArbitraryStep
Contains information about what arbitrary values have already been generated.
type UnmutateToken = <M as Mutator<T>>::UnmutateToken
type UnmutateToken = <M as Mutator<T>>::UnmutateToken
Describes how to reverse a mutation
sourcefn default_arbitrary_step(&self) -> Self::ArbitraryStep
fn default_arbitrary_step(&self) -> Self::ArbitraryStep
The first ArbitraryStep
value to be passed to ordered_arbitrary
sourcefn is_valid(&self, value: &T) -> bool
fn is_valid(&self, value: &T) -> bool
Quickly verifies that the value conforms to the mutator’s expectations
sourcefn validate_value(&self, value: &T) -> Option<Self::Cache>
fn validate_value(&self, value: &T) -> Option<Self::Cache>
sourcefn default_mutation_step(
&self,
value: &T,
cache: &Self::Cache
) -> Self::MutationStep
fn default_mutation_step(
&self,
value: &T,
cache: &Self::Cache
) -> Self::MutationStep
Returns the first MutationStep
associated with the value
and cache. Read more
sourcefn max_complexity(&self) -> f64
fn max_complexity(&self) -> f64
The maximum complexity that a value can possibly have.
sourcefn min_complexity(&self) -> f64
fn min_complexity(&self) -> f64
The minimum complexity that a value can possibly have.
sourcefn complexity(&self, value: &T, cache: &Self::Cache) -> f64
fn complexity(&self, value: &T, cache: &Self::Cache) -> f64
Computes the complexity of the value. Read more
sourcefn ordered_arbitrary(
&self,
step: &mut Self::ArbitraryStep,
max_cplx: f64
) -> Option<(T, f64)>
fn ordered_arbitrary(
&self,
step: &mut Self::ArbitraryStep,
max_cplx: f64
) -> Option<(T, f64)>
Generates an entirely new value based on the given ArbitraryStep
. Read more
sourcefn random_arbitrary(&self, _max_cplx: f64) -> (T, f64)
fn random_arbitrary(&self, _max_cplx: f64) -> (T, f64)
Generates an entirely new value. Read more
sourcefn ordered_mutate(
&self,
value: &mut T,
cache: &mut Self::Cache,
step: &mut Self::MutationStep,
subvalue_provider: &dyn SubValueProvider,
max_cplx: f64
) -> Option<(Self::UnmutateToken, f64)>
fn ordered_mutate(
&self,
value: &mut T,
cache: &mut Self::Cache,
step: &mut Self::MutationStep,
subvalue_provider: &dyn SubValueProvider,
max_cplx: f64
) -> Option<(Self::UnmutateToken, f64)>
Mutates a value (and optionally its cache) based on the given
MutationStep
. Read more
sourcefn random_mutate(
&self,
value: &mut T,
cache: &mut Self::Cache,
max_cplx: f64
) -> (Self::UnmutateToken, f64)
fn random_mutate(
&self,
value: &mut T,
cache: &mut Self::Cache,
max_cplx: f64
) -> (Self::UnmutateToken, f64)
Mutates a value (and optionally its cache). Read more
sourcefn unmutate(&self, value: &mut T, cache: &mut Self::Cache, t: Self::UnmutateToken)
fn unmutate(&self, value: &mut T, cache: &mut Self::Cache, t: Self::UnmutateToken)
Undoes a mutation performed on the given value and cache, described by
the given UnmutateToken
. Read more
sourcefn visit_subvalues<'a>(
&self,
value: &'a T,
cache: &'a Self::Cache,
visit: &mut dyn FnMut(&'a dyn Any, f64)
)
fn visit_subvalues<'a>(
&self,
value: &'a T,
cache: &'a Self::Cache,
visit: &mut dyn FnMut(&'a dyn Any, f64)
)
Call the given closure on all subvalues and their complexities.
sourcefn global_search_space_complexity(&self) -> f64
fn global_search_space_complexity(&self) -> f64
The log2 of the number of values that can be produced by this mutator, or an approximation of this number (e.g. the number of bits that are needed to identify each possible value). Read more
Auto Trait Implementations
impl<T, TH, Focus, M> !RefUnwindSafe for UniqueMutator<T, TH, Focus, M>
impl<T, TH, Focus, M> !Send for UniqueMutator<T, TH, Focus, M>
impl<T, TH, Focus, M> !Sync for UniqueMutator<T, TH, Focus, M>
impl<T, TH, Focus, M> Unpin for UniqueMutator<T, TH, Focus, M> where
Focus: Unpin,
M: Unpin,
T: Unpin,
impl<T, TH, Focus, M> !UnwindSafe for UniqueMutator<T, TH, Focus, M>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, M> MutatorExt<T> for M where
M: Mutator<T>,
T: 'static + Clone,
impl<T, M> MutatorExt<T> for M where
M: Mutator<T>,
T: 'static + Clone,
sourcefn filter<F>(self, filter: F) -> FilterMutator<Self, F> where
F: Fn(&T) -> bool,
fn filter<F>(self, filter: F) -> FilterMutator<Self, F> where
F: Fn(&T) -> bool,
Create a mutator which wraps self
but only produces values
for which the given closure returns true
Read more
sourcefn map<To, Map, Parse>(
self,
map: Map,
parse: Parse
) -> MapMutator<T, To, Self, Parse, Map, fn(_: &To, _: f64) -> f64> where
To: Clone + 'static,
Map: Fn(&T) -> To,
Parse: Fn(&To) -> Option<T>,
fn map<To, Map, Parse>(
self,
map: Map,
parse: Parse
) -> MapMutator<T, To, Self, Parse, Map, fn(_: &To, _: f64) -> f64> where
To: Clone + 'static,
Map: Fn(&T) -> To,
Parse: Fn(&To) -> Option<T>,
Create a mutator which wraps self
and transforms the values generated by self
using the map
closure. The second closure, parse
, should apply the opposite
transformation. Read more