1 | import type { Random } from '../../../random/generator/Random.js';
|
2 | import { Stream } from '../../../stream/Stream.js';
|
3 | import { Value } from './Value.js';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export declare abstract class Arbitrary<T> {
|
13 | |
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | abstract generate(mrng: Random, biasFactor: number | undefined): Value<T>;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | abstract canShrinkWithoutContext(value: unknown): value is T;
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | abstract shrink(value: T, context: unknown | undefined): Stream<Value<T>>;
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | filter<U extends T>(refinement: (t: T) => t is U): Arbitrary<U>;
|
74 | /**
|
75 | * Create another arbitrary by filtering values against `predicate`
|
76 | *
|
77 | * All the values produced by the resulting arbitrary
|
78 | * satisfy `predicate(value) == true`
|
79 | *
|
80 | * Be aware that using filter may highly impact the time required to generate a valid entry
|
81 | *
|
82 | * @example
|
83 | * ```typescript
|
84 | * const integerGenerator: Arbitrary<number> = ...;
|
85 | * const evenIntegerGenerator: Arbitrary<number> = integerGenerator.filter(e => e % 2 === 0);
|
86 | * // new Arbitrary only keeps even values
|
87 | * ```
|
88 | *
|
89 | * @param predicate - Predicate, to test each produced element. Return true to keep the element, false otherwise
|
90 | * @returns New arbitrary filtered using predicate
|
91 | *
|
92 | * @remarks Since 0.0.1
|
93 | */
|
94 | filter(predicate: (t: T) => boolean): Arbitrary<T>;
|
95 | /**
|
96 | * Create another arbitrary by mapping all produced values using the provided `mapper`
|
97 | * Values produced by the new arbitrary are the result of applying `mapper` value by value
|
98 | *
|
99 | * @example
|
100 | * ```typescript
|
101 | * const rgbChannels: Arbitrary<{r:number,g:number,b:number}> = ...;
|
102 | * const color: Arbitrary<string> = rgbChannels.map(ch => `#${(ch.r*65536 + ch.g*256 + ch.b).toString(16).padStart(6, '0')}`);
|
103 | * // transform an Arbitrary producing {r,g,b} integers into an Arbitrary of '#rrggbb'
|
104 | * ```
|
105 | *
|
106 | * @param mapper - Map function, to produce a new element based on an old one
|
107 | * @param unmapper - Optional unmap function, it will never be used except when shrinking user defined values. Must throw if value is not compatible (since 3.0.0)
|
108 | * @returns New arbitrary with mapped elements
|
109 | *
|
110 | * @remarks Since 0.0.1
|
111 | */
|
112 | map<U>(mapper: (t: T) => U, unmapper?: (possiblyU: unknown) => T): Arbitrary<U>;
|
113 | /**
|
114 | * Create another arbitrary by mapping a value from a base Arbirary using the provided `fmapper`
|
115 | * Values produced by the new arbitrary are the result of the arbitrary generated by applying `fmapper` to a value
|
116 | * @example
|
117 | * ```typescript
|
118 | * const arrayAndLimitArbitrary = fc.nat().chain((c: number) => fc.tuple( fc.array(fc.nat(c)), fc.constant(c)));
|
119 | * ```
|
120 | *
|
121 | * @param chainer - Chain function, to produce a new Arbitrary using a value from another Arbitrary
|
122 | * @returns New arbitrary of new type
|
123 | *
|
124 | * @remarks Since 1.2.0
|
125 | */
|
126 | chain<U>(chainer: (t: T) => Arbitrary<U>): Arbitrary<U>;
|
127 | /**
|
128 | * Create another Arbitrary with no shrink values
|
129 | *
|
130 | * @example
|
131 | * ```typescript
|
132 | * const dataGenerator: Arbitrary<string> = ...;
|
133 | * const unshrinkableDataGenerator: Arbitrary<string> = dataGenerator.noShrink();
|
134 | * // same values no shrink
|
135 | * ```
|
136 | *
|
137 | * @returns Create another arbitrary with no shrink values
|
138 | * @remarks Since 0.0.9
|
139 | */
|
140 | noShrink(): Arbitrary<T>;
|
141 | /**
|
142 | * Create another Arbitrary that cannot be biased
|
143 | *
|
144 | * @param freq - The biased version will be used one time over freq - if it exists
|
145 | * @remarks Since 1.1.0
|
146 | */
|
147 | noBias(): Arbitrary<T>;
|
148 | }
|
149 |
|
\ | No newline at end of file |