Skip to content

Commit

Permalink
Document use of Number.MAX_SAFE_INTEGER
Browse files Browse the repository at this point in the history
Fixes #98
Fixes #99
  • Loading branch information
dubzzz committed May 21, 2018
1 parent d752e66 commit b45b90e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/check/arbitrary/IntegerArbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ class IntegerArbitrary extends ArbitraryWithShrink<number> {
function integer(): ArbitraryWithShrink<number>;
/**
* For integers between -2147483648 (included) and max (included)
* @param max Upper bound for the generated integers
* @param max Upper bound for the generated integers (eg.: 2147483647, Number.MAX_SAFE_INTEGER)
*/
function integer(max: number): ArbitraryWithShrink<number>;
/**
* For integers between min (included) and max (included)
* @param min Lower bound for the generated integers
* @param max Upper bound for the generated integers
*
* @param min Lower bound for the generated integers (eg.: 0, Number.MIN_SAFE_INTEGER)
* @param max Upper bound for the generated integers (eg.: 2147483647, Number.MAX_SAFE_INTEGER)
*/
function integer(min: number, max: number): ArbitraryWithShrink<number>;
function integer(a?: number, b?: number): ArbitraryWithShrink<number> {
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/arbitraries/IntegerArbitrary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,15 @@ describe(`IntegerArbitrary (seed: ${seed})`, () => {
assert.ok(out.failed, 'Should have failed');
assert.deepEqual(out.counterexample, [100], 'Should shrink to counterexample 100');
});
it('Should detect overflow', () => {
const out = fc.check(
fc.property(
fc.nat(Number.MAX_SAFE_INTEGER),
fc.nat(Number.MAX_SAFE_INTEGER),
(a: number, b: number) => a + b !== a + b + 1
)
);
assert.ok(out.failed, 'Should have failed');
});
});
});

0 comments on commit b45b90e

Please sign in to comment.