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