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/ACOTTest.ts
-rw-r--r--
2612
 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 { ACOT } from "../../../../main/js/formulas/math/ACOT";
 8import { Grid } from "../../../../main/js/models/common/Grid";
 9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("ACOT", function () {
13  it("should work with numbers", function () {
14    assert.deepEqual(ACOT.SELF.run(null, 10), 0.09966865249116204);
15    assert.deepEqual(ACOT.SELF.run(null, 128731.2), 7.768124588133144e-6);
16    assert.deepEqual(ACOT.SELF.run(null, 11.11), 0.08976710276137885);
17    assert.deepEqual(ACOT.SELF.run(null, 0), 1.570796327);
18    assert.deepEqual(ACOT.SELF.run(null, 88281), 1.1327465705613094e-5);
19    assert.deepEqual(ACOT.SELF.run(null, 2), 0.4636476090008061);
20    assert.deepEqual(ACOT.SELF.run(null, 4), 0.24497866312686414);
21    assert.deepEqual(ACOT.SELF.run(null, -4), -0.24497866312686414);
22    assert.deepEqual(ACOT.SELF.run(null, -10124), -9.877518735162196e-5);
23  });
24
25  it("should work with strings", function () {
26    assert.equal(ACOT.SELF.run(null, "10"), 0.09966865249116204);
27  });
28
29  it("should do pass-through errors", function () {
30    assert.deepEqual(ACOT.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 ACOT(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), 0.09966865249116204);
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(ACOT.SELF.run(null, one), 0.09966865249116204);
47  });
48
49  it("should return error when argument lengths are wrong", function () {
50    assert.deepEqual((ACOT.SELF.run(null) as NAException).name, F7ExceptionName.NA);
51    assert.deepEqual((ACOT.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
52  });
53});