-
Notifications
You must be signed in to change notification settings - Fork 1
/
bigInt.test.ts
48 lines (42 loc) · 1.53 KB
/
bigInt.test.ts
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';
import { bigInt } from './bigInt';
describe(bigInt, () => {
it('accepts an arbitrary bigint', () => {
fc.assert(
fc.property(fc.bigInt(), (n) => {
const variable = new Variable('KEY', String(n));
expect(bigInt()(variable)).toStrictEqual(E.right(n));
}),
);
});
describe('max', () => {
const max = 42;
it('accepts an arbitrary bigint smaller or equal to max', () => {
fc.assert(
fc.property(
fc.bigInt().filter((n) => n <= max),
(n) => {
const variable = new Variable('KEY', String(n));
expect(bigInt({ max: 42n })(variable)).toStrictEqual(E.right(n));
},
),
);
});
it('accepts an arbitrary bigint greater than max', () => {
fc.assert(
fc.property(
fc.bigInt().filter((n) => n > 42),
(n) => {
const variable = new Variable('KEY', String(n));
expect(bigInt({ max: 42n })(variable)).toStrictEqual(
E.left(new DecodeFailed(variable, 'must be smaller than or equal to 42')),
);
},
),
);
});
});
});