forked from strongloop/loopback
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo-point.test.js
63 lines (56 loc) · 2.07 KB
/
geo-point.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
53
54
55
56
57
58
59
60
61
62
63
// Copyright IBM Corp. 2013,2016. All Rights Reserved.
// Node module: loopback
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
describe('GeoPoint', function() {
describe('geoPoint.distanceTo(geoPoint, options)', function() {
it('Get the distance to another `GeoPoint`', function() {
var here = new GeoPoint({ lat: 10, lng: 10 });
var there = new GeoPoint({ lat: 5, lng: 5 });
var distance = here.distanceTo(there, { type: 'meters' });
assert.equal(Math.floor(distance), 782777);
});
});
describe('GeoPoint.distanceBetween(a, b, options)', function() {
it('Get the distance between two points', function() {
var here = new GeoPoint({ lat: 10, lng: 10 });
var there = new GeoPoint({ lat: 5, lng: 5 });
var distance = GeoPoint.distanceBetween(here, there, { type: 'feet' });
assert.equal(Math.floor(distance), 2568169);
});
});
describe('GeoPoint()', function() {
it('Create from string', function() {
var point = new GeoPoint('1.234,5.678');
assert.equal(point.lat, 1.234);
assert.equal(point.lng, 5.678);
var point2 = new GeoPoint('1.222, 5.333');
assert.equal(point2.lat, 1.222);
assert.equal(point2.lng, 5.333);
var point3 = new GeoPoint('1.333, 5.111');
assert.equal(point3.lat, 1.333);
assert.equal(point3.lng, 5.111);
});
it('Serialize as string', function() {
var str = '1.234,5.678';
var point = new GeoPoint(str);
assert.equal(point.toString(), str);
});
it('Create from array', function() {
var point = new GeoPoint([5.555, 6.777]);
assert.equal(point.lat, 5.555);
assert.equal(point.lng, 6.777);
});
it('Create as Model property', function() {
var Model = loopback.createModel('geo-model', {
geo: { type: 'GeoPoint' },
});
var m = new Model({
geo: '1.222,3.444',
});
assert(m.geo instanceof GeoPoint);
assert.equal(m.geo.lat, 1.222);
assert.equal(m.geo.lng, 3.444);
});
});
});