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