name:
src/test/js/formulas/math/ATANTest.ts
-rw-r--r--
2594
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 { ATAN } from "../../../../main/js/formulas/math/ATAN";
8import { Grid } from "../../../../main/js/models/common/Grid";
9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("ATAN", function () {
13 it("should work with valid numbers", function () {
14 assert.deepEqual(ATAN.SELF.run(null, 10.0), Math.atan(10.0));
15 assert.deepEqual(ATAN.SELF.run(null, 128731.2), Math.atan(128731.2));
16 assert.deepEqual(ATAN.SELF.run(null, 11.11), Math.atan(11.11));
17 assert.deepEqual(ATAN.SELF.run(null, 0.0), Math.atan(0.0));
18 assert.deepEqual(ATAN.SELF.run(null, 88281.0), Math.atan(88281));
19 assert.deepEqual(ATAN.SELF.run(null, 2.0), Math.atan(2.0));
20 assert.deepEqual(ATAN.SELF.run(null, 4.0), Math.atan(4.0));
21 assert.deepEqual(ATAN.SELF.run(null, -4.0), Math.atan(-4.0));
22 assert.deepEqual(ATAN.SELF.run(null, -10124.0), Math.atan(-10124.0));
23 });
24
25 it("should work with strings", function () {
26 assert.equal(ATAN.SELF.run(null, "1"), Math.atan(1));
27 });
28
29 it("should do pass-through errors", function () {
30 assert.deepEqual(ATAN.SELF.run(null, new ValueException()), new ValueException());
31 });
32
33 it("should use lookup", function () {
34 const lookup = stub();
35 const collateralLookup = stub();
36 const F = new ATAN(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
37 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(0.99);
38 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), Math.atan(0.99));
39 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
40 assert.equal(collateralLookup.callCount, 1);
41 assert.isTrue(lookup.notCalled);
42 });
43
44 it("should handle grids", function () {
45 const one = Grid.builder().add(0, 0, 0.99).add(0, 1, "A").build();
46 assert.deepEqual(ATAN.SELF.run(null, one), Math.atan(0.99));
47 });
48
49 it("should return error when argument lengths are wrong", function () {
50 assert.deepEqual((ATAN.SELF.run(null) as NAException).name, F7ExceptionName.NA);
51 assert.deepEqual((ATAN.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
52 });
53});