name:
src/test/js/formulas/engineering/BIN2DECTest.ts
-rw-r--r--
1818
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 { BIN2DEC } from "../../../../main/js/formulas/engineering/BIN2DEC";
7import { Grid } from "../../../../main/js/models/common/Grid";
8import { CollateralLookupFunction, LookupFunction } from "../../../../main/js/models/common/Types";
9import { CommonModels } from "../../testutils/CommonModels";
10
11describe("BIN2DEC", function () {
12 it("should return correct value", function () {
13 assert.deepEqual(BIN2DEC.SELF.run(null, "1010101010"), -342);
14 assert.deepEqual(BIN2DEC.SELF.run(null, "10"), 2);
15 });
16
17 it("should use lookup", function () {
18 const lookup = stub();
19 const collateralLookup = stub();
20 const F = new BIN2DEC(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
21 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns("1010101010");
22 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), -342);
23 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
24 assert.equal(collateralLookup.callCount, 1);
25 assert.isTrue(lookup.notCalled);
26 });
27
28 it("should handle grids", function () {
29 assert.deepEqual(
30 BIN2DEC.SELF.run(null, Grid.builder().add(0, 0, "1010101010").add(0, 1, 10).build()),
31 -342
32 );
33 });
34
35 it("should return error when argument lengths are wrong", function () {
36 assert.deepEqual((BIN2DEC.SELF.run(null) as NAException).name, F7ExceptionName.NA);
37 assert.deepEqual(
38 (BIN2DEC.SELF.run(null, "Too many", "Too many") as NAException).name,
39 F7ExceptionName.NA
40 );
41 });
42});