name:
src/test/js/formulas/math/UPLUSTest.ts
-rw-r--r--
2178
1import { assert } from "chai";
2import { it, describe } from "../../testutils/TestUtils";
3import { stub } from "sinon";
4import { F7Exception } from "../../../../main/js/errors/F7Exception";
5import { F7ExceptionName } from "../../../../main/js/errors/F7ExceptionName";
6import { NAException } from "../../../../main/js/errors/NAException";
7import { ValueException } from "../../../../main/js/errors/ValueException";
8import { UPLUS } from "../../../../main/js/formulas/math/UPLUS";
9import { Grid } from "../../../../main/js/models/common/Grid";
10import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
11import { CommonModels } from "../../testutils/CommonModels";
12
13describe("UPLUS", function () {
14 it("should do normal operations", function () {
15 assert.deepEqual(UPLUS.SELF.run(null, 10), 10);
16 assert.deepEqual(UPLUS.SELF.run(null, 0), 0);
17 assert.deepEqual(UPLUS.SELF.run(null, 8278.28687), 8278.28687);
18 });
19
20 it("should do string conversion", function () {
21 assert.deepEqual(UPLUS.SELF.run(null, "10"), 10);
22 });
23
24 it("should do pass-through errors", function () {
25 assert.deepEqual(
26 (UPLUS.SELF.run(null, new ValueException()) as F7Exception).name,
27 F7ExceptionName.VALUE
28 );
29 });
30
31 it("should use lookup", function () {
32 const lookup = stub();
33 const collateralLookup = stub();
34 const F = new UPLUS(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
35 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns("2");
36 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), 2);
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, "2").add(0, 1, "A").build();
44 assert.deepEqual(UPLUS.SELF.run(null, one), 2);
45 });
46
47 it("should return error when argument lengths are wrong", function () {
48 assert.deepEqual(
49 (UPLUS.SELF.run(null, "A", "Too many") as NAException).name,
50 F7ExceptionName.NA
51 );
52 });
53});