UNPKG

1.31 kBJavaScriptView Raw
1/*!
2 * is-number <https://github.com/jonschlinkert/is-number>
3 *
4 * Copyright (c) 2014 Jon Schlinkert, contributors.
5 * Licensed under the MIT License
6 */
7
8'use strict';
9
10var assert = require('assert');
11var isNumber = require('./');
12
13
14var pass = [0, '0', '012', '012', 1, '1', 1.1, '1.1', -1.1, '-1.1', 10, '10', 10.10, '10.10', 100, '100', Math.abs(1), Math.acos(1), Math.asin(1), Math.atan(1), Math.atan2(1, 2), Math.ceil(1), Math.cos(1), Math.E, Math.exp(1), Math.floor(1), Math.LN10, Math.LN2, Math.log(1), Math.LOG10E, Math.LOG2E, Math.max(1, 2), Math.min(1, 2), Math.PI, Math.pow(1, 2), Math.pow(5, 5), Math.random(1), Math.round(1), Math.sin(1), Math.sqrt(1), Math.SQRT1_2, Math.SQRT2, Math.tan(1), Number.MAX_VALUE, Number.MIN_VALUE, 5e3, '5e3', 0xff, '0xff', Infinity, 'Infinity'];
15
16var fail = ['3abc', 'abc', 'abc3', [1, 2, 3], function () {}, new Buffer('abc'), null, 'null', 'undefined', undefined, {abc: 'abc'}, {} ];
17
18
19describe('is a number', function () {
20 pass.forEach(function (num) {
21 it('"' + num + '" should be a number', function () {
22 assert.equal(isNumber(num), true);
23 });
24 });
25});
26
27describe('is not a number', function () {
28 fail.forEach(function (num) {
29 it('"' + num + '" should not be a number', function () {
30 assert.equal(isNumber(num), false);
31 });
32 });
33});
\No newline at end of file