diff options
| author | ST-DDT <[email protected]> | 2023-12-01 18:10:05 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-12-01 17:10:05 +0000 |
| commit | 2eca5bc06c5f53efe9fe495577cd930620453794 (patch) | |
| tree | 6a4efd5c42e7bb08261e7b11eb70f58a90fab6b3 /test/modules | |
| parent | 5e0f4f7dd1497e80c2e725a7bee3887abaab25a7 (diff) | |
| download | faker-2eca5bc06c5f53efe9fe495577cd930620453794.tar.xz faker-2eca5bc06c5f53efe9fe495577cd930620453794.zip | |
test(mersenne): add tests for value ranges (#2470)
Diffstat (limited to 'test/modules')
| -rw-r--r-- | test/modules/number.spec.ts | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index 66018ee6..699200b2 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -1,6 +1,7 @@ import validator from 'validator'; import { describe, expect, it } from 'vitest'; -import { faker, FakerError } from '../../src'; +import { faker, FakerError, SimpleFaker } from '../../src'; +import { MERSENNE_MAX_VALUE } from '../internal/mersenne-test-utils'; import { seededTests } from '../support/seeded-runs'; describe('number', () => { @@ -507,4 +508,38 @@ describe('number', () => { }); }); }); + + describe('value range tests', () => { + const customFaker = new SimpleFaker(); + // @ts-expect-error: access private member field + const randomizer = customFaker._randomizer; + describe('int', () => { + it('should be able to return 0', () => { + randomizer.next = () => 0; + const actual = customFaker.number.int(); + expect(actual).toBe(0); + }); + + // TODO @ST-DDT 2023-10-12: This requires a randomizer with 53 bits of precision + it.todo('should be able to return MAX_SAFE_INTEGER', () => { + randomizer.next = () => MERSENNE_MAX_VALUE; + const actual = customFaker.number.int(); + expect(actual).toBe(Number.MAX_SAFE_INTEGER); + }); + }); + + describe('float', () => { + it('should be able to return 0', () => { + randomizer.next = () => 0; + const actual = customFaker.number.float(); + expect(actual).toBe(0); + }); + + it('should be able to return almost 1', () => { + randomizer.next = () => MERSENNE_MAX_VALUE; + const actual = customFaker.number.float(); + expect(actual).toBe(MERSENNE_MAX_VALUE); + }); + }); + }); }); |
