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/SIGNTest.ts
-rw-r--r--
2284
 1import { assert } from "chai";
 2import { describe, it } 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 { SIGN } from "../../../../main/js/formulas/math/SIGN";
 8import { Grid } from "../../../../main/js/models/common/Grid";
 9import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
10import { CommonModels } from "../../testutils/CommonModels";
11
12describe("SIGN", function () {
13  it("should do normal operations", function () {
14    assert.equal(SIGN.SELF.run(null, 10), 1);
15    assert.equal(SIGN.SELF.run(null, -10), -1);
16    assert.equal(SIGN.SELF.run(null, 0), 0);
17    assert.equal(SIGN.SELF.run(null, -0), 0);
18    assert.equal(SIGN.SELF.run(null, -218637221.22), -1);
19    assert.equal(SIGN.SELF.run(null, true), 1);
20    assert.equal(SIGN.SELF.run(null, false), 0);
21  });
22
23  it("should do string conversion", function () {
24    assert.equal(SIGN.SELF.run(null, "10"), 1);
25  });
26
27  it("should do pass-through errors", function () {
28    assert.deepEqual(SIGN.SELF.run(null, new ValueException()), new ValueException());
29  });
30
31  it("should use lookup", function () {
32    const lookup = stub();
33    const collateralLookup = stub();
34    const F = new SIGN(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
35    collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(6);
36    assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), 1);
37    assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
38    assert.equal(collateralLookup.callCount, 1);
39    assert.isTrue(lookup.notCalled);
40  });
41
42  it("should handle grids", function () {
43    const one = Grid.builder().add(0, 0, -111).add(0, 1, "A").build();
44    assert.deepEqual(SIGN.SELF.run(null, one), -1);
45  });
46
47  it("should return error when argument lengths are wrong", function () {
48    assert.deepEqual((SIGN.SELF.run(null) as NAException).name, F7ExceptionName.NA);
49    assert.deepEqual((SIGN.SELF.run(null, "A", "B") as NAException).name, F7ExceptionName.NA);
50  });
51});