1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var assert = require('assert');
|
11 | var isNumber = require('./');
|
12 |
|
13 |
|
14 | var shouldPass = [ 0,
|
15 | 5e3,
|
16 | -1.1,
|
17 | 0,
|
18 |
|
19 |
|
20 | parseInt('012'),
|
21 | parseFloat('012'),
|
22 | 0xff,
|
23 | 1,
|
24 | 1.1,
|
25 | 10,
|
26 | 10.10,
|
27 | 100,
|
28 |
|
29 | Math.abs(1),
|
30 | Math.acos(1),
|
31 | Math.asin(1),
|
32 | Math.atan(1),
|
33 | Math.atan2(1, 2),
|
34 | Math.ceil(1),
|
35 | Math.cos(1),
|
36 | Math.E,
|
37 | Math.exp(1),
|
38 | Math.floor(1),
|
39 | Math.LN10,
|
40 | Math.LN2,
|
41 | Math.log(1),
|
42 | Math.LOG10E,
|
43 | Math.LOG2E,
|
44 | Math.max(1, 2),
|
45 | Math.min(1, 2),
|
46 | Math.PI,
|
47 | Math.pow(1, 2),
|
48 | Math.pow(5, 5),
|
49 | Math.random(1),
|
50 | Math.round(1),
|
51 | Math.sin(1),
|
52 | Math.sqrt(1),
|
53 | Math.SQRT1_2,
|
54 | Math.SQRT2,
|
55 | Math.tan(1),
|
56 |
|
57 | Number.MAX_VALUE,
|
58 | Number.MIN_VALUE,
|
59 |
|
60 |
|
61 | '-1.1',
|
62 | '0',
|
63 | '012',
|
64 | '0xff',
|
65 | '1',
|
66 | '1.1',
|
67 | '10',
|
68 | '10.10',
|
69 | '100',
|
70 | '5e3'
|
71 | ];
|
72 |
|
73 | var shouldFail = [
|
74 | '3abc',
|
75 | 'abc',
|
76 | 'abc3',
|
77 | 'null',
|
78 | 'undefined',
|
79 | [1, 2, 3],
|
80 | function () {},
|
81 | new Buffer('abc'),
|
82 | null,
|
83 | undefined,
|
84 | {abc: 'abc'},
|
85 | {},
|
86 | []
|
87 | ];
|
88 |
|
89 |
|
90 | describe('is a number', function () {
|
91 | shouldPass.forEach(function (num) {
|
92 | it('"' + num + '" should be a number', function () {
|
93 | assert.equal(isNumber(num), true);
|
94 | });
|
95 | });
|
96 |
|
97 | assert.equal(isNumber(Infinity), true);
|
98 | assert.equal(isNumber('Infinity'), true);
|
99 | });
|
100 |
|
101 |
|
102 | describe('is a finite number:', function () {
|
103 | function isNum(val) {
|
104 | return isNumber(val) && isFinite(val);
|
105 | }
|
106 |
|
107 | assert.equal(isNum(Infinity), false);
|
108 | assert.equal(isNum('Infinity'), false);
|
109 |
|
110 | shouldPass.forEach(function (num) {
|
111 | it('"' + num + '" should be a number', function () {
|
112 | assert.equal(isNum(num), true);
|
113 | });
|
114 | });
|
115 |
|
116 | shouldFail.forEach(function (num) {
|
117 | it('"' + num + '" should be a number', function () {
|
118 | assert.equal(isNum(num), false);
|
119 | });
|
120 | });
|
121 | });
|
122 |
|
123 |
|
124 | describe('is not a number', function () {
|
125 | shouldFail.forEach(function (num) {
|
126 | it('"' + num + '" should not be a number', function () {
|
127 | assert.equal(isNumber(num), false);
|
128 | });
|
129 | });
|
130 | }); |
\ | No newline at end of file |