Skip to content

Commit

Permalink
adding randomNumber and randomize back to helpers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Jan 8, 2013
1 parent 3f0a514 commit c3f19c6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
var Faker = require('../index');

// backword-compatibility
exports.randomNumber = function (range) {
return Faker.random.number(range);
};

// backword-compatibility
exports.randomize = function (array) {
return Faker.random.array_element(array);
};

// parses string for a symbol and replace it with a random number from 1-10
exports.replaceSymbolWithNumber = function (string, symbol) {
// default symbol is '#'
Expand Down
18 changes: 18 additions & 0 deletions test/helpers.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,22 @@ describe("helpers.js", function() {
assert.ok(typeof card === 'object');
});
});

// Make sure we keep this function for backward-compatibility.
describe("randomNumber()", function() {
it("returns an integer", function() {
var num = Faker.Helpers.randomNumber();
assert.ok(typeof num === 'number');
});
});

// Make sure we keep this function for backward-compatibility.
describe("randomize()", function() {
it("returns a random element from an array", function() {
var arr = ['a', 'b', 'c'];
var elem = Faker.Helpers.randomize(arr);
assert.ok(elem);
assert.ok(arr.indexOf(elem) !== -1);
});
});
});

0 comments on commit c3f19c6

Please sign in to comment.