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