From 894da9078a526a76d965486906192ec1f1120da6 Mon Sep 17 00:00:00 2001 From: Victor Quinn Date: Tue, 2 Sep 2014 14:13:27 -0400 Subject: [PATCH] Add geohash method --- chance.js | 7 ++++++- test/test.address.js | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chance.js b/chance.js index 4c8fa7aa..e001ca3d 100644 --- a/chance.js +++ b/chance.js @@ -626,7 +626,12 @@ return this.latitude(options) + ', ' + this.longitude(options); }; - Chance.prototype.geoJson = function (options) { + Chance.prototype.geohash = function (options) { + options = initOptions(options, { length: 7 }); + return this.string({ length: options.length, pool: '0123456789bcdefghjkmnpqrstuvwxyz' }); + }; + + Chance.prototype.geojson = function (options) { options = initOptions(options); return this.latitude(options) + ', ' + this.longitude(options) + ', ' + this.altitude(options); }; diff --git a/test/test.address.js b/test/test.address.js index c363421b..3ef5bf6d 100644 --- a/test/test.address.js +++ b/test/test.address.js @@ -226,7 +226,20 @@ define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, expect(chance.longitude({max: max})).to.be.within(-180, max); }); }); + }); + + describe("Geohash", function () { + it("geohash() looks right", function() { + expect(chance.geohash()).to.be.a('string'); + expect(chance.geohash()).to.have.length(7); + }); + it("geohash() will accept a length and obey it", function() { + _(1000).times(function () { + var length = chance.d10(); + expect(chance.geohash({ length: length })).to.have.length(length); + }); + }); }); describe("Coordinates", function () {