Ferrous API Reference

All Types / Ferrous.Testing

class Gen<T>

public sealed class Gen<T>

A composable, deterministic value generator with optional shrinking for property-based testing with PropAssert (inspired by Rust's proptest).

Type Parameters
T
The generated value type.

Constructors

public Gen(Func<Random, T> sample, Func<T, IEnumerable<T>>? shrink = null)

Initializes a new Gen<T> with a sampling function and optional shrinker.

Methods

public T Sample(Random random)

Generates a single value using the supplied pseudo-random generator.

public IEnumerable<T> Shrink(T value)

Yields simpler candidate values derived from value for counterexample shrinking.

public Gen<TResult> Select<TResult>(Func<T, TResult> selector)

Projects generated values into TResult.

public Gen<T> Where(Func<T, bool> predicate, int maxAttempts = 100)

Filters generated and shrunk values to those satisfying predicate.