1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import {
pairOf,
positiveInt,
property,
shrinkPair,
shrinkPositive,
} 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');
}
});
});
|