Permalink
Browse files

adding range util method

  • Loading branch information...
1 parent 7bc08e2 commit beced59c9ec817136e5371629ded7f8b980d24c2 @aaronpowell committed Dec 2, 2011
Showing with 28 additions and 0 deletions.
  1. +7 −0 lib/tbd.js
  2. +21 −0 tests/util-range-spec.js
View
@@ -117,5 +117,12 @@
};
};
+ utils.range = function (min, max) {
+ return function () {
+ var random = Math.random();
+ return Math.floor(random * (max-min));
+ };
+ };
+
this.tbd.utils = utils;
}).call(this);
View
@@ -0,0 +1,21 @@
+describe('tbd-util-range', function() {
+ var tbd = require('../lib/');
+
+ it('should pick from a number within the supplied range', function () {
+ var data = tbd.from({})
+ .prop('foo').use(tbd.utils.range(0, 10))
+ .make(1);
+ expect(data.length).toBe(1);
+ expect(data[0].foo).toBeGreaterThan(-1);
+ expect(data[0].foo).toBeLessThan(11);
+ });
+
+ it('should allow negative ranges', function () {
+ var data = tbd.from({})
+ .prop('foo').use(tbd.utils.range(-1, -10))
+ .make(1);
+ expect(data.length).toBe(1);
+ expect(data[0].foo).toBeGreaterThan(-11);
+ expect(data[0].foo).toBeLessThan(0);
+ });
+});

0 comments on commit beced59

Please sign in to comment.