A collection of mathematical properties for random testing.
It's based on dicetest.
The author does not consider this crate as stable yet.
```rust use diceprop::{infixfun2, props, FateVarExt}; use dicetest::prelude::*;
fn addisassociativeforsmallf32() { Dicetest::repeatedly().run(|mut fate| { let smallf32die = dice::f32(-100.0..=100.0); let var = fate.rollvar3("f32 ∩ [-100,100]", ["x", "y", "z"], smallf32die); let add = infixfun_2("+", |x, y| x + y); props::binop::associative(var, add); }) } ```
The test fails with the following output:
``` The test failed after 22 passes.
+
associative?
- x, y, z of f32 ∩ [-100,100]
- x = 344.4662
- y = 503.5587
- z = 0.70710677
- (x + y) = 848.0249
- ((x + y) + z) = 848.732
- (y + z) = 504.26578
- (x + (y + z)) = 848.73193
- (((x + y) + z) == (x + (y + z))) = false```rust use diceprop::{fun1, postfixfun_1, props, FateVarExt}; use dicetest::prelude::*;
fn sqrtisleftinverseofsqfornonnegativef32() { Dicetest::repeatedly().run(|mut fate| { let nonnegativef32die = dice::f32(0.0..); let var = fate.rollvar1("f32 ∩ [0,+∞]", "x", nonnegativef32die); let sq = postfixfun1("²", |x| x * x); let sqrt = fun1("√", |x: f32| x.sqrt()); props::fun::left_inverse(var, sq, sqrt); }) } ```
The test fails with the following output:
``` The test failed after 0 passes.
√
left inverse of ²
?
- x of f32 ∩ [0,+∞]
- x = 305770290000000000000000000000000000000.0
- (x)² = inf
- √((x)²) = inf
- (√((x)²) == x) = false```rust use diceprop::{infixfun2, props, FateVarExt}; use dicetest::prelude::*;
fn gtispartialorderforanyf32() { Dicetest::repeatedly().run(|mut fate| { let anyf32die = dice::anyf32(); let var = fate.rollvar3("f32", ["x", "y", "z"], anyf32die); let gt = infixfun2("≤", |x, y| x <= y); props::binrel::partialorder(var, gt); }) } ```
The test fails with the following output:
``` The test failed after 3 passes.
≤
a partial order?
- Is ≤
reflexive?
- x of f32
- x = NaN
- (x ≤ x) = falseLicensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.