name:
src/test/js/formulas/math/ATANHTest.ts
-rw-r--r--
2712
1import { assert } from "chai";
2import { it, describe } from "../../testutils/TestUtils";
3import { stub } from "sinon";
4import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
5import { NAException } from "../../../../main/js/errors/NAException";
6import { ValueException } from "../../../../main/js/errors/ValueException";
7import { ATANH } from "../../../../main/js/formulas/math/ATANH";
8import { Grid } from "../../../../main/js/models/common/Grid";
9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("ATANH", function () {
13 it("should work with valid numbers", function () {
14 assert.deepEqual(ATANH.SELF.run(null, 0.99), 2.6466524123622457);
15 assert.deepEqual(ATANH.SELF.run(null, 0.489733), 0.5357090350574656);
16 assert.deepEqual(ATANH.SELF.run(null, 0.0), 0.0);
17 assert.deepEqual(ATANH.SELF.run(null, -0.66152156111), -0.7955143351612654);
18 assert.deepEqual(ATANH.SELF.run(null, -0.88), -1.3757676565209744);
19 });
20
21 it("should return NUM error when param is out of bounds", function () {
22 assert.deepEqual((ATANH.SELF.run(null, 1) as NAException).name, F7ExceptionName.NUM);
23 assert.deepEqual((ATANH.SELF.run(null, -1) as NAException).name, F7ExceptionName.NUM);
24 assert.deepEqual((ATANH.SELF.run(null, 44) as NAException).name, F7ExceptionName.NUM);
25 });
26
27 it("should work with strings", function () {
28 assert.equal(ATANH.SELF.run(null, "0.99"), 2.6466524123622457);
29 });
30
31 it("should do pass-through errors", function () {
32 assert.deepEqual(ATANH.SELF.run(null, new ValueException()), new ValueException());
33 });
34
35 it("should use lookup", function () {
36 const lookup = stub();
37 const collateralLookup = stub();
38 const F = new ATANH(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
39 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(0.99);
40 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), 2.6466524123622457);
41 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
42 assert.equal(collateralLookup.callCount, 1);
43 assert.isTrue(lookup.notCalled);
44 });
45
46 it("should handle grids", function () {
47 const one = Grid.builder().add(0, 0, 0.99).add(0, 1, "A").build();
48 assert.deepEqual(ATANH.SELF.run(null, one), 2.6466524123622457);
49 });
50
51 it("should return error when argument lengths are wrong", function () {
52 assert.deepEqual((ATANH.SELF.run(null) as NAException).name, F7ExceptionName.NA);
53 assert.deepEqual((ATANH.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
54 });
55});