spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Tests,ParserConstants] chipset change caused fpp errors, renaming constants
author
Ben Vogt <[email protected]>
date
2018-02-10 00:09:14
stats
6 file(s) changed, 48 insertions(+), 44 deletions(-)
files
src/Parser/ParserConstants.ts
tests/Formulas/FinancialTest.ts
tests/Formulas/MathTest.ts
tests/Formulas/RangeTest.ts
tests/Formulas/StatisticalTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/src/Parser/ParserConstants.ts b/src/Parser/ParserConstants.ts
  2index 4eebf66..f196451 100644
  3--- a/src/Parser/ParserConstants.ts
  4+++ b/src/Parser/ParserConstants.ts
  5@@ -351,6 +351,9 @@ symbolIndexToName[Symbol.EXCLAMATION_POINT] = "!";
  6 const SYMBOL_INDEX_TO_NAME = symbolIndexToName;
  7 
  8 
  9+/**
 10+ * State represents the state of the parser. Enums should be in the format {prev}_{next}.
 11+ */
 12 const enum State {
 13   // Start
 14   Start = 0,
 15@@ -412,10 +415,14 @@ const enum State {
 16   PrefixUnaryPlus_Expression = 34,
 17   Function_LeftParen = 35,
 18   Number_Ampersand_Expression = 43,
 19-  CLOSE_PAREN_ON_EXPRESSION = 57,
 20+  Expression_RightParen = 57,
 21+  Function_RightParenNoArguments = 58,
 22   Function_LeftParen_Expression = 60,
 23+  LeftParen_Array = 61,
 24   GTETwoExpressions = 69,
 25-  CLOSE_PAREN_ON_FUNCTION = 70
 26+  CLOSE_PAREN_ON_FUNCTION = 70,
 27+  Variable_FullError = 38,
 28+  Error_Variable = 37
 29 }
 30 
 31 
 32@@ -590,7 +597,7 @@ table[State.Error] = ObjectBuilder
 33   .add(Symbol.CARROT, [REDUCE, ReduceActions.ERROR_AND_CONTINUE])
 34   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.ERROR_AND_CONTINUE])
 35   .add(Symbol.COMMA, [REDUCE, ReduceActions.ERROR_AND_CONTINUE])
 36-  .add(Symbol.VARIABLE, [SHIFT, 37])
 37+  .add(Symbol.VARIABLE, [SHIFT, State.Error_Variable])
 38   .add(Symbol.FULL_ERROR, [SHIFT, 18])
 39   .build();
 40 table[State.Variable] = ObjectBuilder
 41@@ -608,7 +615,7 @@ table[State.Variable] = ObjectBuilder
 42   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY])
 43   .add(Symbol.COMMA, [REDUCE, ReduceActions.WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY])
 44   .add(Symbol.DECIMAL, [REDUCE, ReduceActions.WRAP_CURRENT_INDEX_TOKEN_AS_ARRAY])
 45-  .add(Symbol.FULL_ERROR, [SHIFT, 38])
 46+  .add(Symbol.FULL_ERROR, [SHIFT, State.Variable_FullError])
 47   .build();
 48 table[State.NumberUpper] = ObjectBuilder
 49   .add(Symbol.EOF, [REDUCE, ReduceActions.REFLEXIVE_REDUCE])
 50@@ -866,7 +873,7 @@ table[State.LeftParen_Expression] = ObjectBuilder
 51   .add(Symbol.AMPERSAND, [SHIFT, State.Number_Ampersand])
 52   .add(Symbol.EQUALS, [SHIFT, State.Start_Equals])
 53   .add(Symbol.PLUS, [SHIFT, State.Number_Plus])
 54-  .add(Symbol.RIGHT_PAREN, [SHIFT, State.CLOSE_PAREN_ON_EXPRESSION])
 55+  .add(Symbol.RIGHT_PAREN, [SHIFT, State.Expression_RightParen])
 56   .add(Symbol.LESS_THAN, [SHIFT, State.LessThan])
 57   .add(Symbol.GREATER_THAN, [SHIFT, State.GreaterThan])
 58   .add(Symbol.MINUS, [SHIFT, State.Number_Minus])
 59@@ -912,14 +919,14 @@ table[State.Function_LeftParen] = ObjectBuilder
 60   .add(Symbol.STRING, [SHIFT, State.Start_String])
 61   .add(Symbol.PLUS, [SHIFT, State.PrefixUnaryPlus])
 62   .add(Symbol.LEFT_PAREN, [SHIFT, State.LeftParen])
 63-  .add(Symbol.RIGHT_PAREN, [SHIFT, 58])
 64+  .add(Symbol.RIGHT_PAREN, [SHIFT, State.Function_RightParenNoArguments])
 65   .add(Symbol.MINUS, [SHIFT, State.PrefixUnaryMinus])
 66   .add(Symbol.FUNCTION, [SHIFT, State.Function])
 67   .add(Symbol.EXP_SEQ, 59)
 68   .add(Symbol.CELL, State.Cell)
 69   .add(Symbol.FIXEDCELL, [SHIFT, State.FixedCell])
 70   .add(Symbol.CELL_UPPER, [SHIFT, State.CellUpper])
 71-  .add(Symbol.ARRAY, [SHIFT, 61])
 72+  .add(Symbol.ARRAY, [SHIFT, State.LeftParen_Array])
 73   .add(Symbol.VARIABLE, [SHIFT, State.Variable])
 74   .add(Symbol.NUMBER_UPPER, [SHIFT, State.NumberUpper])
 75   .add(Symbol.FULL_ERROR, [SHIFT, State.Pound])
 76@@ -939,10 +946,10 @@ table[State.Error_Error] = ObjectBuilder
 77   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.ERROR_AND_CONTINUE_WITH_OTHER_ERRORS])
 78   .add(Symbol.COMMA, [REDUCE, ReduceActions.ERROR_AND_CONTINUE_WITH_OTHER_ERRORS])
 79   .build();
 80-table[37] = ObjectBuilder
 81+table[State.Error_Variable] = ObjectBuilder
 82   .add(Symbol.FULL_ERROR, [REDUCE, ReduceActions.AS_ERROR])
 83   .build();
 84-table[38] = ObjectBuilder
 85+table[State.Variable_FullError] = ObjectBuilder
 86   .add(Symbol.VARIABLE, [SHIFT, 62])
 87   .build();
 88 table[39] = ObjectBuilder
 89@@ -1169,7 +1176,7 @@ table[State.VariableSeq_Decimal_Variable] = ObjectBuilder
 90   .add(Symbol.COMMA, [REDUCE, ReduceActions.ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH])
 91   .add(Symbol.DECIMAL, [REDUCE, ReduceActions.ENSURE_LAST_TWO_IN_ARRAY_AND_PUSH])
 92   .build();
 93-table[State.CLOSE_PAREN_ON_EXPRESSION] = ObjectBuilder
 94+table[State.Expression_RightParen] = ObjectBuilder
 95   .add(Symbol.EOF, [REDUCE, ReduceActions.LAST_NUMBER])
 96   .add(Symbol.AMPERSAND, [REDUCE, ReduceActions.LAST_NUMBER])
 97   .add(Symbol.EQUALS, [REDUCE, ReduceActions.LAST_NUMBER])
 98@@ -1184,7 +1191,7 @@ table[State.CLOSE_PAREN_ON_EXPRESSION] = ObjectBuilder
 99   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.LAST_NUMBER])
100   .add(Symbol.COMMA, [REDUCE, ReduceActions.LAST_NUMBER])
101   .build();
102-table[58] = ObjectBuilder
103+table[State.Function_RightParenNoArguments] = ObjectBuilder
104   .add(Symbol.EOF, [REDUCE, ReduceActions.CALL_FUNCTION_LAST_BLANK])
105   .add(Symbol.AMPERSAND, [REDUCE, ReduceActions.CALL_FUNCTION_LAST_BLANK])
106   .add(Symbol.EQUALS, [REDUCE, ReduceActions.CALL_FUNCTION_LAST_BLANK])
107@@ -1218,7 +1225,7 @@ table[State.Function_LeftParen_Expression] = ObjectBuilder
108   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.ENSURE_IS_ARRAY])
109   .add(Symbol.COMMA, [REDUCE, ReduceActions.ENSURE_IS_ARRAY])
110   .build();
111-table[61] = ObjectBuilder
112+table[State.LeftParen_Array] = ObjectBuilder
113   .add(Symbol.RIGHT_PAREN, [REDUCE, ReduceActions.ENSURE_YYTEXT_ARRAY])
114   .add(Symbol.SEMI_COLON, [REDUCE, ReduceActions.ENSURE_YYTEXT_ARRAY])
115   .add(Symbol.COMMA, [REDUCE, ReduceActions.ENSURE_YYTEXT_ARRAY])
116diff --git a/tests/Formulas/FinancialTest.ts b/tests/Formulas/FinancialTest.ts
117index 10cede9..58c0b5a 100644
118--- a/tests/Formulas/FinancialTest.ts
119+++ b/tests/Formulas/FinancialTest.ts
120@@ -346,8 +346,8 @@ test("NPV", function() {
121 
122 
123 test("NPER", function() {
124-  assertEquals(NPER(0.04, 100, 4000, 0, 0), -24.362418941571317);
125-  assertEquals(NPER(0.04, 100, 4000), -24.362418941571317);
126+  assertEquals(NPER(0.04, 100, 4000, 0, 0), -24.362418941571313);
127+  assertEquals(NPER(0.04, 100, 4000), -24.362418941571313);
128   assertEquals(NPER(0.02, 100, 4000, 0, 0), -29.68225660720854);
129   assertEquals(NPER(0.01, 100, 4000, 0, 0), -33.815180780052486);
130   assertEquals(NPER(0.04, -50, 1000, 20, 0), 41.44012515117696);
131diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
132index ce89520..e08f7b9 100644
133--- a/tests/Formulas/MathTest.ts
134+++ b/tests/Formulas/MathTest.ts
135@@ -348,9 +348,9 @@ test("ATAN2", function(){
136 
137 test("ATANH", function(){
138   assertEquals(ATANH(0.51), 0.5627297693521489);
139-  assertEquals(ATANH(0.44), 0.47223080442042564);
140+  assertEquals(ATANH(0.44), 0.4722308044204257);
141   assertEquals(ATANH(0), 0);
142-  assertEquals(ATANH("0.1"), 0.10033534773107562);
143+  assertEquals(ATANH("0.1"), 0.10033534773107558);
144   assertEquals(ATANH(false), 0);
145   catchAndAssertEquals(function() {
146     ATANH(true);
147@@ -434,7 +434,7 @@ test("COS", function(){
148 
149 
150 test("COSH", function(){
151-  assertEquals(COSH(PI()), 11.591953275521522);
152+  assertEquals(COSH(PI()), 11.591953275521519);
153   assertEquals(COSH(1), 1.5430806348152437);
154   assertEquals(COSH(false), 1);
155   assertEquals(COSH(0), 1);
156diff --git a/tests/Formulas/RangeTest.ts b/tests/Formulas/RangeTest.ts
157index e0efeca..8e9e0af 100644
158--- a/tests/Formulas/RangeTest.ts
159+++ b/tests/Formulas/RangeTest.ts
160@@ -34,12 +34,12 @@ test("GROWTH", function(){
161     [15.53, 19.99, 20.43, 21.18, 25.93, 30.00, 30.00, 34.01, 36.47],
162     [1, 2, 3, 4, 5, 6, 7, 8, 9],
163     [10, 11, 12]
164-  ), [41.740521723275876, 46.22712349335047, 51.19598074591973]);
165+  ), [41.74052172327583, 46.22712349335043, 51.19598074591968]);
166   assertArrayEquals(GROWTH(
167     [15.53, 19.99, 20.43, 21.18, 25.93, [30.00, 30.00, 34.01], 36.47],
168     [1, 2, 3, 4, 5, 6, 7, 8, 9],
169     [10, 11, 12]
170-  ), [41.740521723275876, 46.22712349335047, 51.19598074591973]);
171+  ), [41.74052172327583, 46.22712349335043, 51.19598074591968]);
172   catchAndAssertEquals(function() {
173     GROWTH(
174       [15.53, 19.99, 20.43, 21.18, "25.93", 30.00, 30.00, 34.01, 36.47],
175diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
176index 3a53e19..991ef0a 100644
177--- a/tests/Formulas/StatisticalTest.ts
178+++ b/tests/Formulas/StatisticalTest.ts
179@@ -286,7 +286,7 @@ test("EXPONDIST", function(){
180 
181 test("FINV", function(){
182   assertEquals(FINV(0.42, 2, 3), 1.174597274485816);
183-  assertEquals(FINV(0.42, 2, 5), 1.0370426242728021);
184+  assertEquals(FINV(0.42, 2, 5), 1.037042624272801);
185   assertEquals(FINV(0.42, 33, 5), 1.303222112500911);
186   assertEquals(FINV(["0.42"], [33, []], [5]), 1.303222112500911);
187   assertEquals(FINV("0.42", 2, 3), 1.174597274485816);
188@@ -337,7 +337,7 @@ test("FISHERINV", function(){
189   assertEquals(FISHERINV("0.962"), 0.7451676440945232);
190   assertEquals(FISHERINV(0), 0);
191   assertEquals(FISHERINV(false), 0);
192-  assertEquals(FISHERINV(true), 0.761594155955765);
193+  assertEquals(FISHERINV(true), 0.7615941559557649);
194   assertEquals(FISHERINV(0.92), 0.7258974148490807);
195   catchAndAssertEquals(function() {
196     FISHER("str");
197@@ -728,11 +728,11 @@ test("FORCAST", function() {
198 
199 
200 test("POISSON", function() {
201-  assertEquals(POISSON(3, 500, true), 1.4932281660406229e-210);
202-  assertEquals(POISSON(30, 500, true), 2.660801877634559e-169);
203-  assertEquals(POISSON(3, 5, true), 0.26502591529736175);
204-  assertEquals(POISSON(3, 5, false), 0.14037389581428059);
205-  assertEquals(POISSON(3, 5), 0.14037389581428059);
206+  assertEquals(POISSON(3, 500, true), 1.4932281660406588e-210);
207+  assertEquals(POISSON(30, 500, true), 2.660801877634623e-169);
208+  assertEquals(POISSON(3, 5, true), 0.2650259152973617);
209+  assertEquals(POISSON(3, 5, false), 0.14037389581428056);
210+  assertEquals(POISSON(3, 5), 0.14037389581428056);
211   catchAndAssertEquals(function() {
212     POISSON(-3, 5);
213   }, ERRORS.NUM_ERROR);
214@@ -781,7 +781,7 @@ test("PERCENTRANK$EXC", function() {
215 
216 test("NORMSINV", function() {
217   assertEquals(NORMSINV(0.1), -1.2815515655446006);
218-  assertEquals(NORMSINV(0.4), -0.2533471031357999);
219+  assertEquals(NORMSINV(0.4), -0.25334710313580006);
220   catchAndAssertEquals(function() {
221     NORMSINV(0);
222   }, ERRORS.NUM_ERROR);
223@@ -813,8 +813,8 @@ test("NORMDIST", function() {
224   assertEquals(NORMDIST(1, 0, 6, true), 0.5661838326109037);
225   assertEquals(NORMDIST(1, 0, 6, false), 0.06557328601698999);
226   assertEquals(NORMDIST(0.5, 0.44, 8, true), 0.5029920390526184);
227-  assertEquals(NORMDIST(0.5, 0.44, 8, false), 0.04986638253844748);
228-  assertEquals(NORMDIST(-0.5, 0.44, 8, true), 0.45323192202214374);
229+  assertEquals(NORMDIST(0.5, 0.44, 8, false), 0.049866382538447475);
230+  assertEquals(NORMDIST(-0.5, 0.44, 8, true), 0.4532319220221437);
231   assertEquals(NORMDIST(-0.5, -100, 100, true), 0.840131867824506);
232   catchAndAssertEquals(function() {
233     NORMDIST(-0.5, 0.44, 0, true);
234@@ -829,9 +829,9 @@ test("NORMDIST", function() {
235 
236 
237 test("NORMINV", function() {
238-  assertEquals(NORMINV(0.8, 0, 6), 5.049727401437487);
239+  assertEquals(NORMINV(0.8, 0, 6), 5.0497274014374876);
240   assertEquals(NORMINV(0.2, 0, 6), -5.049727401437487);
241-  assertEquals(NORMINV(0.4, 1, 6), -0.5200826188147996);
242+  assertEquals(NORMINV(0.4, 1, 6), -0.5200826188148002);
243   catchAndAssertEquals(function() {
244     NORMINV(-0.5, 0.44, 1);
245   }, ERRORS.NUM_ERROR);
246@@ -897,7 +897,7 @@ test("HARMEAN", function() {
247 test("CONFIDENCE", function() {
248   assertEquals(CONFIDENCE(0.04, 6.48, 25), 2.6616585881788426);
249   assertEquals(CONFIDENCE(0.0001, 101.1, 24281), 2.5242568756291566);
250-  assertEquals(CONFIDENCE(0.8, 101.1, 24281), 0.1643742612132182);
251+  assertEquals(CONFIDENCE(0.8, 101.1, 24281), 0.1643742612132184);
252   catchAndAssertEquals(function() {
253     CONFIDENCE(0, 101.1, 24281);
254   }, ERRORS.NUM_ERROR);
255@@ -951,7 +951,7 @@ test("COVAR", function() {
256 });
257 
258 test("WEIBULL", function() {
259-  assertEquals(WEIBULL(2.4, 2, 4, true), 0.30232367392896886);
260+  assertEquals(WEIBULL(2.4, 2, 4, true), 0.302323673928969);
261   assertEquals(WEIBULL(3.1, 4, 4, true), 0.3028470073265427);
262   assertEquals(WEIBULL(0.16, 1, 4, false), 0.2401973597880808);
263   catchAndAssertEquals(function() {
264diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
265index 1e9878a..ebb210d 100644
266--- a/tests/SheetFormulaTest.ts
267+++ b/tests/SheetFormulaTest.ts
268@@ -142,8 +142,9 @@ test("Sheet TRIM", function(){
269   assertFormulaEquals("=TRIM(' trim ')", "trim");
270 });
271 
272+// I have strong suspicions that these are subject to minuscule rounding-errors and can change on different chips.
273 test("Sheet COSH", function(){
274-  assertFormulaEquals("=COSH(PI())", 11.591953275521522);
275+  assertFormulaEquals("=COSH(PI())", 11.591953275521519);
276 });
277 
278 test("Sheet COT", function(){
279@@ -716,7 +717,7 @@ test("Sheet SLN", function(){
280 });
281 
282 test("Sheet NPER", function(){
283-  assertFormulaEquals('=NPER(0.04, 100, 4000, 0, 0)', -24.362418941571317);
284+  assertFormulaEquals('=NPER(0.04, 100, 4000, 0, 0)', -24.362418941571313);
285 });
286 
287 test("Sheet NOMINAL", function(){
288@@ -753,8 +754,8 @@ test("Sheet LINEST", function(){
289 });
290 
291 test("Sheet POISSON, POISSON.DIST", function(){
292-  assertFormulaEquals('=POISSON(3, 5, true)', 0.26502591529736175);
293-  assertFormulaEquals('=POISSON.DIST(3, 5, true)', 0.26502591529736175);
294+  assertFormulaEquals('=POISSON(3, 5, true)', 0.2650259152973617);
295+  assertFormulaEquals('=POISSON.DIST(3, 5, true)', 0.2650259152973617);
296 });
297 
298 test("Sheet PERCENTRANK, PERCENTRANK.INC", function(){
299@@ -775,7 +776,7 @@ test("Sheet NORMSINV", function(){
300 });
301 
302 test("Sheet NORMINV", function(){
303-  assertFormulaEquals('=NORMINV(0.8, 0, 6)', 5.049727401437487);
304+  assertFormulaEquals('=NORMINV(0.8, 0, 6)', 5.0497274014374876);
305 });
306 
307 test("Sheet NEGBINOMDIST", function(){
308@@ -899,7 +900,7 @@ test("Sheet PPMT", function(){
309 });
310 
311 test("Sheet WEIBULL", function(){
312-  assertFormulaEquals('=WEIBULL(2.4, 2, 4, true)', 0.30232367392896886);
313+  assertFormulaEquals('=WEIBULL(2.4, 2, 4, true)', 0.302323673928969);
314 });
315 
316 test("Sheet VARPA", function(){