Skip to content

Commit

Permalink
feat(test): Added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Jul 5, 2016
1 parent 0923cf5 commit 90f0bfc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Lat/lon normalization cause...**sigh**",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "node test.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
Expand Down
30 changes: 30 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const assert = require('assert')
const ll = require('./')

const lat = 38.13234
const lng = 70.01232
const latlng = {lat, lng}
const point = {x: lng, y: lat}
const coordinates = [lng, lat]
const str = `${lng},${lat}`

const pairs = [
// normalization
[latlng, ll(latlng)],
[latlng, ll(point)],
[latlng, ll(coordinates)],
[latlng, ll(str)],

// convert to type, normalizes to `latlng` first in each function
[ll.toCoordinates(latlng), coordinates],
[ll.toPoint(latlng), point],
[ll.toString(latlng), str],

// if the type is known, use the specific convert function directly
[latlng, ll.fromLatlng(latlng)],
[latlng, ll.fromCoordinates(coordinates)],
[latlng, ll.fromPoint(point)],
[latlng, ll.fromString(str)]
]

pairs.forEach((pair) => assert.deepEqual(pair[0], pair[1]))

0 comments on commit 90f0bfc

Please sign in to comment.