Trait contrafact::Fact
source · pub trait Fact<'a, T>: Send + Sync + Clone + Debugwhere
T: Target<'a>,{
// Required methods
fn labeled(self, label: impl ToString) -> Self;
fn label(&self) -> String;
fn mutate(&mut self, g: &mut Generator<'a>, t: T) -> Mutation<T>;
// Provided methods
fn check(self, t: &T) -> Check { ... }
fn satisfy_attempts(&self) -> usize { ... }
fn satisfy(&mut self, g: &mut Generator<'a>, t: T) -> ContrafactResult<T> { ... }
fn build_fallible(self, g: &mut Generator<'a>) -> ContrafactResult<T> { ... }
fn build(self, g: &mut Generator<'a>) -> T { ... }
}
Expand description
A declarative representation of a constraint on some data, which can be used to both make an assertion (check) or to mold some arbitrary existing data into a shape which passes that same assertion (mutate)
Required Methods§
Provided Methods§
sourcefn check(self, t: &T) -> Check
fn check(self, t: &T) -> Check
Assert that the constraint is satisfied for given data.
If the mutation function is written properly, we get a check for free by using a special Generator which fails upon mutation. If this is for some reason unreasonable, a check function can be written by hand, but care must be taken to make sure it perfectly lines up with the mutation function.
sourcefn satisfy_attempts(&self) -> usize
fn satisfy_attempts(&self) -> usize
Make this many attempts to satisfy a constraint before giving up and panicking.
If you are combining highly contentious facts together and relying on randomness to find a solution, this limit may need to be higher. In general, you should try to write facts that don’t interfere with each other so that the constraint can be met on the first attempt, or perhaps the second or third. If necessary, this can be raised to lean more on random search.
sourcefn satisfy(&mut self, g: &mut Generator<'a>, t: T) -> ContrafactResult<T>
fn satisfy(&mut self, g: &mut Generator<'a>, t: T) -> ContrafactResult<T>
Mutate a value such that it satisfies the constraint. If the constraint cannot be satisfied, panic.
sourcefn build_fallible(self, g: &mut Generator<'a>) -> ContrafactResult<T>
fn build_fallible(self, g: &mut Generator<'a>) -> ContrafactResult<T>
Build a new value such that it satisfies the constraint