var assert = require('assert'), error = require('../../../lib/error/index'), math = require('../../../index'), approx = require('../../../tools/approx'), pi = math.pi, complex = math.complex, matrix = math.matrix, unit = math.unit, acsc = math.acsc, csc = math.csc, bigmath = math.create({number: 'bignumber', precision: 20}), Big = bigmath.bignumber; describe('acsc', function() { it('should return the arccsc of a boolean', function () { approx.equal(acsc(true), pi / 2); assert.ok(isNaN(acsc(false))); //assert.deepEqual(acsc(false), complex(0, Infinity)); }); it('should return the arccsc of null', function () { assert.ok(isNaN(acsc(null))); //assert.deepEqual(acsc(null), complex(0, Infinity)); }); it('should return the arccsc of a number', function() { approx.equal(acsc(-2) / pi, -1/6); approx.equal(acsc(-1) / pi, -0.5); assert.ok(isNaN(acsc(0))); //assert.deepEqual(acsc(0), complex(0, Infinity)); approx.equal(acsc(1) / pi, 0.5); approx.equal(acsc(2) / pi, 1/6); }); it('should return the arccsc of a bignumber', function() { var arg1 = Big(-2); var arg2 = Big(-1.71); var arg3 = Big(-1); assert.deepEqual(acsc(arg1), Big('-0.5235987755982988731')); assert.deepEqual(acsc(arg2), Big('-0.624627713324716013')); assert.deepEqual(acsc(arg3), Big('-1.5707963267948966192')); assert.deepEqual(acsc(Big(1)), Big('1.5707963267948966192')); assert.deepEqual(acsc(Big(1.71)), Big('0.624627713324716013')); assert.deepEqual(acsc(Big(2)), Big('0.5235987755982988731')); // Make sure args were not changed assert.deepEqual(arg1, Big(-2)); assert.deepEqual(arg2, Big(-1.71)); assert.deepEqual(arg3, Big(-1)); // Hit Newton's method case bigmath.config({precision: 61}); var arg4 = Big(1.00000001); assert.deepEqual(acsc(arg4).toString(), '1.570654905439248565373629613450057180739125884090554026623514'); assert.deepEqual(arg4, Big(1.00000001)); }); it('should be the inverse function of csc', function() { approx.equal(acsc(csc(-1)), -1); approx.equal(acsc(csc(0)), 0); approx.equal(acsc(csc(0.1)), 0.1); approx.equal(acsc(csc(0.5)), 0.5); approx.equal(acsc(csc(2)), 1.14159265358979); }); it('should be the inverse function of bignumber csc', function() { // More Newton's method test cases assert.deepEqual(acsc(bigmath.csc(Big(-2))).toString(), '-1.141592653589793238462643383279502884197169399375105820974945'); assert.deepEqual(acsc(bigmath.csc(Big(-0.5))).toString(), '-0.5'); assert.deepEqual(acsc(bigmath.csc(Big(-0.1))).toString(), '-0.1'); assert.deepEqual(acsc(bigmath.csc(Big(0.1))).toString(), '0.1'); assert.deepEqual(acsc(bigmath.csc(Big(0.5))).toString(), '0.5'); assert.deepEqual(acsc(bigmath.csc(Big(2))).toString(), '1.141592653589793238462643383279502884197169399375105820974945'); bigmath.config({precision: 20}); // Full decimal Taylor test cases /* csc(-1) = -0.8414709848078965067 acsc(-0.8414709848078965067) = -1.00000000000000000008 => (rounding up) -1.0000000000000000001 assert.deepEqual(acsc(bigmath.csc(Big(-1))), Big('-1')); */ assert.ok(acsc(bigmath.csc(Big(0))).isZero()); assert.deepEqual(acsc(bigmath.csc(Big(0.1))).toString(), '0.1'); assert.deepEqual(acsc(bigmath.csc(Big(0.5))).toString(), '0.5'); //assert.deepEqual(acsc(bigmath.csc(Big(2))).toString(), '1.1415926535897932385'); }); it('should throw an error if the bignumber result is complex', function() { assert.throws(function () { acsc(Big(0.5)); }, /acsc() only has non-complex values for |x| >= 1./); assert.throws(function () { acsc(Big(0)); }, /acsc() only has non-complex values for |x| >= 1./); assert.throws(function () { acsc(Big(-0.5)); }, /acsc() only has non-complex values for |x| >= 1./); }); it('should return the arccsc of a complex number', function() { var re = 0.150385604327861963; var im = 0.231334698573973315; approx.deepEqual(acsc(complex('2+3i')), complex(re, -im)); approx.deepEqual(acsc(complex('2-3i')), complex(re, im)); approx.deepEqual(acsc(complex('-2+3i')), complex(-re, -im)); approx.deepEqual(acsc(complex('-2-3i')), complex(-re, im)); approx.deepEqual(acsc(complex('1+i')), complex(0.4522784471511907,-0.53063753095251783)); approx.deepEqual(acsc(complex('i')), complex(0, -0.881373587019543)); approx.deepEqual(acsc(complex('-1')), complex(-pi / 2, 0)); approx.deepEqual(acsc(complex('-0.5')), complex(-pi / 2, 1.3169578969248)); assert.deepEqual(acsc(complex('0')), complex(pi / 2, Infinity)); approx.deepEqual(acsc(complex('0.5')), complex(pi / 2, -1.3169578969248)); approx.deepEqual(acsc(complex('1')), complex(pi / 2, 0)); }); it('should throw an error if called with a unit', function() { assert.throws(function () {acsc(unit('45deg'))}); assert.throws(function () {acsc(unit('5 celsius'))}); }); it('should throw an error if called with a string', function() { assert.throws(function () {acsc('string')}); }); it('should calculate the arccsc element-wise for arrays and matrices', function() { var acsc123 = [pi / 2, pi / 6, 0.339836909454]; approx.deepEqual(acsc([1,2,3]), acsc123); approx.deepEqual(acsc(matrix([1,2,3])), matrix(acsc123)); }); it('should throw an error in case of invalid number of arguments', function() { assert.throws(function () {acsc()}, error.ArgumentsError); assert.throws(function () {acsc(1, 2)}, error.ArgumentsError); }); });