add a few tests

geohash, smooth, base64, msgpack
This commit is contained in:
Dave Conway-Jones
2016-04-23 23:57:16 +01:00
parent d89a2bb7a1
commit da8dd1dc30
7 changed files with 542 additions and 9 deletions

View File

@@ -61,7 +61,13 @@ module.exports = function(RED) {
else if (msg.payload.indexOf(",") !== -1) {
// has a comma so assume it's lat,lon(,precision)
var bits = msg.payload.split(",");
if (bits.length === 2) {
if ((bits.length === 2) || (bits.length === 3)) {
var li = 9;
if (bits.length === 3) {
li = parseInt(bits[2]);
if (li < 1) { li = 1; }
if (li > 9) { li = 9; }
}
var la = Number(bits[0]);
if (la < -90) { la = -90; }
if (la > 90) { la = 90; }
@@ -69,7 +75,7 @@ module.exports = function(RED) {
if (lo < -180) { lo = ((lo-180)%360)+180; }
if (lo > 180) { lo = ((lo+180)%360)-180; }
if (!isNaN(la) && !isNaN(lo)) {
msg.payload = geohash.encode(la, lo);
msg.payload = geohash.encode(la, lo, li);
node.send(msg);
} else {
node.warn("Incorrect string format - should be lat,lon");

View File

@@ -1,6 +1,6 @@
{
"name" : "node-red-node-geohash",
"version" : "0.0.5",
"version" : "0.0.6",
"description" : "A Node-RED node to encode and decode lat,lon pairs to a geohash.",
"dependencies" : {
"ngeohash" : "0.6.0"