UNPKG

1.94 kBTypeScriptView Raw
1import { Arbitrary } from '../arbitrary/definition/Arbitrary';
2import { IRawProperty } from '../property/IRawProperty';
3import { Parameters } from './configuration/Parameters';
4/**
5 * Generate an array containing all the values that would have been generated during {@link assert} or {@link check}
6 *
7 * @example
8 * ```typescript
9 * fc.sample(fc.nat(), 10); // extract 10 values from fc.nat() Arbitrary
10 * fc.sample(fc.nat(), {seed: 42}); // extract values from fc.nat() as if we were running fc.assert with seed=42
11 * ```
12 *
13 * @param generator - {@link IProperty} or {@link Arbitrary} to extract the values from
14 * @param params - Integer representing the number of values to generate or `Parameters` as in {@link assert}
15 *
16 * @remarks Since 0.0.6
17 * @public
18 */
19declare function sample<Ts>(generator: IRawProperty<Ts> | Arbitrary<Ts>, params?: Parameters<Ts> | number): Ts[];
20/**
21 * Gather useful statistics concerning generated values
22 *
23 * Print the result in `console.log` or `params.logger` (if defined)
24 *
25 * @example
26 * ```typescript
27 * fc.statistics(
28 * fc.nat(999),
29 * v => v < 100 ? 'Less than 100' : 'More or equal to 100',
30 * {numRuns: 1000, logger: console.log});
31 * // Classify 1000 values generated by fc.nat(999) into two categories:
32 * // - Less than 100
33 * // - More or equal to 100
34 * // The output will be sent line by line to the logger
35 * ```
36 *
37 * @param generator - {@link IProperty} or {@link Arbitrary} to extract the values from
38 * @param classify - Classifier function that can classify the generated value in zero, one or more categories (with free labels)
39 * @param params - Integer representing the number of values to generate or `Parameters` as in {@link assert}
40 *
41 * @remarks Since 0.0.6
42 * @public
43 */
44declare function statistics<Ts>(generator: IRawProperty<Ts> | Arbitrary<Ts>, classify: (v: Ts) => string | string[], params?: Parameters<Ts> | number): void;
45export { sample, statistics };