From 9dab0896f018403daaac346e7a927f16c9e34253 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 24 Jun 2013 16:30:09 -0700 Subject: [PATCH] Add geo point tests --- README.md | 12 ++++++++- index.js | 2 +- lib/geo-point.js | 18 ------------- test/geo-point.test.js | 60 +++++++++++++----------------------------- test/support.js | 1 + 5 files changed, 32 insertions(+), 61 deletions(-) delete mode 100644 lib/geo-point.js diff --git a/README.md b/README.md index 2eca44da..7a49cb5f 100644 --- a/README.md +++ b/README.md @@ -689,7 +689,11 @@ Include the connector in your package.json dependencies and run `npm install`. } } -### GeoPoint TODO +### GeoPoint + +Use the `GeoPoint` class. + + var GeoPoint = require('asteroid').GeoPoint; Embed a latitude / longitude point in a [Model](#model). @@ -723,9 +727,15 @@ Get the distance between two points. #### Distance Types +**Note:** all distance methods use `miles` by default. + - `miles` - `radians` - `kilometers` + - `meters` + - `miles` + - `feet` + - `degrees` #### geoPoint.lat diff --git a/index.js b/index.js index fcce0eb6..39bdd874 100644 --- a/index.js +++ b/index.js @@ -15,4 +15,4 @@ asteroid.Memory = require('./lib/connectors/memory'); * Types */ -asteroid.GeoPoint = require('./lib/geo-point'); \ No newline at end of file +asteroid.GeoPoint = require('jugglingdb/lib/geo').GeoPoint; \ No newline at end of file diff --git a/lib/geo-point.js b/lib/geo-point.js deleted file mode 100644 index 8b18e782..00000000 --- a/lib/geo-point.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Export the `GeoPoint` class. - */ - -module.exports = GeoPoint; - -function GeoPoint(data) { - if(!(this instanceof GeoPoint)) { - return new GeoPoint(data); - } - - this.lat = data.lat; - this.lng = data.lng; -} - -// TODO remove this -// register the type -require('jugglingdb/lib/model-builder').ModelBuilder.registerType(GeoPoint); \ No newline at end of file diff --git a/test/geo-point.test.js b/test/geo-point.test.js index fe8be350..fafabb69 100644 --- a/test/geo-point.test.js +++ b/test/geo-point.test.js @@ -1,41 +1,19 @@ -// describe('GeoPoint', function() { -// -// describe('geoPoint.distanceTo(geoPoint, options)', function() { -// it("Get the distance to another `GeoPoint`.", function(done) { -// /* example - -// var here = new GeoPoint({lat: 10, long: 10}); -// var there = new GeoPoint({lat: 5, long: 5}); -// console.log(here.distanceTo(there, {type: 'miles'})); // 438 -// */ -// done(new Error('test not implemented')); -// }); -// }); -// -// describe('GeoPoint.distanceBetween(a, b, options)', function() { -// it("Get the distance between two points.", function(done) { -// /* example - -// GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438 -// */ -// done(new Error('test not implemented')); -// }); -// }); -// -// describe('geoPoint.lat', function() { -// it("The latitude point in degrees", function(done) { -// done(new Error('test not implemented')); -// }); -// }); -// -// describe('geoPoint.long', function() { -// it("The longitude point in degrees", function(done) { -// /* example - -// app.use(asteroid.rest()); -// -// -// app.use(asteroid.sio); -// -// */ -// done(new Error('test not implemented')); -// }); -// }); -// }); \ No newline at end of file +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); + }); + }); +}); \ No newline at end of file diff --git a/test/support.js b/test/support.js index d6b456a6..e620f208 100644 --- a/test/support.js +++ b/test/support.js @@ -5,6 +5,7 @@ assert = require('assert'); asteroid = require('../'); memoryConnector = asteroid.Memory; +GeoPoint = asteroid.GeoPoint; app = null; TaskEmitter = require('sl-task-emitter'); request = require('supertest');