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