aboutsummaryrefslogtreecommitdiff
path: root/test/random.unit.js
diff options
context:
space:
mode:
authorMarak <[email protected]>2017-09-08 16:01:22 -0400
committerGitHub <[email protected]>2017-09-08 16:01:22 -0400
commitd2bc3091e84ba03db44a6e76e938ecf307214a57 (patch)
tree33dc1e1f45824fb94f739249406e68c6ae9b2aa2 /test/random.unit.js
parentaa8ac6cc11bb1be49dfd184289d45c8d9f420734 (diff)
parentfb8653c95016d393ccbbe6441f9952ed333d8e2d (diff)
downloadfaker-d2bc3091e84ba03db44a6e76e938ecf307214a57.tar.xz
faker-d2bc3091e84ba03db44a6e76e938ecf307214a57.zip
Merge pull request #366 from joonhocho/master
[api] Add `faker.random.arrayElements`
Diffstat (limited to 'test/random.unit.js')
-rw-r--r--test/random.unit.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/random.unit.js b/test/random.unit.js
index d04bf280..e10d36be 100644
--- a/test/random.unit.js
+++ b/test/random.unit.js
@@ -97,6 +97,46 @@ describe("random.js", function () {
});
});
+ describe('arrayElements', function() {
+ it('returns a subset with random elements in the array', function() {
+ var testArray = ['hello', 'to', 'you', 'my', 'friend'];
+ var subset = faker.random.arrayElements(testArray);
+
+ // Check length
+ assert.ok(subset.length >= 1 && subset.length <= testArray.length);
+
+ // Check elements
+ subset.forEach(function(element) {
+ assert.ok(testArray.indexOf(element) > -1);
+ });
+
+ // Check uniqueness
+ subset.forEach(function(element) {
+ assert.ok(!this.hasOwnProperty(element));
+ this[element] = true;
+ }, {});
+ });
+
+ it('returns a subset of fixed length with random elements in the array', function() {
+ var testArray = ['hello', 'to', 'you', 'my', 'friend'];
+ var subset = faker.random.arrayElements(testArray, 3);
+
+ // Check length
+ assert.ok(subset.length === 3);
+
+ // Check elements
+ subset.forEach(function(element) {
+ assert.ok(testArray.indexOf(element) > -1);
+ });
+
+ // Check uniqueness
+ subset.forEach(function(element) {
+ assert.ok(!this.hasOwnProperty(element));
+ this[element] = true;
+ }, {});
+ });
+ });
+
describe('UUID', function() {
it('should generate a valid UUID', function() {
var UUID = faker.random.uuid();