// test sign var assert = require('assert'), approx = require('../../../tools/approx'), math = require('../../../index')(); describe('sign', function() { it('should calculate the sign of a boolean', function () { assert.equal(math.sign(true), 1); assert.equal(math.sign(false), 0); }); it('should calculate the sign of a number as 1, -1 or 0', function() { assert.equal(math.sign(3), 1); assert.equal(math.sign(-3), -1); assert.equal(math.sign(0), 0); }); it('should calculate the sign of a complex value', function() { approx.deepEqual(math.sign(math.complex(2,-3)), math.complex(0.554700196225229, -0.832050294337844)); }); it('should throw an error when used with a unit', function() { assert.throws(function () { math.sign(math.unit('5cm')); }); }); it('should throw an error when used with a string', function() { assert.throws(function () { math.sign("hello world"); }); }); it('should return a matrix of the signs of each elements in the given array', function() { assert.deepEqual(math.sign([-2,-1,0,1,2]), [-1,-1,0,1,1]); }); it('should return a matrix of the signs of each elements in the given matrix', function() { assert.deepEqual(math.sign(math.matrix([-2,-1,0,1,2])), math.matrix([-1,-1,0,1,1])); }); });