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