Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmoudgmal authored and Marak committed Sep 27, 2018
1 parent b6ac5f2 commit 8d48361
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,33 @@ 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);
assert.ok(faker.random.number.called);
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 () {
Expand All @@ -328,18 +343,33 @@ 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);
assert.ok(faker.random.number.called);
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 () {
Expand Down

0 comments on commit 8d48361

Please sign in to comment.