Permalink
Newer
100644
80 lines (72 sloc)
3.26 KB
1
var Code = require('code')
2
var Lab = require('lab')
3
4
var isPositiveInteger = require('../index.js')
9
var lab = exports.lab = Lab.script()
10
var describe = lab.describe
11
var it = lab.it
12
var expect = Code.expect
13
14
describe('is-positive-integer', function () {
15
it('should return true for positive integers', function (done) {
16
expect(isPositiveInteger(1)).to.equal(true)
17
expect(isPositiveInteger(10)).to.equal(true)
18
expect(isPositiveInteger(100)).to.equal(true)
19
expect(isPositiveInteger(1000)).to.equal(true)
20
expect(isPositiveInteger(90071992555)).to.equal(true)
21
expect(isPositiveInteger(999999999999)).to.equal(true)
22
expect(isPositiveInteger(MAX_SAFE_INTEGER)).to.equal(true)
23
expect(isPositiveInteger(Number.MAX_VALUE)).to.equal(true)
25
done()
26
})
27
28
it('should return false for negative integers or zero', function (done) {
29
expect(isPositiveInteger(0)).to.equal(false)
30
expect(isPositiveInteger(-1)).to.equal(false)
31
expect(isPositiveInteger(-10)).to.equal(false)
32
expect(isPositiveInteger(-100)).to.equal(false)
33
expect(isPositiveInteger(-1000)).to.equal(false)
34
expect(isPositiveInteger(new Number(0))).to.equal(false)
35
expect(isPositiveInteger(new Number(-12))).to.equal(false)
36
done()
37
})
38
39
it('should return false for floats', function (done) {
40
expect(isPositiveInteger(1.1)).to.equal(false)
41
expect(isPositiveInteger(10.1)).to.equal(false)
42
expect(isPositiveInteger(100.1)).to.equal(false)
43
expect(isPositiveInteger(1000.1)).to.equal(false)
44
expect(isPositiveInteger(-1.1)).to.equal(false)
45
expect(isPositiveInteger(-10.1)).to.equal(false)
46
expect(isPositiveInteger(-100.1)).to.equal(false)
47
expect(isPositiveInteger(-1000.1)).to.equal(false)
49
done()
50
})
51
52
it('should return false for others', function (done) {
53
expect(isPositiveInteger(Infinity)).to.equal(false)
54
expect(isPositiveInteger({})).to.equal(false)
55
expect(isPositiveInteger([])).to.equal(false)
56
expect(isPositiveInteger('10')).to.equal(false)
57
expect(isPositiveInteger('what')).to.equal(false)
58
expect(isPositiveInteger(/what/)).to.equal(false)
59
expect(isPositiveInteger(null)).to.equal(false)
60
expect(isPositiveInteger(undefined)).to.equal(false)
62
expect(isPositiveInteger({ valueOf: function () { return 42 } })).to.equal(false)
66
67
describe('isSafePositiveInteger', function() {
68
it('should return true for positive integers', function (done) {
69
expect(isSafePositiveInteger(1)).to.equal(true)
70
expect(isSafePositiveInteger(10)).to.equal(true)
71
expect(isSafePositiveInteger(100)).to.equal(true)
72
expect(isSafePositiveInteger(1000)).to.equal(true)
73
expect(isSafePositiveInteger(90071992555)).to.equal(true)
74
expect(isSafePositiveInteger(999999999999)).to.equal(true)
75
expect(isSafePositiveInteger(MAX_SAFE_INTEGER)).to.equal(true)
76
expect(isSafePositiveInteger(Number.MAX_VALUE)).to.equal(false)
77
done()
78
})
79
})