spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Sheet] Adding parsing formula tests for simple operators
author
Ben Vogt <[email protected]>
date
2017-05-11 02:07:34
stats
2 file(s) changed, 17 insertions(+), 2 deletions(-)
files
src/Sheet.ts
tests/SheetFormulaTest.ts
 1diff --git a/src/Sheet.ts b/src/Sheet.ts
 2index 3194839..f83020c 100644
 3--- a/src/Sheet.ts
 4+++ b/src/Sheet.ts
 5@@ -417,6 +417,9 @@ var Sheet = (function () {
 6           if (number2 === 0) {
 7             throw new DivZeroError("Evaluation caused divide by zero error.");
 8           }
 9+          if (number2 !== 0 && number1 === 0) {
10+            result = 0;
11+          }
12           result = number1 / number2;
13           if (result == Infinity) {
14             throw new DivZeroError("Evaluation caused divide by zero error.");
15diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
16index c955148..38f5f74 100644
17--- a/tests/SheetFormulaTest.ts
18+++ b/tests/SheetFormulaTest.ts
19@@ -431,7 +431,6 @@ test("Sheet XOR", function(){
20 test("Sheet *", function(){
21   assertFormulaEquals('= 10 * 10', 100);
22   assertFormulaEquals('= 10 * 0', 0);
23-  assertFormulaEquals('= 10 * 0', 0);
24   assertFormulaEquals('= 1 * 1', 1);
25 });
26 
27@@ -439,5 +438,17 @@ test("Sheet /", function(){
28   assertFormulaEquals('= 10 / 2', 5);
29   assertFormulaEquals('= 10 / 1', 10);
30   assertFormulaEquals('= 1 / 1', 1);
31+  assertFormulaEquals('= 0 / 1', 0);
32+  assertFormulaEquals('="1" / 1', 1);
33+  assertFormulaEquals('="500" / 1', 500);
34   assertFormulaEqualsError('= 10 / 0', DIV_ZERO_ERROR);
35+  assertFormulaEqualsError('= 0 / 0', DIV_ZERO_ERROR);
36+  assertFormulaEquals('= P9 / 1', 0);
37 });
38+
39+test("Sheet ^", function(){
40+  assertFormulaEquals('= 10 ^ 10', 10000000000);
41+  assertFormulaEquals('= 10 ^ 0', 1);
42+  assertFormulaEquals('= 1 ^ 1', 1);
43+  assertFormulaEquals('= 2 ^ 10', 1024);
44+});
45\ No newline at end of file