Skip to content

Commit

Permalink
Add geohash method
Browse files Browse the repository at this point in the history
  • Loading branch information
victorquinn committed Sep 2, 2014
1 parent 11d1309 commit 894da90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion chance.js
Expand Up @@ -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);
};
Expand Down
13 changes: 13 additions & 0 deletions test/test.address.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 894da90

Please sign in to comment.