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/execution/ExecutorMultiplicationTest.ts
-rw-r--r--
3688
 1import { DivException } from "../../../main/js/errors/DivException";
 2import { NAException } from "../../../main/js/errors/NAException";
 3import { NameException } from "../../../main/js/errors/NameException";
 4import { NullException } from "../../../main/js/errors/NullException";
 5import { NumException } from "../../../main/js/errors/NumException";
 6import { ParseException } from "../../../main/js/errors/ParseException";
 7import { RefException } from "../../../main/js/errors/RefException";
 8import { ValueException } from "../../../main/js/errors/ValueException";
 9import { runner, it, describe } from "../testutils/TestUtils";
10
11describe("Executor.execute - Multiplication", function () {
12  it("should work with numbers", function () {
13    runner().addCell("Alpha", "A1", "= 10 * 4").addExpectedValue("Alpha", "A1", 40.0).run();
14    runner().addCell("Alpha", "A1", "= 0 * 0").addExpectedValue("Alpha", "A1", 0.0).run();
15    runner().addCell("Alpha", "A1", "= 10 * -10").addExpectedValue("Alpha", "A1", -100.0).run();
16    runner().addCell("Alpha", "A1", "= -10 * -4").addExpectedValue("Alpha", "A1", 40.0).run();
17    runner().addCell("Alpha", "A1", "= 1e10 * 1.1").addExpectedValue("Alpha", "A1", 1.1e10).run();
18  });
19
20  it("should work with booleans", function () {
21    runner().addCell("Alpha", "A1", "= 9 * TRUE").addExpectedValue("Alpha", "A1", 9.0).run();
22    runner().addCell("Alpha", "A1", "= 9 * FALSE").addExpectedValue("Alpha", "A1", 0.0).run();
23    runner().addCell("Alpha", "A1", "= 9 * -TRUE").addExpectedValue("Alpha", "A1", -9.0).run();
24    runner().addCell("Alpha", "A1", "= 9 * -FALSE").addExpectedValue("Alpha", "A1", 0.0).run();
25  });
26
27  it("should work with strings", function () {
28    runner().addCell("Alpha", "A1", '= 9 * "10"').addExpectedValue("Alpha", "A1", 90.0).run();
29    runner().addCell("Alpha", "A1", '= 9 * "1e10"').addExpectedValue("Alpha", "A1", 9e10).run();
30    runner().addCell("Alpha", "A1", '= 9 * "0"').addExpectedValue("Alpha", "A1", 0.0).run();
31  });
32
33  it("should not work with strings that are not numbers", function () {
34    runner()
35      .addCell("Alpha", "A1", '= 9 * "No good."')
36      .addExpectedValue("Alpha", "A1", new ValueException())
37      .run();
38  });
39
40  it("should work with blank values", function () {
41    runner().addCell("Alpha", "A1", "= 2 * M44").addExpectedValue("Alpha", "A1", 0.0).run();
42  });
43
44  it("should work with array literals", function () {
45    runner().addCell("Alpha", "A1", "= 3 * {2}").addExpectedValue("Alpha", "A1", 6.0).run();
46    runner().addCell("Alpha", "A1", "= 3 * {2, 44}").addExpectedValue("Alpha", "A1", 6.0).run();
47    runner()
48      .addCell("Alpha", "A1", '= 3 * -{2, "Ignore me."}')
49      .addExpectedValue("Alpha", "A1", -6.0)
50      .run();
51  });
52
53  it("should return errors as they are encountered", function () {
54    runner()
55      .addCell("Alpha", "A1", "= 3 * #NULL!")
56      .addCell("Alpha", "A2", "= 3 * #DIV/0!")
57      .addCell("Alpha", "A3", "= 3 * #VALUE!")
58      .addCell("Alpha", "A4", "= 3 * #REF!")
59      .addCell("Alpha", "A5", "= 3 * #NAME?")
60      .addCell("Alpha", "A6", "= 3 * #NUM!")
61      .addCell("Alpha", "A7", "= 3 * #N/A")
62      .addCell("Alpha", "A8", "= 3 * #ERROR!")
63      .addExpectedValue("Alpha", "A1", new NullException())
64      .addExpectedValue("Alpha", "A2", new DivException())
65      .addExpectedValue("Alpha", "A3", new ValueException())
66      .addExpectedValue("Alpha", "A4", new RefException())
67      .addExpectedValue("Alpha", "A5", new NameException())
68      .addExpectedValue("Alpha", "A6", new NumException())
69      .addExpectedValue("Alpha", "A7", new NAException())
70      .addExpectedValue("Alpha", "A8", new ParseException())
71      .run();
72  });
73});