Skip to content

Commit

Permalink
Merge pull request #1225 from edwinsamodra/create-bigInt
Browse files Browse the repository at this point in the history
rebuild bigInt generator pull request
  • Loading branch information
Marak authored Oct 16, 2021
2 parents dae7901 + a5f25f7 commit 58dedb9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/datatype.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ function Datatype (faker, seed) {

};

/**
* returns a Big Integer with values generated by faker.datatype.bigInt
* @method faker.datatype.bigInt
* @param { number } value
*/

this.bigInt = function bigInt(value) {
if(value === undefined){
value = Math.floor(Math.random() * 99999999999) + 10000000000;
}

return BigInt(value);
};

return this;
}

Expand Down
23 changes: 23 additions & 0 deletions test/datatype.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,27 @@ describe("datatype.js", function () {
});
});

describe('bigInt', function () {
it('should generate a bigInt value', function () {
var generateBigInt = faker.datatype.bigInt();
assert.strictEqual(typeof generateBigInt, 'bigint');
});

it('Generate and compare two numbers of data type BigInt, with seeding', function () {
faker.seed(123);
var generateBigInt1 = faker.datatype.bigInt();
faker.seed(123);
var generateBigInt2 = faker.datatype.bigInt();
assert.strictEqual(generateBigInt1, generateBigInt2);
});

it('summing with the Number datatype should be an error', function(done) {
try {
faker.datatype.bigInt() + 10
} catch (error) {
done();
}
});
});

});

0 comments on commit 58dedb9

Please sign in to comment.