aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoon Ho Cho <[email protected]>2016-04-08 18:45:51 -0700
committerJoon Ho Cho <[email protected]>2016-04-08 18:45:51 -0700
commitfb8653c95016d393ccbbe6441f9952ed333d8e2d (patch)
treef129b98b764784a4eeae4a01e827b8e6ac38f420 /test
parent649843ade73b730911506b8ecc6bf64bad10238c (diff)
downloadfaker-fb8653c95016d393ccbbe6441f9952ed333d8e2d.tar.xz
faker-fb8653c95016d393ccbbe6441f9952ed333d8e2d.zip
add faker.random.arrayElements
Diffstat (limited to 'test')
-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 94a7167d..786cdc9b 100644
--- a/test/random.unit.js
+++ b/test/random.unit.js
@@ -89,6 +89,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();