aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatt Mayer <[email protected]>2023-05-02 04:39:20 +0700
committerGitHub <[email protected]>2023-05-01 21:39:20 +0000
commit7f9e9df4221d27b0b41a8ca04ea2cf69e7065613 (patch)
tree0b688a002c0ae5153e3e109902bd6b2c6d319c9d /test
parent08cf1d85c8ba29991e47dc4b764172abb2cc0705 (diff)
downloadfaker-7f9e9df4221d27b0b41a8ca04ea2cf69e7065613.tar.xz
faker-7f9e9df4221d27b0b41a8ca04ea2cf69e7065613.zip
fix(test): fix failing latitude test (#2116)
Diffstat (limited to 'test')
-rw-r--r--test/location.spec.ts20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/location.spec.ts b/test/location.spec.ts
index e1b9e1ca..22b5b214 100644
--- a/test/location.spec.ts
+++ b/test/location.spec.ts
@@ -11,6 +11,18 @@ function kilometersToMiles(miles: number) {
return miles * 0.621371;
}
+/**
+ * Returns the number of decimal places a number has
+ */
+function precision(num: number): number {
+ const decimalPart = num.toString().split('.')[1];
+ if (decimalPart === undefined) {
+ return 0;
+ }
+
+ return decimalPart.length;
+}
+
// http://nssdc.gsfc.nasa.gov/planetary/factsheet/earthfact.html
const EQUATORIAL_EARTH_RADIUS = 6378.137;
@@ -239,7 +251,7 @@ describe('location', () => {
const latitude = faker.location.latitude({ max: 5, min: -5 });
expect(
- latitude.toString().split('.')[1].length,
+ precision(latitude),
'The precision of latitude should be 4 digits'
).lessThanOrEqual(4);
@@ -251,7 +263,7 @@ describe('location', () => {
const latitude = faker.location.latitude({ precision: 7 });
expect(
- latitude.toString().split('.')[1].length,
+ precision(latitude),
'The precision of latitude should be 7 digits'
).lessThanOrEqual(7);
@@ -278,7 +290,7 @@ describe('location', () => {
const longitude = faker.location.longitude({ max: 100, min: -30 });
expect(
- longitude.toString().split('.')[1].length,
+ precision(longitude),
'The precision of longitude should be 4 digits'
).lessThanOrEqual(4);
@@ -290,7 +302,7 @@ describe('location', () => {
const longitude = faker.location.longitude({ precision: 7 });
expect(
- longitude.toString().split('.')[1].length,
+ precision(longitude),
'The precision of longitude should be 7 digits'
).lessThanOrEqual(7);