Skip to content

Commit bc7bd57

Browse files
fix: deterministic results for address.nearbyGPSCoordinate (#737)
1 parent caa5f16 commit bc7bd57

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/address.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,13 @@ export class Address {
538538
// This approach will likely result in a higher density of points near the center.
539539
const randomCoord = coordinateWithOffset(
540540
coordinate,
541-
degreesToRadians(Math.random() * 360.0),
541+
degreesToRadians(
542+
this.faker.datatype.number({
543+
min: 0,
544+
max: 360,
545+
precision: 1e-4,
546+
})
547+
),
542548
radius,
543549
isMetric
544550
);

test/address.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const seededRuns = [
2929
cardinalDirection: 'East',
3030
cardinalDirectionAbbr: 'E',
3131
timeZone: 'Europe/Amsterdam',
32+
nearbyGpsCoordinates: ['-0.0394', '0.0396'],
3233
},
3334
},
3435
{
@@ -58,6 +59,7 @@ const seededRuns = [
5859
cardinalDirection: 'East',
5960
cardinalDirectionAbbr: 'E',
6061
timeZone: 'Africa/Casablanca',
62+
nearbyGpsCoordinates: ['-0.0042', '0.0557'],
6163
},
6264
},
6365
{
@@ -87,6 +89,7 @@ const seededRuns = [
8789
cardinalDirection: 'West',
8890
cardinalDirectionAbbr: 'W',
8991
timeZone: 'Asia/Magadan',
92+
nearbyGpsCoordinates: ['0.0503', '-0.0242'],
9093
},
9194
},
9295
];
@@ -333,6 +336,17 @@ describe('address', () => {
333336
expect(timeZone).toEqual(expectations.timeZone);
334337
});
335338
});
339+
340+
describe('nearbyGPSCoordinate()', () => {
341+
it('returns expected coordinates', () => {
342+
faker.seed(seed);
343+
344+
// this input is required for all expected results for this function
345+
const coordsInput: [number, number] = [0, 0];
346+
const coords = faker.address.nearbyGPSCoordinate(coordsInput);
347+
expect(coords).toEqual(expectations.nearbyGpsCoordinates);
348+
});
349+
});
336350
});
337351
}
338352

0 commit comments

Comments
 (0)