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/SQRTPITest.ts
-rw-r--r--
2655
 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 { SQRTPI } from "../../../../main/js/formulas/math/SQRTPI";
 8import { Grid } from "../../../../main/js/models/common/Grid";
 9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("SQRTPI", function () {
13  it("should work with valid numbers", function () {
14    assert.deepEqual(SQRTPI.SELF.run(null, 10), 5.604991216397929);
15    assert.deepEqual(SQRTPI.SELF.run(null, 128731.2), 635.9410288759473);
16    assert.deepEqual(SQRTPI.SELF.run(null, 11.11), 5.907884086657642);
17    assert.deepEqual(SQRTPI.SELF.run(null, 0), 0);
18    assert.deepEqual(SQRTPI.SELF.run(null, 88281), 526.6335927868261);
19    assert.deepEqual(SQRTPI.SELF.run(null, 2), 2.5066282746310002);
20    assert.deepEqual(SQRTPI.SELF.run(null, 4), 3.5449077018110318);
21  });
22
23  it("should return error when the parameter is less than 0", function () {
24    assert.deepEqual((SQRTPI.SELF.run(null, -10) as NAException).name, F7ExceptionName.NUM);
25  });
26
27  it("should work with strings", function () {
28    assert.equal(SQRTPI.SELF.run(null, "4"), 3.5449077018110318);
29  });
30
31  it("should do pass-through errors", function () {
32    assert.deepEqual(SQRTPI.SELF.run(null, new ValueException()), new ValueException());
33  });
34
35  it("should use lookup", function () {
36    const lookup = stub();
37    const collateralLookup = stub();
38    const F = new SQRTPI(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
39    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(4);
40    assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), 3.5449077018110318);
41    assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
42    assert.equal(collateralLookup.callCount, 1);
43    assert.isTrue(lookup.notCalled);
44  });
45
46  it("should handle grids", function () {
47    const one = Grid.builder().add(0, 0, 4).add(0, 1, "A").build();
48    assert.deepEqual(SQRTPI.SELF.run(null, one), 3.5449077018110318);
49  });
50
51  it("should return error when argument lengths are wrong", function () {
52    assert.deepEqual((SQRTPI.SELF.run(null) as NAException).name, F7ExceptionName.NA);
53    assert.deepEqual((SQRTPI.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
54  });
55});