From e4cc4e50d1d4103c26f06fd2db0ca187dbb537cd Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Fri, 11 Apr 2025 20:35:21 +0200 Subject: fix(number): don't ignore multipleOf in float when min=max (#3417) --- test/modules/number.spec.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/modules') diff --git a/test/modules/number.spec.ts b/test/modules/number.spec.ts index 278baadb..60781af8 100644 --- a/test/modules/number.spec.ts +++ b/test/modules/number.spec.ts @@ -156,6 +156,18 @@ describe('number', () => { ); }); + it('throws for impossible multipleOf where min=max', () => { + const input = { + min: 11, + max: 11, + multipleOf: 10, + }; + + expect(() => faker.number.int(input)).toThrow( + new FakerError('No suitable integer value between 11 and 11 found.') + ); + }); + it('should return a random number given a maximum value as Number', () => { const actual = faker.number.int(10); @@ -391,6 +403,32 @@ describe('number', () => { ); }); + it('throws for impossible multipleOf', () => { + const input = { + min: 11, + max: 19, + multipleOf: 10, + }; + + expect(() => faker.number.float(input)).toThrow( + new FakerError( + 'No suitable integer value between 1.1 and 1.9000000000000001 found.' + ) + ); + }); + + it('throws for impossible multipleOf where min=max', () => { + const input = { + min: 11, + max: 11, + multipleOf: 10, + }; + + expect(() => faker.number.float(input)).toThrow( + new FakerError('No suitable integer value between 1.1 and 1.1 found.') + ); + }); + it('should not modify the input object', () => { expect(() => faker.number.float(Object.freeze({ min: 1, max: 2 })) -- cgit v1.2.3