diff options
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'); + } + }); +}); |
