-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (57 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var expect = require('chai').expect;
var MAX_SAFE_INT = require('max-safe-int');
var MIN_SAFE_INT = -MAX_SAFE_INT;
describe('random-float', function () {
var randomFloat = require('../../');
it('common', function () {
expect(randomFloat()).to.be.a('number');
expect(randomFloat()).to.be.within(MIN_SAFE_INT, MAX_SAFE_INT);
expect(randomFloat()).to.be.match(/(-?\d+.[\d]{1,4})?$/);
expect(randomFloat({
max: 2
})).be.be.within(MIN_SAFE_INT, 2);
expect(randomFloat({
min: -1,
max: 1,
fixed: 0
})).be.be.oneOf([0, 1, -1]);
expect(randomFloat({
min: -1,
max: 1,
fixed: 2
})).be.be.match(/(-1)|([01])(.[\d]{1,2})?$/);
expect(randomFloat({
min: 0,
max: 'abc',
fixed: 2
})).be.be.match(/([012].[\d]{1,2})?$/);
expect(randomFloat({
min: 'abc',
fixed: 2
})).be.be.match(/(-?\d+.[\d]{1,2})?$/);
expect(randomFloat({
min: 2,
max: 1,
fixed: 2
})).be.be.match(/([12].[\d]{1,2})?$/);
expect(randomFloat({
min: 1,
max: 1,
})).be.be.equal(1);
expect(randomFloat({
min: -1,
max: -1,
inspected: true
})).be.be.equal(-1);
expect(randomFloat({
min: '-1',
max: 1,
fixed: 2
})).be.be.match(/(-1)|([01])(.[\d]{1,2})?$/);
expect(randomFloat({
min: -1,
max: '1',
fixed: 2
})).be.be.match(/(-1)|([01])(.[\d]{1,2})?$/);
});
});