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/SINHTest.ts
-rw-r--r--
2584
 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 { SINH } from "../../../../main/js/formulas/math/SINH";
 8import { Grid } from "../../../../main/js/models/common/Grid";
 9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("SINH", function () {
13  it("should work with valid numbers", function () {
14    assert.deepEqual(SINH.SELF.run(null, 10), Math["sinh"](10));
15    assert.deepEqual(SINH.SELF.run(null, 128731.2), Math["sinh"](128731.2));
16    assert.deepEqual(SINH.SELF.run(null, 11.11), Math["sinh"](11.11));
17    assert.deepEqual(SINH.SELF.run(null, 0), 0);
18    assert.deepEqual(SINH.SELF.run(null, 88281), Math["sinh"](88281));
19    assert.deepEqual(SINH.SELF.run(null, 2), Math["sinh"](2));
20    assert.deepEqual(SINH.SELF.run(null, 4), Math["sinh"](4));
21    assert.deepEqual(SINH.SELF.run(null, -4), Math["sinh"](-4));
22    assert.deepEqual(SINH.SELF.run(null, -10124), Math["sinh"](-10124));
23  });
24
25  it("should work with strings", function () {
26    assert.equal(SINH.SELF.run(null, "10"), Math["sinh"](10));
27  });
28
29  it("should do pass-through errors", function () {
30    assert.deepEqual(SINH.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 SINH(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
37    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(10);
38    assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), Math["sinh"](10));
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, 10).add(0, 1, "A").build();
46    assert.deepEqual(SINH.SELF.run(null, one), Math["sinh"](10));
47  });
48
49  it("should return error when argument lengths are wrong", function () {
50    assert.deepEqual((SINH.SELF.run(null) as NAException).name, F7ExceptionName.NA);
51    assert.deepEqual((SINH.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
52  });
53});