Skip to main content

Crate karpal_proof_derive

Crate karpal_proof_derive 

Source
Expand description

Derive macros for automatic algebraic law verification.

These macros generate #[cfg(test)] modules containing proptest-based property tests that verify algebraic laws for user-defined types.

§Usage

use karpal_proof_derive::VerifySemigroup;

#[derive(Clone, Debug, PartialEq, VerifySemigroup)]
#[verify(strategy = "0u32..100")]
struct MyWrapper(u32);

§Attributes

  • #[verify(strategy = "...")]Required. A proptest strategy expression that generates values of the annotated type. Examples:

    • "0u32..100" for numeric ranges
    • "any::<MyType>()" for types implementing Arbitrary
    • "(0i32..50).prop_map(MyWrapper)" for newtype wrappers
  • #[verify(epsilon = "1e-10")] — Optional. Use approximate floating-point comparison instead of exact PartialEq. The generated tests will use (left - right).abs() < epsilon instead of prop_assert_eq!.

Derive Macros§

VerifyCommutative
Derive VerifyCommutative: generates proptest for commutativity of combine.
VerifyGroup
Derive VerifyGroup: generates proptest for left/right inverse.
VerifyLattice
Derive VerifyLattice: generates proptests for associativity, commutativity, idempotency, and absorption of meet/join.
VerifyMonoid
Derive VerifyMonoid: generates proptest for left/right identity of empty.
VerifyRing
Derive VerifyRing: generates proptest for additive inverse (negate).
VerifySemigroup
Derive VerifySemigroup: generates proptest for associativity of combine.
VerifySemiring
Derive VerifySemiring: generates proptests for additive monoid, multiplicative monoid, distributivity, and zero annihilation.