diff options
| author | Mahmoud Gamal <[email protected]> | 2017-11-07 15:57:33 +0100 |
|---|---|---|
| committer | Marak <[email protected]> | 2018-09-26 21:37:42 -0400 |
| commit | 8d483617a6feafecece769958d84f94b6523a4a6 (patch) | |
| tree | ddca7d572f367c8c5869f6ebaa5cdc56d54bbd51 | |
| parent | b6ac5f269a0ce79ffa1cfea8ed0dca894c430d89 (diff) | |
| download | faker-8d483617a6feafecece769958d84f94b6523a4a6.tar.xz faker-8d483617a6feafecece769958d84f94b6523a4a6.zip | |
Add tests
| -rw-r--r-- | test/address.unit.js | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/test/address.unit.js b/test/address.unit.js index e4b6e627..00044682 100644 --- a/test/address.unit.js +++ b/test/address.unit.js @@ -300,11 +300,12 @@ describe("address.js", function () { } }); - it("returns latitude with min and max", function () { + it("returns latitude with min and max and default precision", function () { for (var i = 0; i < 100; i++) { sinon.spy(faker.random, 'number'); var latitude = faker.address.latitude(-5, 5); assert.ok(typeof latitude === 'string'); + assert.equal(latitude.split('.')[1].length, 4); var latitude_float = parseFloat(latitude); assert.ok(latitude_float >= -5); assert.ok(latitude_float <= 5); @@ -312,6 +313,20 @@ describe("address.js", function () { faker.random.number.restore(); } }); + + it("returns random latitude with custome precision", function () { + for (var i = 0; i < 100; i++) { + sinon.spy(faker.random, 'number'); + var latitude = faker.address.latitude(undefined, undefined, 7); + assert.ok(typeof latitude === 'string'); + assert.equal(latitude.split('.')[1].length, 7); + var latitude_float = parseFloat(latitude); + assert.ok(latitude_float >= -180); + assert.ok(latitude_float <= 180); + assert.ok(faker.random.number.called); + faker.random.number.restore(); + } + }); }); describe("longitude()", function () { @@ -328,11 +343,12 @@ describe("address.js", function () { } }); - it("returns random longitude with min and max", function () { + it("returns random longitude with min and max and default precision", function () { for (var i = 0; i < 100; i++) { sinon.spy(faker.random, 'number'); var longitude = faker.address.longitude(100, -30); assert.ok(typeof longitude === 'string'); + assert.equal(longitude.split('.')[1].length, 4); var longitude_float = parseFloat(longitude); assert.ok(longitude_float >= -30); assert.ok(longitude_float <= 100); @@ -340,6 +356,20 @@ describe("address.js", function () { faker.random.number.restore(); } }); + + it("returns random longitude with custome precision", function () { + for (var i = 0; i < 100; i++) { + sinon.spy(faker.random, 'number'); + var longitude = faker.address.longitude(undefined, undefined, 7); + assert.ok(typeof longitude === 'string'); + assert.equal(longitude.split('.')[1].length, 7); + var longitude_float = parseFloat(longitude); + assert.ok(longitude_float >= -180); + assert.ok(longitude_float <= 180); + assert.ok(faker.random.number.called); + faker.random.number.restore(); + } + }); }); describe("direction()", function () { |
