// test equal var assert = require('assert'), math = require('../../../index')(), bignumber = math.bignumber, complex = math.complex, matrix = math.matrix, unit = math.unit, equal = math.equal; describe('equal', function() { it('should compare two numbers correctly', function() { assert.equal(equal(2, 3), false); assert.equal(equal(2, 2), true); assert.equal(equal(0, 0), true); assert.equal(equal(-2, 2), false); }); it('should compare two booleans', function() { assert.equal(equal(true, true), true); assert.equal(equal(true, false), false); assert.equal(equal(false, true), false); assert.equal(equal(false, false), true); }); it('should compare mixed numbers and booleans', function() { assert.equal(equal(2, true), false); assert.equal(equal(1, true), true); assert.equal(equal(0, true), false); assert.equal(equal(true, 2), false); assert.equal(equal(true, 1), true); assert.equal(equal(false, 2), false); assert.equal(equal(false, 0), true); }); it('should compare bignumbers', function() { assert.equal(equal(bignumber(2), bignumber(3)), false); assert.equal(equal(bignumber(2), bignumber(2)), true); assert.equal(equal(bignumber(3), bignumber(2)), false); assert.equal(equal(bignumber(0), bignumber(0)), true); assert.equal(equal(bignumber(-2), bignumber(2)), false); }); it('should compare mixed numbers and bignumbers', function() { assert.deepEqual(equal(bignumber(2), 3), false); assert.deepEqual(equal(2, bignumber(2)), true); assert.equal(equal(1/3, bignumber(1).div(3)), true); assert.equal(equal(bignumber(1).div(3), 1/3), true); }); it('should compare mixed booleans and bignumbers', function() { assert.equal(equal(bignumber(0.1), true), false); assert.equal(equal(bignumber(1), true), true); assert.equal(equal(false, bignumber(0)), true); }); it('should compare two complex numbers correctly', function() { assert.equal(equal(complex(2,3), complex(2,4)), false); assert.equal(equal(complex(2,3), complex(2,3)), true); assert.equal(equal(complex(1,3), complex(2,3)), false); assert.equal(equal(complex(1,3), complex(2,4)), false); assert.equal(equal(complex(2,0), 2), true); assert.equal(equal(complex(2,1), 2), false); assert.equal(equal(2, complex(2, 0)), true); assert.equal(equal(2, complex(2, 1)), false); assert.equal(equal(complex(2,0), 3), false); }); it('should compare mixed complex numbers and bignumbers (downgrades to numbers)', function() { assert.deepEqual(equal(math.complex(6, 0), bignumber(6)), true); assert.deepEqual(equal(math.complex(6, -2), bignumber(6)), false); assert.deepEqual(equal(bignumber(6), math.complex(6, 0)), true); assert.deepEqual(equal(bignumber(6), math.complex(6, 4)), false); }); it('should compare two units correctly', function() { assert.equal(equal(unit('100cm'), unit('10inch')), false); assert.equal(equal(unit('100cm'), unit('1m')), true); //assert.equal(equal(unit('12inch'), unit('1foot')), true); // round-off error :( //assert.equal(equal(unit('2.54cm'), unit('1inch')), true); // round-off error :( }); it('should throw an error when comparing a unit with a big number', function() { assert.throws( function () {equal(math.unit('5 m'), bignumber(10)).toString() }); }); it('should throw an error when comparing a unit with a number', function() { assert.throws(function () {equal(unit('100cm'), 22)}); }); it('should compare two strings correctly', function() { assert.equal(equal('0', 0), true); assert.equal(equal('Hello', 'hello'), false); assert.equal(equal('hello', 'hello'), true); }); it('should compare two matrices correctly', function() { assert.deepEqual(equal([1,4,5], [3,4,5]), [false, true, true]); assert.deepEqual(equal([1,4,5], matrix([3,4,5])), matrix([false, true, true])); }); it('should throw an error if matrices have different sizes', function() { assert.throws(function () {equal([1,4,5], [3,4])}); }); it('should throw an error in case of invalid number of arguments', function() { assert.throws(function () {equal(1)}, math.error.ArgumentsError); assert.throws(function () {equal(1, 2, 3)}, math.error.ArgumentsError); }); });