PgGenerator<T>
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Generates random inputs for PgPropertyRunner, the counterpart of a proptest strategy.
public sealed class PgGenerator<T>Type parameters:
T
The generated value.
Create generators with PgGenerators and compose them with Select<TResult>(Func<T, TResult>), Where(Func<T, bool>) and LINQ query syntax. Every composed generator shrinks a failing input toward simpler values without extra code: numbers toward zero, strings and arrays toward fewer and simpler elements, and choices toward the first alternative.
Inheritance: object
Methods
Section titled “Methods”SelectMany<TResult>(Func<T, PgGenerator<TResult>>)
Section titled “SelectMany<TResult>(Func<T, PgGenerator<TResult>>)”Generates a value, then a value from a generator that depends on it.
public PgGenerator<TResult> SelectMany<TResult>(Func<T, PgGenerator<TResult>> selector)Type parameters:
TResult
The dependent value.
Parameters:
selector — Func<T, PgGenerator<TResult>>
Chooses the dependent generator.
Returns: PgGenerator<TResult>
A generator of dependent values.
SelectMany<TOther, TResult>(Func<T, PgGenerator<TOther>>, Func<T, TOther, TResult>)
Section titled “SelectMany<TOther, TResult>(Func<T, PgGenerator<TOther>>, Func<T, TOther, TResult>)”Generates a value, then a value from a generator that depends on it, and combines them; this supports
multiple from clauses in LINQ query syntax.
public PgGenerator<TResult> SelectMany<TOther, TResult>(Func<T, PgGenerator<TOther>> selector, Func<T, TOther, TResult> resultSelector)Type parameters:
TOther
The dependent value.
TResult
The combined value.
Parameters:
selector — Func<T, PgGenerator<TOther>>
Chooses the dependent generator.
resultSelector — Func<T, TOther, TResult>
Combines both values.
Returns: PgGenerator<TResult>
A generator of combined values.
Select<TResult>(Func<T, TResult>)
Section titled “Select<TResult>(Func<T, TResult>)”Projects each generated value.
public PgGenerator<TResult> Select<TResult>(Func<T, TResult> selector)Type parameters:
TResult
The projected value.
Parameters:
selector — Func<T, TResult>
The projection.
Returns: PgGenerator<TResult>
A generator of projected values, which shrink as their sources do.
Where(Func<T, bool>)
Section titled “Where(Func<T, bool>)”Keeps only values that satisfy a condition, as proptest’s prop_filter does.
public PgGenerator<T> Where(Func<T, bool> predicate)Parameters:
predicate — Func<T, bool>
The condition.
Returns: PgGenerator<T>
A generator that draws again when the condition fails.
After 100 failed draws for one input, the runner rejects that case and generates another. A run fails when it rejects more cases than MaxRejects allows, so prefer constructing valid values with Select<TResult>(Func<T, TResult>) over discarding most of them.