forked from manuelbieh/geolib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoDecimal.test.js
52 lines (48 loc) · 1.62 KB
/
toDecimal.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import toDecimal from './toDecimal';
describe('toDecimal', () => {
it('converts a sexagesimal value into decimal representation', () => {
expect(toDecimal('51° 31\' 10.11" N')).toEqual(51.519475);
});
it('returns a decimal value as number if it is already in decimal format', () => {
expect(toDecimal(51.519475)).toEqual(51.519475);
expect(toDecimal('51.519475')).toEqual(51.519475);
});
it('converts a valid coordinate of any type into decimal representation', () => {
expect(toDecimal({ lat: 1, lng: 1 })).toEqual({ lat: 1, lng: 1 });
expect(toDecimal({ lat: '51° 31\' 10.11" N', lng: 1 })).toEqual({
lat: 51.519475,
lng: 1,
});
expect(
toDecimal({
latitude: '51° 31\' 10.11" N',
longitude: '51° 31\' 10.11" N',
})
).toEqual({
latitude: 51.519475,
longitude: 51.519475,
});
expect(toDecimal([1, 2])).toEqual([1, 2]);
expect(toDecimal(["71° 0'", 2])).toEqual([71, 2]);
});
it('converts an array of arbitrary coordinates to an array of decimal coordinates', () => {
expect(toDecimal([{ lat: "71° 0'", lng: 1 }])).toEqual([
{
lat: 71,
lng: 1,
},
]);
expect(
toDecimal([
{ latitude: "71° 0'", longitude: 1 },
["71° 0'", "71° 0'"],
])
).toEqual([
{
latitude: 71,
longitude: 1,
},
[71, 71],
]);
});
});