name:
src/test/js/formulas/logic/NOTTest.ts
-rw-r--r--
2475
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 { NOT } from "../../../../main/js/formulas/logic/NOT";
9import { Grid } from "../../../../main/js/models/common/Grid";
10import {
11 CollateralLookupFunction,
12 LookupFunction,
13 Primitive,
14} from "../../../../main/js/models/common/Types";
15import { CommonModels } from "../../testutils/CommonModels";
16
17describe("NOT", function () {
18 it("should work with numbers", function () {
19 assert.equal(NOT.SELF.run(null, 10), false);
20 assert.equal(NOT.SELF.run(null, 0), true);
21 });
22
23 it("should work with strings", function () {
24 assert.equal(NOT.SELF.run(null, "TRUE"), false);
25 assert.equal(NOT.SELF.run(null, "fAlsE"), true);
26 });
27
28 it("should work with booleans", function () {
29 assert.equal(NOT.SELF.run(null, true), false);
30 assert.equal(NOT.SELF.run(null, false), true);
31 });
32
33 it("should work with null/blank/empty", function () {
34 assert.equal(NOT.SELF.run(null, null), true);
35 });
36
37 it("should do pass-through errors", function () {
38 assert.equal(
39 (NOT.SELF.run(null, new ValueException()) as F7Exception).name,
40 F7ExceptionName.VALUE
41 );
42 });
43
44 it("should use lookup", function () {
45 const lookup = stub();
46 const collateralLookup = stub();
47 const F = new NOT(lookup as LookupFunction, collateralLookup as CollateralLookupFunction);
48 collateralLookup.withArgs(CommonModels.A1, CommonModels.M22_RANGE).returns(true);
49 assert.deepEqual(F.run(CommonModels.A1, CommonModels.M22_RANGE), false);
50 assert.isTrue(collateralLookup.calledWith(CommonModels.A1, CommonModels.M22_RANGE));
51 assert.equal(collateralLookup.callCount, 1);
52 assert.isTrue(lookup.notCalled);
53 });
54
55 it("should handle grids", function () {
56 const one = Grid.from<Primitive>([[44], [true]]);
57 assert.deepEqual(NOT.SELF.run(null, one), false);
58 });
59
60 it("should return error when argument lengths are wrong", function () {
61 assert.deepEqual((NOT.SELF.run(null) as NAException).name, F7ExceptionName.NA);
62 assert.deepEqual((NOT.SELF.run(null, 10, 10, 10) as NAException).name, F7ExceptionName.NA);
63 });
64});