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