-
Notifications
You must be signed in to change notification settings - Fork 1
/
number.test.ts
35 lines (29 loc) · 1.17 KB
/
number.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
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';
import { number } from './number';
describe(number, () => {
it('accepts an arbitrary number', () => {
const decoder = number();
fc.assert(
fc.property(
fc.float().filter((x) => Number.isFinite(x) && !Object.is(x, -0)),
(n) => {
const variable = new Variable('KEY', String(n));
expect(decoder(variable)).toStrictEqual(E.right(n));
},
),
);
});
test.each([Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY])('rejects "%s"', (str) => {
const decoder = number();
const variable = new Variable('KEY', String(str));
expect(decoder(variable)).toStrictEqual(E.left(new DecodeFailed(variable, 'must be finite')));
});
test.each([[-0, 0]])('regards "%s" as `%s`', (input, output) => {
const decoder = number();
const variable = new Variable('KEY', String(input));
expect(decoder(variable)).toStrictEqual(E.right(output));
});
});