From 8736fba2ab94cd307905585f81f87d4df9eef3e4 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Mon, 1 Dec 2025 09:08:49 +0100 Subject: more checks on shrinking --- pbt/ts/src/property.test.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pbt/ts/src/property.test.ts (limited to 'pbt/ts/src/property.test.ts') 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'); + } + }); +}); -- cgit v1.3.1