Skip to content

Commit

Permalink
chore: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT committed Jan 18, 2024
1 parent fe99819 commit e1d13a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/modules/number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ export class NumberModule extends SimpleModuleBase {
* @param options.multipleOf The generated number will be a multiple of this property.
* This property can be used to limit the result to a specific number of decimal digits.
* For example `0.01` will round to 2 decimal points.
* If multipleOf is passed, the upper bound is inclusive and the `fractionDigits` option has to be excluded.
* If `multipleOf` is passed, the upper bound is inclusive.
* This option is incompatible with the `fractionDigits` option.
* @param options.fractionDigits The maximum number of digits to appear after the decimal point.
* This parameter has to be excluded if `multipleOf` is provided.
* This option is incompatible with the `multipleOf` option.
*
* @throws When `min` is greater than `max`.
* @throws When `precision` is negative.
Expand Down
12 changes: 9 additions & 3 deletions test/modules/datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ describe('datatype', () => {

expect(() => {
faker.datatype.float({ min, max });
}).toThrowError(`Max ${max} should be greater than min ${min}.`);
}).toThrow(
new FakerError(`Max ${max} should be greater than min ${min}.`)
);
});

it('should throw when precision <= 0', () => {
Expand All @@ -330,10 +332,14 @@ describe('datatype', () => {

expect(() => {
faker.datatype.float({ min, max, precision: 0 });
}).toThrowError('multipleOf/precision should be greater than 0.');
}).toThrow(
new FakerError('multipleOf/precision should be greater than 0.')
);
expect(() => {
faker.datatype.float({ min, max, precision: -1 });
}).toThrowError('multipleOf/precision should be greater than 0.');
}).toThrow(
new FakerError('multipleOf/precision should be greater than 0.')
);
});
});

Expand Down
7 changes: 4 additions & 3 deletions test/modules/number.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,17 @@ describe('number', () => {
expect(results).toEqual([0, 0.4, 0.8, 1.2, 1.6]);
});

it('provides numbers with an exact fractional digits', () => {
for (let i = 0; i < 100; i++) {
it.each(times(100))(
'provides numbers with an exact fractional digits',
() => {
const actual = faker.number.float({
min: 0.5,
max: 0.99,
fractionDigits: 2,
});
expect(actual).toBe(Number(actual.toFixed(2)));
}
});
);

it('throws an error if fractionDigits and multipleOf is provided at the same time', () => {
expect(() =>
Expand Down

0 comments on commit e1d13a5

Please sign in to comment.