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