spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
added more formula tests.
author
Ben Vogt <[email protected]>
date
2017-01-07 21:56:13
stats
1 file(s) changed, 225 insertions(+), 9 deletions(-)
files
tests/SheetFormulaTest.ts
  1diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
  2index ec4cbab..bb3ddb1 100644
  3--- a/tests/SheetFormulaTest.ts
  4+++ b/tests/SheetFormulaTest.ts
  5@@ -9,15 +9,15 @@ function testFormula(formula: string, expectation: any) {
  6   assertEquals(expectation, cell.getValue());
  7 }
  8 
  9-function testFormulaWithDependencies(formula: string, expectation: any, pairs: Array<Array<string>>) {
 10+function testFormulaToArray(formula: string, expectation: any) {
 11   var sheet  = new Sheet();
 12-  for (var pair of pairs) {
 13-    sheet.setCell(pair[0], pair[1]);
 14-  }
 15   sheet.setCell("A1", formula);
 16   var cell = sheet.getCell("A1");
 17   assertEquals(null, cell.getError());
 18-  assertEquals(expectation, cell.getValue());
 19+  var values = cell.getValue();
 20+  for (var index in values) {
 21+    assertEquals(values[index], expectation[index]);
 22+  }
 23 }
 24 
 25 // Test ABS formula
 26@@ -68,23 +68,84 @@ testFormula("=AVERAGE(10, 20, 4.1)", 11.366666666666667);
 27 testFormula("=AVERAGEA(10, 20, 4.1)", 11.366666666666667);
 28 
 29 // Test AVERAGEIF
 30-testFormulaWithDependencies("=AVERAGEIF(B1:B3, '>2')", 7.5, [["B1", "1"], ["B2", "5"], ["B3", "10"]]);
 31+testFormula("=AVERAGEIF([1, 5, 10], '>2')", 7.5);
 32+
 33+// Test BASE
 34+testFormula('=BASE(15, 2, 10)', '0000001111');
 35 
 36 // Test BIN2DEC
 37 testFormula("=BIN2DEC(1010101010)", -342);
 38 
 39+// Test BESSELI
 40+testFormula('=BESSELI(1, 2)', 0.13574766658069928);
 41+
 42+// Test BESSELJ
 43+testFormula('=BESSELJ(1, 2)', 0.11490348499246938);
 44+
 45+// Test BESSELK
 46+testFormula('=BESSELK(1, 2)', 1.6248388844172295);
 47+
 48+// Test BESSELY
 49+testFormula('=BESSELY(1, 2)', -1.6506826133039476);
 50+
 51+// Test BETADIST
 52+testFormula('=BETADIST(2, 8, 10, true, 1, 3)', 0.6854705810117458);
 53+
 54+// Test BETAINV
 55+testFormula('=BETAINV(0.6854705810117458, 8, 10, 1, 3)', 1.9999999999999996);
 56+
 57+// Test BINOMDISTRANGE
 58+// TODO: This should work.
 59+// testFormula('=BINOMDISTRANGE(60, 0.75, 45, 50)', 0.52363);
 60+
 61+// Test BINOMINV
 62+// TODO: This should work.
 63+// testFormula('=BINOMINV(6, 0.5, 0.75)', 4);
 64+
 65+// Test BITAND
 66+testFormula('=BITAND(42, 24)', 8);
 67+
 68+// Test BITLSHIFT
 69+testFormula('=BITLSHIFT(42, 24)', 704643072);
 70+
 71+// Test BITOR
 72+testFormula('=BITOR(42, 24)', 58);
 73+
 74+// Test BITRSHIFT
 75+testFormula('=BITRSHIFT(42, 2)', 10);
 76+
 77+// Test BITXOR
 78+testFormula('=BITXOR(42, 24)', 50);
 79+
 80 // Test BIN2HEX
 81 testFormula("=BIN2HEX(1010101010)", "fffffffeaa");
 82 
 83 // Test BIN2OCT
 84 testFormula("=BIN2OCT(1010101010)", "7777777252");
 85 
 86+// Test DECIMAL
 87+testFormula('=DECIMAL(199.99999)', 199);
 88+
 89 // Test BINOMDIST
 90 // TODO: This. FormulaJS implementation differs from GS.
 91 
 92 // Test CEIL
 93 testFormula("=CEILING(22.22, 0.1)", 22.3);
 94 
 95+// Test CEILINGMATH
 96+testFormula('=CEILINGMATH(1001.112131)', 1002);
 97+
 98+// Test CEILINGPRECISE
 99+testFormula('=CEILINGPRECISE(1001.112131)', 1002);
100+
101+// Test CHISQDIST
102+// TODO: This should work.
103+// testFormula('=CHISQDIST(0.5, 1, true)', 55);
104+
105+// Test CHISQINV
106+// TODO: This should work.
107+// testFormula('=CHISQINV(0.5, 1, true)', 44);
108+
109 // Test CHAR
110 testFormula("=CHAR(97)", "a");
111 
112@@ -94,14 +155,28 @@ testFormula("=CODE('a')", 97);
113 // Test COMBIN
114 testFormula("=COMBIN(4, 2)", 6);
115 
116+// Test COMBINA
117+testFormula('=COMBINA(4, 3)', 20);
118+
119+// Test COMPLEX
120+testFormula('=COMPLEX(3, 4)', '3+4i');
121+
122 // Test CONCATENATE
123 testFormula('=CONCATENATE("hey", " ", "there")', "hey there");
124 
125+// Test CONFIDENCENORM
126+// TODO: This should work.
127+// testFormula('=CONFIDENCE(0.05, 1.6, 250)', 0.1983344105);
128+
129+// Test CONFIDENCET
130+// TODO: This should work.
131+// testFormula('=CONFIDENCET(0.05, 1, 50)', 0.2842);
132+
133 // Test CONVERT
134 testFormula('=CONVERT(5.1, "mm", "m")', 0.0050999999999999995);
135 
136 // Test CORREL
137-testFormulaWithDependencies('=CORREL(B1:B2,B3:B4)', 1, [["B1", "9"], ["B2", "5"], ["B3", "10"], ["B4", "4"]]);
138+testFormula('=CORREL([9, 5],[10, 4])', 1);
139 
140 // Test COS
141 testFormula("=COS(PI())", -1);
142@@ -109,8 +184,14 @@ testFormula("=COS(PI())", -1);
143 // Test COSH
144 testFormula("=COSH(PI())", 11.591953275521522);
145 
146+// Test COT
147+testFormula('=COT(30)', -0.15611995216165922);
148+
149+// Test COTH
150+testFormula('=COTH(2)', 1.0373147207275482);
151+
152 // Test COUNT
153-testFormulaWithDependencies('=COUNT(B1:B3)', 3, [["B1", "1"], ["B2", "5"], ["B3", "10"]]);
154+testFormula('=COUNT([1, 5, 10])', 3);
155 
156 // Test COUNTA
157 testFormula("=COUNTA(10, 10, 22)", 3);
158@@ -119,13 +200,28 @@ testFormula("=COUNTA(10, 10, 22)", 3);
159 // TODO: Fix COUNTBLANK. Does not work properly.
160 
161 // Test COUNTIF
162-testFormulaWithDependencies('=COUNTIF(B1:B3, ">4")', 2, [["B1", "1"], ["B2", "5"], ["B3", "10"]]);
163+testFormula('=COUNTIF([1, 5, 10], ">4")', 2);
164 
165 // Test COUNTIFS
166-testFormulaWithDependencies('=COUNTIFS(B1:B3, ">4", C1:C3, ">4")', 2, [["B1", "1"], ["B2", "5"], ["B3", "10"], ["C1", "1"], ["C2", "5"], ["C3", "10"]]);
167+testFormula('=COUNTIFS([1, 5, 10], ">4", [1, 5, 10], ">4")', 2);
168+
169+// Test COUNTIN
170+testFormula('=COUNTIN([1,3,1],1)', 2);
171 
172 // Test COUNTUNIQUE
173-testFormulaWithDependencies('=COUNTUNIQUE(B1:B3)', 2, [["B1", "1"], ["B2", "1"], ["B3", "10"]]);
174+testFormula('=COUNTUNIQUE([1, 1, 10])', 2);
175+
176+// Test COVARIANCEP
177+testFormula('=COVARIANCEP([3,2,4,5,6], [9,7,12,15,17])', 5.2);
178+
179+// Test COVARIANCES
180+testFormula('=COVARIANCES([2,4,8], [5,11,12])', 9.666666666666668);
181+
182+// Test CSC
183+testFormula('=CSC(15)', 1.5377805615408537);
184+
185+// Test CSCH
186+testFormula('=CSCH(1.5)', 0.46964244059522464);
187 
188 // Test CUMIPMT
189 testFormula("=CUMIPMT(0.12, 12, 100, 1, 5, 0)", -54.39423242396348);
190@@ -229,3 +325,114 @@ testFormula('=FISHERINV(0.962)', 0.7451676440945232);
191 
192 // Test IF
193 testFormula('=IF("m" = "m", "hit", "miss")', 'hit');
194+
195+// Test INT
196+testFormula('=INT(99.33)', 99);
197+
198+// Test ISEVEN
199+testFormula('=ISEVEN(4)', true);
200+
201+// Test ISODD
202+testFormula('=ISODD(3)', true);
203+
204+// Test LN
205+testFormula('=LN(100)', 4.605170185988092);
206+
207+// Test LOG
208+testFormula('=LOG(256, 2)', 8);
209+
210+// Test LOG10
211+testFormula('=LOG10(100)', 2);
212+
213+// Test MAX
214+testFormula('=MAX(100, 22)', 100);
215+
216+// Test MAXA
217+testFormula('=MAXA(100, 22, 44)', 100);
218+
219+// Test MEDIAN
220+testFormula('=MEDIAN(100, 22, 54)', 54);
221+
222+// Test MIN
223+testFormula('=MIN(100, 22, 44)', 22);
224+
225+// Test MINA
226+testFormula('=MINA(100, 22, 44)', 22);
227+
228+// Test MOD
229+testFormula('=MOD(10, 3)', 1);
230+
231+// Test NOT
232+testFormula('=NOT(TRUE())', false);
233+
234+// Test ODD
235+testFormula('=ODD(2)', 3);
236+
237+// Test OR
238+testFormula('=OR("m" = "p", "n" = "n")', true);
239+
240+// Test PI()
241+testFormula('=PI()', 3.141592653589793);
242+
243+// Test POWER
244+testFormula('=POWER(4, 10)', 1048576);
245+
246+// Test ROUND
247+testFormula('=ROUND(99.44, 1)', 99.4);
248+
249+// Test ROUNDDOWN
250+testFormula('=ROUNDDOWN(99.46, 1)', 99.4);
251+
252+// Test ROUNDUP
253+testFormula('=ROUNDUP(99.46, 1)', 99.5);
254+
255+// Test SIN
256+// TODO: This shuld work.
257+// testFormula('=SIN(PI())', 0);
258+
259+// Test SINH
260+testFormula('=SINH(PI())', 11.548739357257752);
261+
262+// Test SPLIT
263+testFormulaToArray('=SPLIT("1,2,3", ",", TRUE)', [ '1', '2', '3' ]);
264+
265+// Test SQRT
266+testFormula('=SQRT(9)', 3);
267+
268+// Test SQRTPI
269+testFormula('=SQRTPI(9)', 5.317361552716548);
270+
271+// Test SUM
272+testFormula('=SUM(10, 10)', 20);
273+
274+// Test SUMIF
275+testFormula('=SUMIF([1, 5, 10], ">2")', 15);
276+
277+// Test SUMPRODUCT
278+testFormula('=SUMPRODUCT([1, 5, 10])', 16);
279+
280+// Test SUMSQ
281+testFormula('=SUMSQ([1, 5, 10], 10)', 226);
282+
283+// Test SUMX2MY2
284+testFormula('=SUMX2MY2([1, 5, 10], [1, 5, 10])', 0);
285+
286+// Test SUMX2PY2
287+// TODO: This should work.
288+// testFormulaWithDependencies('=SUMX2PY2(B1:B3, C1:C3)', 0, [["B1", "1"], ["B2", "5"], ["B3", "10"], ["C1", "1"], ["C2", "5"], ["C3", "10"]]);
289+
290+// Test TAN
291+// TODO: This should work.
292+// testFormula('=TAN(PI())', 0);
293+
294+// Test TANH
295+testFormula('=TANH(PI())', 0.99627207622075);
296+
297+// Test TRUE
298+testFormula('=TRUE()', true);
299+
300+// Test TRUE
301+testFormula('=TRUNC(3.1415, 2)', 3.14);
302+
303+// Test XOR
304+testFormula('=XOR(1, 1)', false);