contrafact 0.2.0-rc.1

A trait for highly composable constraints ("facts") which can be used both to verify data and to generate arbitrary data within those constraints
Documentation
use super::*;

/// Negates a fact
// TODO: `not` in particular would really benefit from Facts having accessible
// labels, since currently you can only get context about why a `not` fact passed,
// not why it fails.
pub fn not<'a, T>(fact: LambdaUnit<'a, T>) -> LambdaUnit<'a, T>
where
    T: Target<'a>,
{
    lambda_unit("not", move |g, t| {
        let label = format!("not({:?})", fact);
        let fact = fact.clone();
        brute(label, move |o| fact.clone().check(o).is_err()).mutate(g, t)
    })
}

// /// Negates a fact, with no context given
// pub fn not<'a, F, T>(fact: F) -> Fact<'a, (), T>
// where
//     F: 'a + Fact<'a, T>,
//     T: Bounds<'a>,
// {
//     not("not", fact)
// }

#[test]
fn test_not() {
    observability::test_run().ok();
    let mut g = utils::random_generator();

    let eq1 = eq(1);
    let not1 = vec(not(eq1));

    let nums = not1.clone().build(&mut g);
    not1.clone().check(&nums).unwrap();

    assert!(nums.iter().all(|x| *x != 1));
}