Skip to content

Commit

Permalink
test: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pkuczynski committed Mar 29, 2022
1 parent d56e4c7 commit 89851e7
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ export class Address {
latitude(max: number = 90, min: number = -90, precision: number = 4): string {
return this.faker.datatype
.number({
max: max,
min: min,
max,
min,
precision: parseFloat((0.0).toPrecision(precision) + '1'),
})
.toFixed(precision);
Expand Down
6 changes: 1 addition & 5 deletions src/datatype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ export class Datatype {
const precision = typeof opts.precision === 'number' ? opts.precision : 1;

if (max < min) {
throw new Error(`Max should be larger then min: ${max} > ${min}`);
}

if (max === min) {
return max;
throw new Error(`Max ${max} should be larger then min ${min}`);
}

// Make the range inclusive of the max value
Expand Down
2 changes: 1 addition & 1 deletion src/locales/ro/address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const address = {
secondary_address,
state,
state_abbr,
streets,
street_address,
street_name,
street_suffix,
streets,
} as Partial<AddressDefinitions>;

export default address;
2 changes: 1 addition & 1 deletion test/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ describe('address', () => {

it('returns latitude with min and max and default precision', () => {
for (let i = 0; i < 100; i++) {
const latitude = faker.address.latitude(-5, 5);
const latitude = faker.address.latitude(5, -5);

expect(latitude).toBeTypeOf('string');
expect(
Expand Down
19 changes: 11 additions & 8 deletions test/datatype.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const seededRuns = [
number: {
noArgs: 37454,
numbers: [2, 5, 6, 1, 5],
withMin: 37427,
withMin: 37412,
withMinAndMax: -1,
withMax: 26,
withMinAndMaxAndPrecision: -0.43,
},
float: {
noArgs: 37453.64,
numbers: [37452, 79656, 95076, 18342, 73200],
withMin: 37427.37,
withMin: 37411.64,
withMinAndMax: -0.43,
withMax: 25.84,
withMinAndMaxAndPrecision: -0.4261,
Expand Down Expand Up @@ -80,15 +80,15 @@ const seededRuns = [
number: {
noArgs: 26202,
numbers: [1, 3, 1, 1, 1],
withMin: 26171,
withMin: 26160,
withMinAndMax: -13,
withMax: 18,
withMinAndMaxAndPrecision: -12.92,
},
float: {
noArgs: 26202.2,
numbers: [26202, 56052, 15864, 21258, 27810],
withMin: 26171.21,
withMin: 26160.2,
withMinAndMax: -12.92,
withMax: 18.08,
withMinAndMaxAndPrecision: -12.9153,
Expand Down Expand Up @@ -152,15 +152,15 @@ const seededRuns = [
number: {
noArgs: 92852,
numbers: [6, 3, 6, 5, 1],
withMin: 92849,
withMin: 92810,
withMinAndMax: 61,
withMax: 64,
withMinAndMaxAndPrecision: 61.07,
},
float: {
noArgs: 92851.09,
numbers: [92856, 45900, 89346, 77826, 22554],
withMin: 92848.09,
withMin: 92809.09,
withMinAndMax: 61.07,
withMax: 64.07,
withMinAndMaxAndPrecision: 61.0658,
Expand Down Expand Up @@ -290,11 +290,14 @@ describe('datatype', () => {
});

it('should throw when min > max', () => {
const min = 10;
const max = 9;

faker.seed(seed);

expect(() => {
faker.datatype.number({ min: 10, max: 9 });
}).toThrowError(`Max should be larger then min: 9 > 10`);
faker.datatype.number({ min, max });
}).toThrowError(`Max ${max} should be larger then min ${min}`);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const seededRuns = [
seed: 1211,
expectations: {
fileName: 'turnpike_frozen_handcrafted.mka',
commonFileName: 'turnpike_frozen_handcrafted.mka',
commonFileName: 'turnpike_frozen_handcrafted.mp4v',
mimeType: 'text/vnd.fmi.flexstor',
commonFileType: 'application',
commonFileExt: 'htm',
Expand Down

0 comments on commit 89851e7

Please sign in to comment.