forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathisNumeric.test.js
More file actions
34 lines (27 loc) · 1.26 KB
/
Copy pathisNumeric.test.js
File metadata and controls
34 lines (27 loc) · 1.26 KB
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
var assert = require('assert');
var math = require('../../../index');
var isNumeric = math.isNumeric;
var bignumber = math.bignumber;
var fraction = math.fraction;
describe('isNumeric', function() {
it('should test whether a value is numeric', function() {
assert.strictEqual(isNumeric(2), true);
assert.strictEqual(isNumeric(true), true);
assert.strictEqual(isNumeric(bignumber(2.3)), true);
assert.strictEqual(isNumeric(fraction(1,3)), true);
assert.strictEqual(isNumeric('2'), false);
assert.strictEqual(isNumeric('foo'), false);
assert.strictEqual(isNumeric(math.complex(2,3)), false);
assert.strictEqual(isNumeric(math.unit('5 cm')), false);
});
it('should test isNumeric element wise on an Array', function() {
assert.deepEqual(isNumeric([2, 'foo', true]), [true, false, true]);
});
it('should test isNumeric element wise on a Matrix', function() {
assert.deepEqual(isNumeric(math.matrix([2, 'foo', true])), math.matrix([true, false, true]));
});
it('should throw an error in case of unsupported data types', function() {
assert.throws(function () {isNumeric(new Date())}, /TypeError: Unexpected type of argument/);
assert.throws(function () {isNumeric({})}, /TypeError: Unexpected type of argument/);
});
});