Expand description
§prop-check-rs
A property-based testing library written in Rust. It leverages functional programming concepts to efficiently generate and validate test data.
§What is Property-Based Testing?
Property-based testing is a testing methodology where instead of testing specific input values, you define properties that your program should satisfy and then verify these properties against a large number of randomly generated inputs. This approach helps discover edge cases that developers might not have anticipated.
§Key Components
-
Gen<A>: A generator for values of typeA. It provides methods likemap,flat_map, andand_thento create new generators from existing ones. -
Gens: A factory for creating various generators for basic types, lists, optional values, and more. -
Prop: A structure representing a property. A property defines a condition to verify against values generated by a generator. -
State<S, A>: A monad representing a computation with stateSthat produces a value of typeA. This allows composing computations while maintaining state.
§Example
use prop_check_rs::gen::Gens;
use prop_check_rs::prop::{for_all_gen, test_with_prop};
use prop_check_rs::rng::RNG;
// Generator for a list of integers from 0 to 100
let gen = Gens::list_of_n(10, Gens::choose_i32(0, 100));
// Property: The list length is always 10
let prop = for_all_gen(gen, |list| {
list.len() == 10
});
// Test the property (max size 1, 100 test cases)
let result = test_with_prop(prop, 1, 100, RNG::new());Modules§
Structs§
Enums§
- SGen
- Generator with size information.