loopback/test/geo-point.test.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2013-06-24 23:30:09 +00:00
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});
assert.equal(here.distanceTo(there, {type: 'meters'}), 782777.923052584);
});
});
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});
assert.equal(GeoPoint.distanceBetween(here, there, {type: 'feet'}), 2568169.038886431);
});
});
2013-06-26 03:29:58 +00:00
describe('GeoPoint()', function(){
2013-07-16 20:41:17 +00:00
it('Create from string', function() {
2013-06-26 03:29:58 +00:00
var point = new GeoPoint('1.234,5.678');
assert.equal(point.lng, 1.234);
assert.equal(point.lat, 5.678);
var point2 = new GeoPoint('1.222, 5.333');
assert.equal(point2.lng, 1.222);
assert.equal(point2.lat, 5.333);
var point3 = new GeoPoint('1.333, 5.111');
assert.equal(point3.lng, 1.333);
assert.equal(point3.lat, 5.111);
});
2013-07-16 20:41:17 +00:00
it('Serialize as string', function() {
2013-06-26 03:29:58 +00:00
var str = '1.234,5.678';
var point = new GeoPoint(str);
assert.equal(point.toString(), str);
});
2013-07-16 20:41:17 +00:00
it('Create from array', function() {
2013-06-26 03:29:58 +00:00
var point = new GeoPoint([5.555, 6.777]);
assert.equal(point.lng, 5.555);
assert.equal(point.lat, 6.777);
});
it('Create as Model property', function() {
2013-07-16 17:49:25 +00:00
var Model = loopback.createModel('geo-model', {
2013-06-26 03:29:58 +00:00
geo: {type: 'GeoPoint'}
});
var m = new Model({
geo: '1.222,3.444'
});
assert(m.geo instanceof GeoPoint);
assert.equal(m.geo.lng, 1.222);
assert.equal(m.geo.lat, 3.444);
});
});
2013-06-24 23:30:09 +00:00
});