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