1 | import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
|
2 | /**
|
3 | * Constraints to be applied on {@link option}
|
4 | * @remarks Since 2.2.0
|
5 | * @public
|
6 | */
|
7 | export interface OptionConstraints<TNil = null> {
|
8 | /**
|
9 | * The probability to build a nil value is of `1 / freq`
|
10 | * @remarks Since 1.17.0
|
11 | */
|
12 | freq?: number;
|
13 | /**
|
14 | * The nil value (default would be null)
|
15 | * @remarks Since 1.17.0
|
16 | */
|
17 | nil?: TNil;
|
18 | /**
|
19 | * While going deeper and deeper within a recursive structure (see {@link letrec}),
|
20 | * this factor will be used to increase the probability to generate nil.
|
21 | *
|
22 | * Example of values: 0.1 (small impact as depth increases), 0.5, 1 (huge impact as depth increases).
|
23 | *
|
24 | * @remarks Since 2.14.0
|
25 | */
|
26 | depthFactor?: number;
|
27 | /**
|
28 | * Maximal authorized depth. Once this depth has been reached only nil will be used.
|
29 | *
|
30 | * @remarks Since 2.14.0
|
31 | */
|
32 | maxDepth?: number;
|
33 | /**
|
34 | * Depth identifier can be used to share the current depth between several instances.
|
35 | *
|
36 | * By default, if not specified, each instance of option will have its own depth.
|
37 | * In other words: you can have depth=1 in one while you have depth=100 in another one.
|
38 | *
|
39 | * @remarks Since 2.14.0
|
40 | */
|
41 | depthIdentifier?: string;
|
42 | }
|
43 | /**
|
44 | * For either null or a value coming from `arb`
|
45 | *
|
46 | * @param arb - Arbitrary that will be called to generate a non null value
|
47 | *
|
48 | * @remarks Since 0.0.6
|
49 | * @public
|
50 | */
|
51 | declare function option<T>(arb: Arbitrary<T>): Arbitrary<T | null>;
|
52 | /**
|
53 | * For either null or a value coming from `arb` with custom frequency
|
54 | *
|
55 | * @param arb - Arbitrary that will be called to generate a non null value
|
56 | * @param freq - The probability to build a null value is of `1 / freq`
|
57 | *
|
58 | * @deprecated
|
59 | * Superceded by `fc.option(arb, {freq})` - see {@link https://github.com/dubzzz/fast-check/issues/992 | #992}.
|
60 | * Ease the migration with {@link https://github.com/dubzzz/fast-check/tree/main/codemods/unify-signatures | our codemod script}.
|
61 | *
|
62 | * @remarks Since 0.0.6
|
63 | * @public
|
64 | */
|
65 | declare function option<T>(arb: Arbitrary<T>, freq: number): Arbitrary<T | null>;
|
66 | /**
|
67 | * For either nil or a value coming from `arb` with custom frequency
|
68 | *
|
69 | * @param arb - Arbitrary that will be called to generate a non nil value
|
70 | * @param constraints - Constraints on the option
|
71 | *
|
72 | * @remarks Since 1.17.0
|
73 | * @public
|
74 | */
|
75 | declare function option<T, TNil = null>(arb: Arbitrary<T>, constraints: OptionConstraints<TNil>): Arbitrary<T | TNil>;
|
76 | export { option };
|