diff options
| author | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-12-01 09:08:49 +0100 |
|---|---|---|
| committer | Arnaud Bailly <arnaud@pankzsoft.com> | 2025-12-01 09:08:49 +0100 |
| commit | 8736fba2ab94cd307905585f81f87d4df9eef3e4 (patch) | |
| tree | 39afadbf91b807f385c8f0be64a1b08fb208f23a /pbt/ts/src/property.test.ts | |
| parent | a8c27de3f4434d8a08e953b95b47a4161f9473ed (diff) | |
| download | lambda-nantes-8736fba2ab94cd307905585f81f87d4df9eef3e4.tar.gz | |
more checks on shrinking
Diffstat (limited to 'pbt/ts/src/property.test.ts')
| -rw-r--r-- | pbt/ts/src/property.test.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/pbt/ts/src/property.test.ts b/pbt/ts/src/property.test.ts new file mode 100644 index 0000000..c4e089d --- /dev/null +++ b/pbt/ts/src/property.test.ts @@ -0,0 +1,34 @@ +import { + pairOf, + positiveInt, + property, + shrinkPair, + shrinkPositive, + someInt, +} from './property'; + +// from https://github.com/jlink/shrinking-challenge/blob/main/challenges/difference.md +const predicate1: (pair: [number, number]) => boolean = ([x, y]) => + x < 10 || x != y; + +describe('Find minimal counterexample', () => { + test('do not shrink example if no shrinker given', () => { + const result = property(pairOf(positiveInt), predicate1)(42, 1); + expect(result.result).toBe('Falsified'); + expect(result.counterexample).toBeNull; + }); + + test('shrink example if shrinker given', () => { + const result = property( + pairOf(positiveInt), + predicate1, + shrinkPair(shrinkPositive, shrinkPositive), + )(42, 1); + expect(result.result).toBe('Falsified'); + if (result.counterexample !== null) { + expect(result.counterexample.counterexample).toStrictEqual([10, 10]); + } else { + fail('no counterexample'); + } + }); +}); |
