f7
f7 is a spreadsheet formula execution library
git clone https://git.vogt.world/f7.git
Log | Files | README.md | LICENSE.md
← All files
name: src/test/js/formulas/math/ACOSTest.ts
-rw-r--r--
2230
 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 { ACOS } from "../../../../main/js/formulas/math/ACOS";
 8import { Grid } from "../../../../main/js/models/common/Grid";
 9import {
10  CollateralLookupFunction,
11  LookupFunction,
12  Primitive,
13} from "../../../../main/js/models/common/Types";
14import { CommonModels } from "../../testutils/CommonModels";
15
16describe("ACOS", function () {
17  it("should work with numbers", function () {
18    assert.equal(ACOS.SELF.run(null, 0), Math.acos(0));
19    assert.equal(ACOS.SELF.run(null, 0.99), Math.acos(0.99));
20    assert.equal(ACOS.SELF.run(null, 0.55), Math.acos(0.55));
21    assert.equal(ACOS.SELF.run(null, -0.55), Math.acos(-0.55));
22  });
23
24  it("should work with strings", function () {
25    assert.equal(ACOS.SELF.run(null, "0.99"), Math.acos(0.99));
26  });
27
28  it("should do pass-through errors", function () {
29    assert.deepEqual(ACOS.SELF.run(null, new ValueException()), new ValueException());
30  });
31
32  it("should use lookup", function () {
33    const lookup = stub();
34    const collateralLookup = stub();
35    const F = new ACOS(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
36    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(0.99);
37    assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), Math.acos(0.99));
38    assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
39    assert.equal(collateralLookup.callCount, 1);
40    assert.isTrue(lookup.notCalled);
41  });
42
43  it("should handle grids", function () {
44    const one = Grid.from<Primitive>([[0.99], ["A"]]);
45    assert.deepEqual(ACOS.SELF.run(null, one), Math.acos(0.99));
46  });
47
48  it("should return error when argument lengths are wrong", function () {
49    assert.deepEqual((ACOS.SELF.run(null) as NAException).name, F7ExceptionName.NA);
50    assert.deepEqual((ACOS.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
51  });
52});