From 2a46c19f932da6f08a0fc71cb92def44f4f08075 Mon Sep 17 00:00:00 2001 From: James Drew Date: Mon, 22 Dec 2014 21:52:01 +0000 Subject: Added unit test for uuid generator --- test/random.unit.js | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index 6071767b..da1274fd 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -61,4 +61,12 @@ describe("random.js", function () { assert.equal(opts.max, max); }); }); + + describe('UUID', function() { + it('should generate a valid UUID', function() { + var UUID = faker.random.uuid(); + var RFC4122 = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/; + assert.ok(RFC4122.test(UUID)); + }) + }) }); -- cgit v1.2.3 From 22488b7b678e00b7db591f4bcd91dbdd57ed450e Mon Sep 17 00:00:00 2001 From: Evan Sharp Date: Tue, 17 Mar 2015 08:58:46 -0400 Subject: Fix random number unit test spec Updated the "returns a random number given a maximum value as Object" to include the max value in the check (changed `<` to `<=`) --- test/random.unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index da1274fd..a67e42fd 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -17,7 +17,7 @@ describe("random.js", function () { it("returns a random number given a maximum value as Object", function() { var options = { max: 10 }; - assert.ok(faker.random.number(options) < options.max); + assert.ok(faker.random.number(options) <= options.max); }); it("returns a random number between a range", function() { -- cgit v1.2.3 From cb82376c37716f765aee2a856567a02d1d1233ff Mon Sep 17 00:00:00 2001 From: Phil Greenberg Date: Wed, 10 Jun 2015 22:49:12 -0700 Subject: Fixing bug in random.number when max = 0 Also added tests for random.array_element --- test/random.unit.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index a67e42fd..97612c47 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -14,12 +14,16 @@ describe("random.js", function () { assert.ok(faker.random.number(max) <= max); }); - it("returns a random number given a maximum value as Object", function() { var options = { max: 10 }; assert.ok(faker.random.number(options) <= options.max); }); + it("returns a random number given a maximum value of 0", function() { + var options = { max: 0 }; + assert.ok(faker.random.number(options) === 0); + }); + it("returns a random number between a range", function() { var options = { min: 22, max: 33 }; for(var i = 0; i < 100; i++) { @@ -62,6 +66,18 @@ describe("random.js", function () { }); }); + describe('array_element', function() { + it('returns a random element in the array', function() { + var testArray = ['hello', 'to', 'you', 'my', 'friend']; + assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + }); + + it('returns a random element in the array when there is only 1', function() { + var testArray = ['hello']; + assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + }); + }); + describe('UUID', function() { it('should generate a valid UUID', function() { var UUID = faker.random.uuid(); -- cgit v1.2.3 From c0b64f7c0f9bd921a8c719a9763d4397ecbf4749 Mon Sep 17 00:00:00 2001 From: Phil Greenberg Date: Wed, 10 Jun 2015 22:58:26 -0700 Subject: Adding test for negative minimum and max = 0 --- test/random.unit.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index 97612c47..c5991d5c 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -24,6 +24,11 @@ describe("random.js", function () { assert.ok(faker.random.number(options) === 0); }); + it("returns a random number given a negative number minimum and maximum value of 0", function() { + var options = { min: -100, max: 0 }; + assert.ok(faker.random.number(options) <= options.max); + }); + it("returns a random number between a range", function() { var options = { min: 22, max: 33 }; for(var i = 0; i < 100; i++) { -- cgit v1.2.3 From 687e01b61440a638e7a28d88b33379994ac16cb2 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 10 Apr 2015 08:15:14 +0100 Subject: resolves #176 Add random boolean generator --- test/random.unit.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index c5991d5c..ad4ec1c2 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -90,4 +90,11 @@ describe("random.js", function () { assert.ok(RFC4122.test(UUID)); }) }) + + describe('boolean', function() { + it('should generate a boolean value', function() { + var bool = faker.random.boolean(); + assert.ok(typeof bool == 'boolean'); + }); + }); }); -- cgit v1.2.3 From 4c1b454b8e3c8d87f2569a2ce0d7730dc31ee821 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 8 Jul 2015 23:56:22 -0700 Subject: [api] [refactor] Rename `array_element` and `object_element` to camelCase. Set default max random number to 99999. Added default arguments to some methods. --- test/random.unit.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index ad4ec1c2..201c2267 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -71,15 +71,15 @@ describe("random.js", function () { }); }); - describe('array_element', function() { + describe('arrayElement', function() { it('returns a random element in the array', function() { var testArray = ['hello', 'to', 'you', 'my', 'friend']; - assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + assert.ok(testArray.indexOf(faker.random.arrayElement(testArray)) > -1); }); it('returns a random element in the array when there is only 1', function() { var testArray = ['hello']; - assert.ok(testArray.indexOf(faker.random.array_element(testArray)) > -1); + assert.ok(testArray.indexOf(faker.random.arrayElement(testArray)) > -1); }); }); -- cgit v1.2.3 From 40c13f210afd9a2cd5bf5f60fba7169c6e35ea44 Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Wed, 15 Jul 2015 13:31:51 -0500 Subject: Implemented faker.seed method for randomization seeding --- test/random.unit.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test/random.unit.js') diff --git a/test/random.unit.js b/test/random.unit.js index 201c2267..8f047ee5 100644 --- a/test/random.unit.js +++ b/test/random.unit.js @@ -65,10 +65,16 @@ describe("random.js", function () { }; faker.random.number(opts); - + assert.equal(opts.min, min); assert.equal(opts.max, max); }); + + it('should return deterministic results when seeded', function() { + faker.seed(100); + var name = faker.name.findName(); + assert.equal(name, 'Dulce Jenkins'); + }) }); describe('arrayElement', function() { -- cgit v1.2.3