diff options
| author | Leyla Jähnig <[email protected]> | 2022-04-01 16:10:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-01 14:10:47 +0000 |
| commit | bc7bd571d8d6c70b046a3bda23c61c527ddb1d4a (patch) | |
| tree | 1435dd1bb440b907d9f2ce958cc043e84742b45d | |
| parent | caa5f162933915d60750c7fcc2fde2eb9dcb1c90 (diff) | |
| download | faker-bc7bd571d8d6c70b046a3bda23c61c527ddb1d4a.tar.xz faker-bc7bd571d8d6c70b046a3bda23c61c527ddb1d4a.zip | |
fix: deterministic results for address.nearbyGPSCoordinate (#737)
| -rw-r--r-- | src/address.ts | 8 | ||||
| -rw-r--r-- | test/address.spec.ts | 14 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/address.ts b/src/address.ts index 264b0281..a6f54cca 100644 --- a/src/address.ts +++ b/src/address.ts @@ -538,7 +538,13 @@ export class Address { // This approach will likely result in a higher density of points near the center. const randomCoord = coordinateWithOffset( coordinate, - degreesToRadians(Math.random() * 360.0), + degreesToRadians( + this.faker.datatype.number({ + min: 0, + max: 360, + precision: 1e-4, + }) + ), radius, isMetric ); diff --git a/test/address.spec.ts b/test/address.spec.ts index 5929f462..1b987761 100644 --- a/test/address.spec.ts +++ b/test/address.spec.ts @@ -29,6 +29,7 @@ const seededRuns = [ cardinalDirection: 'East', cardinalDirectionAbbr: 'E', timeZone: 'Europe/Amsterdam', + nearbyGpsCoordinates: ['-0.0394', '0.0396'], }, }, { @@ -58,6 +59,7 @@ const seededRuns = [ cardinalDirection: 'East', cardinalDirectionAbbr: 'E', timeZone: 'Africa/Casablanca', + nearbyGpsCoordinates: ['-0.0042', '0.0557'], }, }, { @@ -87,6 +89,7 @@ const seededRuns = [ cardinalDirection: 'West', cardinalDirectionAbbr: 'W', timeZone: 'Asia/Magadan', + nearbyGpsCoordinates: ['0.0503', '-0.0242'], }, }, ]; @@ -333,6 +336,17 @@ describe('address', () => { expect(timeZone).toEqual(expectations.timeZone); }); }); + + describe('nearbyGPSCoordinate()', () => { + it('returns expected coordinates', () => { + faker.seed(seed); + + // this input is required for all expected results for this function + const coordsInput: [number, number] = [0, 0]; + const coords = faker.address.nearbyGPSCoordinate(coordsInput); + expect(coords).toEqual(expectations.nearbyGpsCoordinates); + }); + }); }); } |
