diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2025-01-26 12:25:24 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2025-01-26 12:25:24 +0100 |
| commit | b8d51740ef8236639b7ac1eada6cf1a64750529a (patch) | |
| tree | 7fb3b678479f9da10b3eee81fef679525e75f323 /pbt/ts/src/property.ts | |
| parent | cc78d5d55b6e1a941b4f4d99c28e35f1363dbcab (diff) | |
| download | lambda-nantes-b8d51740ef8236639b7ac1eada6cf1a64750529a.tar.gz | |
Move shared code to library
Diffstat (limited to 'pbt/ts/src/property.ts')
| -rw-r--r-- | pbt/ts/src/property.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pbt/ts/src/property.ts b/pbt/ts/src/property.ts index a8c59ba..d4eea28 100644 --- a/pbt/ts/src/property.ts +++ b/pbt/ts/src/property.ts @@ -64,3 +64,40 @@ export function property<A>( return { result: 'OK', tests: i, counterexample: null }; }; } + +// basic generators + +export function listOf<A>(gen: Gen<A>): Gen<A[]> { + return (rng: Prando) => { + let g = gen(rng); + return (size: number) => { + let result = []; + for (let i = 0; i < size; i++) { + result.push(g(size)); + } + return result; + }; + }; +} + +export function shrinklist<A>(arr: A[]): A[][] { + let result = []; + + let tail = arr.slice(1); + let keep1 = arr.slice(); + keep1.splice(1, 1); + result.push(tail,keep1); + + if (arr.length >3) { + let half = Math.floor(arr.length / 2); + let copy = arr.slice(); + let secondHalf = copy.slice(half); + result.push(secondHalf); + } + + return result; +} + +export let someInt : Gen<number> = (rng: Prando) => + (size: number) => + rng.nextInt(-size, size); |
