name:
tests/Formulas/StatisticalTest.ts
-rw-r--r--
42168
1import {
2 AVERAGE,
3 AVERAGEA,
4 AVERAGEIF,
5 AVEDEV,
6 CORREL,
7 COUNT,
8 COUNTA,
9 PEARSON,
10 MEDIAN,
11 DEVSQ,
12 EXPONDIST,
13 FDIST$LEFTTAILED,
14 FINV,
15 FISHER,
16 FISHERINV,
17 MAX,
18 MAXA,
19 MIN,
20 MINA,
21 QUARTILE,
22 PERCENTILE,
23 STDEV,
24 STDEVA,
25 STDEVP,
26 STDEVPA,
27 TRIMMEAN,
28 SLOPE,
29 STANDARDIZE,
30 SMALL,
31 LARGE,
32 KURT,
33 INTERCEPT,
34 FORECAST,
35 POISSON,
36 PERCENTRANK,
37 PERCENTRANK$EXC,
38 NORMSINV,
39 NORMSDIST,
40 NORMDIST,
41 NORMINV,
42 NEGBINOMDIST,
43 GEOMEAN,
44 HARMEAN,
45 CONFIDENCE,
46 BINOMDIST,
47 COVAR,
48 WEIBULL,
49 VARPA,
50 VARP,
51 VARA,
52 VAR,
53 PERMUT,
54 RSQ,
55 SKEW,
56 STEYX,
57 PROB,
58 MODE,
59 RANK,
60 RANK$AVG,
61 RANK$EQ,
62 LOGNORMDIST,
63 TDIST,
64 HYPGEOMDIST,
65 ZTEST
66} from "../../src/Formulas/Statistical";
67import * as ERRORS from "../../src/Errors";
68import {
69 assertEquals,
70 catchAndAssertEquals,
71 test
72} from "../Utils/Asserts";
73
74
75test("AVEDEV", function(){
76 assertEquals(AVEDEV(1, 2, 4, 55), 19.75);
77 assertEquals(AVEDEV(1, 2, 4, "55"), 19.75);
78 assertEquals(AVEDEV([1, 2, 4, "55"]), 1.1111111111111112);
79 assertEquals(AVEDEV([1, 2, 4, "55"], [10, 10, "str"]), 3.6799999999999997);
80 assertEquals(AVEDEV([1, 2, 4, "55"], [10, 10]), 3.6799999999999997);
81 assertEquals(AVEDEV(1, 2, 4, "55", [10, [10]]), 13.777777777777777);
82 assertEquals(AVEDEV(1, 2, 4, "55", 10, 10), 13.77777777777778);
83 assertEquals(AVEDEV(1, 2, 4, 55, false), 17.040000000000003);
84 assertEquals(AVEDEV(1, 2, 4, 55, 0), 17.040000000000003);
85 assertEquals(AVEDEV(1, 2, 4, 55, true), 16.959999999999997);
86 assertEquals(AVEDEV(1, 2, 4, 55, 1), 16.959999999999997);
87 assertEquals(AVEDEV([1, 2, 4, 55, 0]), 17.040000000000003);
88 assertEquals(AVEDEV([1, 2, 4, 55], 0), 17.040000000000003);
89 catchAndAssertEquals(function() {
90 AVEDEV();
91 }, ERRORS.NA_ERROR);
92 catchAndAssertEquals(function() {
93 AVEDEV(10, 10, "str");
94 }, ERRORS.VALUE_ERROR);
95 catchAndAssertEquals(function() {
96 AVEDEV(10, 10, []);
97 }, ERRORS.REF_ERROR);
98});
99
100
101test("AVERAGE", function(){
102 assertEquals(AVERAGE(1, 2, 4, 55), 15.5);
103 assertEquals(AVERAGE(1, 2, 4, "55"), 15.5);
104 assertEquals(AVERAGE(1, 2, 4, 55, false), 12.4);
105 assertEquals(AVERAGE(1, 2, 4, 55, true), 12.6);
106 assertEquals(AVERAGE(1, 2, 4, 55, 0), 12.4);
107 assertEquals(AVERAGE(1, 2, 4, 55, 1), 12.6);
108 catchAndAssertEquals(function() {
109 AVERAGE(1, 2, 4, "str");
110 }, ERRORS.VALUE_ERROR);
111 assertEquals(AVERAGE([1, 2, 4, 55, "str"]), 15.5);
112 assertEquals(AVERAGE([1, 2, 4, 55, "22"]), 15.5);
113 assertEquals(AVERAGE([0]), 0);
114 catchAndAssertEquals(function() {
115 AVERAGE();
116 }, ERRORS.NA_ERROR);
117 catchAndAssertEquals(function() {
118 AVERAGE([]);
119 }, ERRORS.REF_ERROR);
120});
121
122
123test("AVERAGEA", function(){
124 assertEquals(AVERAGEA(1, 2, 4, 55), 15.5);
125 assertEquals(AVERAGEA(1, 2, 4, "55"), 15.5);
126 assertEquals(AVERAGEA(1, 2, 4, 55, false), 12.4);
127 assertEquals(AVERAGEA(1, 2, 4, 55, true), 12.6);
128 assertEquals(AVERAGEA(1, 2, 4, 55, 0), 12.4);
129 assertEquals(AVERAGEA(1, 2, 4, 55, 1), 12.6);
130 catchAndAssertEquals(function() {
131 AVERAGEA(1, 2, 4, "str");
132 }, ERRORS.VALUE_ERROR);
133 assertEquals(AVERAGEA([1, 2, 4, 55, "str"]), 12.4);
134 assertEquals(AVERAGEA([1, 2, 4, 55, "22"]), 12.4);
135 assertEquals(AVERAGEA([1, 2, 4, 55, 0]), 12.4);
136 assertEquals(AVERAGEA([0]), 0);
137 catchAndAssertEquals(function() {
138 AVERAGEA();
139 }, ERRORS.NA_ERROR);
140 catchAndAssertEquals(function() {
141 AVERAGEA([]);
142 }, ERRORS.REF_ERROR);
143});
144
145
146test("AVERAGEIF", function(){
147 assertEquals(AVERAGEIF([1, 5, [5, 20, 100], [], [[2]], 10], '>2'), 28);
148 assertEquals(AVERAGEIF([1, 5, 10], '>2'), 7.5);
149 assertEquals(AVERAGEIF([1, 5, 10], ">4"), 7.5);
150 assertEquals(AVERAGEIF([1, 2, 2, 2, 2, 2, 2, 2], ">1"), 2);
151 assertEquals(AVERAGEIF([1, 5, 10], 5), 5);
152 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], 5), 5);
153 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], 10), 10);
154 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], ">5"), 10);
155 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "=5"), 5);
156 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "=10"), 10);
157 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "= 10 "), 10);
158 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], ">0"), 5.166666666666667);
159 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], ">=5"), 6);
160 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "<>1"), 6);
161 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "<10"), 4.2);
162 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5, 44], "<=10"), 5.166666666666667);
163 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], ">4.99"), 6);
164 assertEquals(AVERAGEIF([1, 5, 5, 5, 10, 5], "<4.99"), 1);
165 catchAndAssertEquals(function() {
166 AVERAGEIF([1, 5, 5, 5, 10, 5], "= 1.0.0 ");
167 }, ERRORS.DIV_ZERO_ERROR);
168 catchAndAssertEquals(function() {
169 AVERAGEIF([1, 5, 5, 5, 10, 5], "=>5");
170 }, ERRORS.DIV_ZERO_ERROR);
171 catchAndAssertEquals(function() {
172 AVERAGEIF([1, 5, 5, 5, 10, 5], "==5");
173 }, ERRORS.DIV_ZERO_ERROR);
174});
175
176
177test("CORREL", function(){
178 assertEquals(CORREL([9, 5],[10, 4]), 1);
179 assertEquals(CORREL([10, 5, 16],[9, 3, 22]), 0.9876779373054069);
180 catchAndAssertEquals(function() {
181 CORREL(5, 5);
182 }, ERRORS.DIV_ZERO_ERROR);
183 catchAndAssertEquals(function() {
184 CORREL([9, true], [5, true]);
185 }, ERRORS.DIV_ZERO_ERROR);
186 catchAndAssertEquals(function() {
187 CORREL([9, "10"], [5, "10"]);
188 }, ERRORS.DIV_ZERO_ERROR);
189 catchAndAssertEquals(function() {
190 CORREL([9], [5]);
191 }, ERRORS.DIV_ZERO_ERROR);
192 catchAndAssertEquals(function() {
193 CORREL.apply(this, []);
194 }, ERRORS.NA_ERROR);
195 catchAndAssertEquals(function() {
196 CORREL.apply(this, [[9, 5]]);
197 }, ERRORS.NA_ERROR);
198 catchAndAssertEquals(function() {
199 CORREL.apply(this, [[9, 5],[10]]);
200 }, ERRORS.NA_ERROR);
201});
202
203
204test("PEARSON", function(){
205 // same as CORREL
206 assertEquals(PEARSON([9, 5],[10, 4]), 1);
207});
208
209
210test("COUNT", function(){
211 assertEquals(COUNT([1, 5, 10, 0]), 4);
212 assertEquals(COUNT(1, 5, 10, 0), 4);
213 assertEquals(COUNT(1, 5, 10, "0"), 4);
214 assertEquals(COUNT(1, 5, 10, ["0", "str"]), 4);
215 assertEquals(COUNT(1, 5, 10, false), 4);
216 assertEquals(COUNT(1, 5, 10, true), 4);
217 assertEquals(COUNT([]), 0);
218 assertEquals(COUNT(["str"]), 0);
219 catchAndAssertEquals(function() {
220 COUNT();
221 }, ERRORS.NA_ERROR);
222});
223
224
225test("COUNTA", function(){
226 assertEquals(COUNTA(1, 2, 3), 3);
227 assertEquals(COUNTA(0, 1, 2, 3), 4);
228 assertEquals(COUNTA(0, 1, 2, 3, [], []), 6);
229 assertEquals(COUNTA(0, 1, 2, 3, [], ""), 6);
230 assertEquals(COUNTA(1, 2, "3"), 3);
231 assertEquals(COUNTA(1, 2, "3", ["str"]), 4);
232 assertEquals(COUNTA(1, 2, false), 3);
233 assertEquals(COUNTA(1, 2, true), 3);
234 assertEquals(COUNTA([]), 1);
235 catchAndAssertEquals(function() {
236 COUNTA();
237 }, ERRORS.NA_ERROR);
238});
239
240
241test("DEVSQ", function(){
242 assertEquals(DEVSQ(1, 2), 0.5);
243 assertEquals(DEVSQ([1, 2]), 0.5);
244 assertEquals(DEVSQ([1, [2]]), 0.5);
245 assertEquals(DEVSQ(1), 0);
246 assertEquals(DEVSQ(false), 0);
247 assertEquals(DEVSQ(true), 0);
248 assertEquals(DEVSQ(1, 2, 3, 4), 5);
249 assertEquals(DEVSQ([1, 2, 3, 4]), 5);
250 catchAndAssertEquals(function() {
251 DEVSQ(1, "str");
252 }, ERRORS.VALUE_ERROR);
253 catchAndAssertEquals(function() {
254 DEVSQ();
255 }, ERRORS.NA_ERROR);
256 catchAndAssertEquals(function() {
257 DEVSQ([1, 2, [], 3]);
258 }, ERRORS.REF_ERROR);
259});
260
261
262test("EXPONDIST", function(){
263 assertEquals(EXPONDIST(4, 0.5, false), 0.06766764161830635);
264 assertEquals(EXPONDIST(4, 0.5, 0), 0.06766764161830635);
265 assertEquals(EXPONDIST(4, 0.5, true), 0.8646647167633873);
266 assertEquals(EXPONDIST(4, 0.5, 1), 0.8646647167633873);
267 assertEquals(EXPONDIST(4, 0.5, -1), 0.8646647167633873);
268 assertEquals(EXPONDIST([4, "str"], ["0.5"], [false]), 0.06766764161830635);
269 catchAndAssertEquals(function() {
270 EXPONDIST("str", 0.5, "1");
271 }, ERRORS.VALUE_ERROR);
272 catchAndAssertEquals(function() {
273 EXPONDIST(4, 0.5, "1");
274 }, ERRORS.VALUE_ERROR);
275 catchAndAssertEquals(function() {
276 EXPONDIST.apply(this, []);
277 }, ERRORS.NA_ERROR);
278 catchAndAssertEquals(function() {
279 EXPONDIST.apply(this, [4, 0.5]);
280 }, ERRORS.NA_ERROR);
281 catchAndAssertEquals(function() {
282 EXPONDIST.apply(this, [4, 0.5, true, 1]);
283 }, ERRORS.NA_ERROR);
284});
285
286
287test("FINV", function(){
288 assertEquals(FINV(0.42, 2, 3), 1.174597274485816);
289 assertEquals(FINV(0.42, 2, 5), 1.037042624272801);
290 assertEquals(FINV(0.42, 33, 5), 1.303222112500911);
291 assertEquals(FINV(["0.42"], [33, []], [5]), 1.303222112500911);
292 assertEquals(FINV("0.42", 2, 3), 1.174597274485816);
293 catchAndAssertEquals(function() {
294 FINV.apply(this, []);
295 }, ERRORS.NA_ERROR);
296 catchAndAssertEquals(function() {
297 FINV.apply(this, [0.42, 2, 4, 4]);
298 }, ERRORS.NA_ERROR);
299 catchAndAssertEquals(function() {
300 FINV(0.42, 2, []);
301 }, ERRORS.REF_ERROR);
302 catchAndAssertEquals(function() {
303 FINV(-10, 2, 3);
304 }, ERRORS.NUM_ERROR);
305});
306
307
308test("FISHER", function(){
309 assertEquals(FISHER(0.962), 1.972066740199461);
310 assertEquals(FISHER([0.962]), 1.972066740199461);
311 assertEquals(FISHER("0.962"), 1.972066740199461);
312 assertEquals(FISHER(0), 0);
313 assertEquals(FISHER(false), 0);
314 assertEquals(FISHER(0.92), 1.589026915173973);
315 catchAndAssertEquals(function() {
316 FISHER("str");
317 }, ERRORS.VALUE_ERROR);
318 catchAndAssertEquals(function() {
319 FISHER(1);
320 }, ERRORS.NUM_ERROR);
321 catchAndAssertEquals(function() {
322 FISHER(-1);
323 }, ERRORS.NUM_ERROR);
324 catchAndAssertEquals(function() {
325 FISHER.apply(this, []);
326 }, ERRORS.NA_ERROR);
327 catchAndAssertEquals(function() {
328 FISHER.apply(this, [0.55, 0.1]);
329 }, ERRORS.NA_ERROR);
330});
331
332
333test("FISHERINV", function(){
334 assertEquals(FISHERINV(0.962), 0.7451676440945232);
335 assertEquals(FISHERINV(0.962), 0.7451676440945232);
336 assertEquals(FISHERINV([0.962]), 0.7451676440945232);
337 assertEquals(FISHERINV("0.962"), 0.7451676440945232);
338 assertEquals(FISHERINV(0), 0);
339 assertEquals(FISHERINV(false), 0);
340 assertEquals(FISHERINV(true), 0.7615941559557649);
341 assertEquals(FISHERINV(0.92), 0.7258974148490807);
342 catchAndAssertEquals(function() {
343 FISHER("str");
344 }, ERRORS.VALUE_ERROR);
345 catchAndAssertEquals(function() {
346 FISHER.apply(this, []);
347 }, ERRORS.NA_ERROR);
348 catchAndAssertEquals(function() {
349 FISHER.apply(this, [0.55, 0.1]);
350 }, ERRORS.NA_ERROR);
351});
352
353
354test("MAX", function(){
355 assertEquals(MAX(100, 22), 100);
356 assertEquals(MAX(100, "22"), 100);
357 assertEquals(MAX(-100, false), 0);
358 assertEquals(MAX(-100, true), 1);
359 assertEquals(MAX(100, [101, 2]), 101);
360 assertEquals(MAX(100, [101, 2, "10000"]), 101);
361 assertEquals(MAX(100, ["10000"]), 100);
362 catchAndAssertEquals(function() {
363 MAX(100, []);
364 }, ERRORS.REF_ERROR);
365 catchAndAssertEquals(function() {
366 MAX([]);
367 }, ERRORS.REF_ERROR);
368 catchAndAssertEquals(function() {
369 MAX();
370 }, ERRORS.NA_ERROR);
371 catchAndAssertEquals(function() {
372 MAX(100, "str");
373 }, ERRORS.VALUE_ERROR);
374});
375
376
377test("MAXA", function(){
378 assertEquals(MAXA(100, 22, 44), 100);
379 assertEquals(MAXA("100", 22, 44), 44);
380 assertEquals(MAXA(-1, -10, "stuff"), 0);
381 catchAndAssertEquals(function() {
382 MAX(100, []);
383 }, ERRORS.REF_ERROR);
384 catchAndAssertEquals(function() {
385 MAX([]);
386 }, ERRORS.REF_ERROR);
387 catchAndAssertEquals(function() {
388 MAX.apply(this, []);
389 }, ERRORS.NA_ERROR);
390});
391
392
393test("MEDIAN", function(){
394 assertEquals(MEDIAN(100, 22, 54), 54);
395 assertEquals(MEDIAN(100, 22, "54"), 54);
396 assertEquals(MEDIAN(100, 22), 61);
397 assertEquals(MEDIAN(2), 2);
398 assertEquals(MEDIAN(false), 0);
399 assertEquals(MEDIAN(1, 1, 2, 6, 6, 9, 5), 5);
400 assertEquals(MEDIAN(6, 6, 1, 1, 2, 9), 4);
401 assertEquals(MEDIAN(1, 1, 2, [5, 6, 6, 9]), 5);
402 catchAndAssertEquals(function() {
403 MEDIAN(1, 1, 2, 5, "mmm", 6, 6, 9);
404 }, ERRORS.VALUE_ERROR);
405 assertEquals(MEDIAN(1, 1, 2, [5, "mmm", 6, 6, 9]), 5);
406 assertEquals(MEDIAN(1, 1, 2, ["mm"]), 1);
407 assertEquals(MEDIAN(100, 22, 1, 14), 18);
408 assertEquals(MEDIAN(100, 22, 1, 1), 11.5);
409 assertEquals(MEDIAN(100, 22, 1), 22);
410 assertEquals(MEDIAN(100, 22, [54]), 54);
411 assertEquals(MEDIAN(100, 22, ["str"]), 61);
412 catchAndAssertEquals(function() {
413 MEDIAN(10, 22, "str");
414 }, ERRORS.VALUE_ERROR);
415 catchAndAssertEquals(function() {
416 MEDIAN();
417 }, ERRORS.NA_ERROR);
418 catchAndAssertEquals(function() {
419 MEDIAN(["str"]);
420 }, ERRORS.NUM_ERROR);
421});
422
423
424test("MIN", function(){
425 assertEquals(MIN(100, 22, 44), 22);
426 assertEquals(MIN(100, "22"), 22);
427 assertEquals(MIN(100, false), 0);
428 assertEquals(MIN(100, true), 1);
429 assertEquals(MIN(100, [101, 2]), 2);
430 assertEquals(MIN(100, [101, 2, "-10"]), 2);
431 assertEquals(MIN(100, ["-10"]), 100);
432 catchAndAssertEquals(function() {
433 MIN(100, []);
434 }, ERRORS.REF_ERROR);
435 catchAndAssertEquals(function() {
436 MIN([]);
437 }, ERRORS.REF_ERROR);
438 catchAndAssertEquals(function() {
439 MIN();
440 }, ERRORS.NA_ERROR);
441 catchAndAssertEquals(function() {
442 MIN(100, "str");
443 }, ERRORS.VALUE_ERROR);
444});
445
446
447// TODO: More tests for MINA
448test("MINA", function(){
449 assertEquals(MINA(100, 22, 44), 22);
450});
451
452
453test("F.DIST", function(){
454 assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, false), 0.0003451054686025578);
455 assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, true), 0.9980694465675269);
456 assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, 1), 0.9980694465675269);
457 assertEquals(FDIST$LEFTTAILED(15.35, "7", [6], 1), 0.9980694465675269);
458 assertEquals(FDIST$LEFTTAILED(15.35, "7", [6], 10), 0.9980694465675269);
459 catchAndAssertEquals(function() {
460 FDIST$LEFTTAILED(15.35, 7, 6, "10");
461 }, ERRORS.VALUE_ERROR);
462 catchAndAssertEquals(function() {
463 FDIST$LEFTTAILED(-15.35, 7, 6, 1);
464 }, ERRORS.NUM_ERROR);
465 catchAndAssertEquals(function() {
466 FDIST$LEFTTAILED.apply(this, [15.35, 7, 6]);
467 }, ERRORS.NA_ERROR);
468 catchAndAssertEquals(function() {
469 FDIST$LEFTTAILED.apply(this, []);
470 }, ERRORS.NA_ERROR);
471});
472
473
474test("PERCENTILE", function () {
475 assertEquals(PERCENTILE([72, 57, 66, 92, 32, 17, 146], 0.5), 66);
476 assertEquals(PERCENTILE([72, 57, 66, 92, 32, 17, 146], 0.2), 37.00000000000001);
477 assertEquals(PERCENTILE([72, 57, 66, 92, 32, 17, 146], 0.1), 26);
478 assertEquals(PERCENTILE([72, 57, 66, 92, 32, 17, 146], 0), 17);
479 assertEquals(PERCENTILE([72], 0.2), 72);
480 assertEquals(PERCENTILE([72], 0), 72);
481 assertEquals(PERCENTILE([72], 1), 72);
482 assertEquals(PERCENTILE([72], 0.1111), 72);
483 catchAndAssertEquals(function() {
484 PERCENTILE.apply(this, [[], 0]);
485 }, ERRORS.REF_ERROR);
486 catchAndAssertEquals(function() {
487 PERCENTILE.apply(this, [[10], 0, 10]);
488 }, ERRORS.NA_ERROR);
489 catchAndAssertEquals(function() {
490 PERCENTILE.apply(this, [[10]]);
491 }, ERRORS.NA_ERROR);
492 catchAndAssertEquals(function() {
493 PERCENTILE.apply(this, [[10], -0.1]);
494 }, ERRORS.NUM_ERROR);
495 catchAndAssertEquals(function() {
496 PERCENTILE.apply(this, [[10], 1.1]);
497 }, ERRORS.NUM_ERROR);
498});
499
500
501test("QUARTILE", function(){
502 assertEquals(QUARTILE([1, 2, 3, 4], 0), 1);
503 assertEquals(QUARTILE([1, 2, 3, 4], 1), 1.75);
504 assertEquals(QUARTILE([1, 2, 3, 4], 2), 2.5);
505 assertEquals(QUARTILE([1, 2, 3, 4], 3), 3.25);
506 assertEquals(QUARTILE([1, 2, 3, 4], 4), 4);
507 catchAndAssertEquals(function() {
508 QUARTILE.apply(this, [[1, 2, 3, 4], 5]);
509 }, ERRORS.NUM_ERROR);
510 catchAndAssertEquals(function() {
511 QUARTILE.apply(this, [[1, 2, 3, 4], -1]);
512 }, ERRORS.NUM_ERROR);
513 catchAndAssertEquals(function() {
514 QUARTILE.apply(this, [[1, 2, 3, 4]]);
515 }, ERRORS.NA_ERROR);
516 catchAndAssertEquals(function() {
517 QUARTILE.apply(this, [[1, 2, 3, 4], 5, 7]);
518 }, ERRORS.NA_ERROR);
519});
520
521
522test("STDEV", function(){
523 assertEquals(STDEV(1, 2, 3, 4, 5, 6, 7, "18281821"), 2.160246899469287);
524 assertEquals(STDEV(1, 2, 3, 4, 5, 6, 7), 2.160246899469287);
525 assertEquals(STDEV([1, 2, 3, 4, 5, 6, 7]), 2.160246899469287);
526 assertEquals(STDEV(1, 2, 3, [4, 5], 6, 7), 2.160246899469287);
527 assertEquals(STDEV(33, 44), 7.7781745930520225);
528 assertEquals(STDEV(33, 44, 0, 1, 0, 1), 19.934057957843574);
529 assertEquals(STDEV(33, 44, false, true, false, true), 19.934057957843574);
530 catchAndAssertEquals(function() {
531 STDEV();
532 }, ERRORS.NA_ERROR);
533 catchAndAssertEquals(function() {
534 STDEV([10, 10, [], 10]);
535 }, ERRORS.REF_ERROR);
536});
537
538
539test("STDEVA", function(){
540 assertEquals(STDEVA(1, 2, 3, 4, 5, 6, 7, "123"), 42.12036324629692);
541 assertEquals(STDEVA(1, 2, 3, 4, 5, 6, 7, 123), 42.12036324629692);
542 assertEquals(STDEVA(1, 2, 3, 4, 5, 6, 7), 2.160246899469287);
543 assertEquals(STDEVA([1, 2, 3, 4, 5, 6, 7]), 2.160246899469287);
544 assertEquals(STDEVA(1, 2, 3, [4, 5], 6, 7), 2.160246899469287);
545 assertEquals(STDEVA(33, 44), 7.7781745930520225);
546 assertEquals(STDEVA(33, 44, 0, 1, 0, 1), 19.934057957843574);
547 assertEquals(STDEVA(33, 44, false, true, false, true), 19.934057957843574);
548 catchAndAssertEquals(function() {
549 STDEVA(1, 2, 3, 4, 5, 6, 7, "string");
550 }, ERRORS.VALUE_ERROR);
551 catchAndAssertEquals(function() {
552 STDEVA();
553 }, ERRORS.NA_ERROR);
554 catchAndAssertEquals(function() {
555 STDEVA([10, 10, [], 10]);
556 }, ERRORS.REF_ERROR);
557});
558
559test("STDEVP", function(){
560 assertEquals(STDEVP(1, 2, 3, 4, 5, 6, 7, 123), 39.39999206852712);
561 assertEquals(STDEVP(1, 2, 3, 4, 5, 6, 7, "132321"), 2);
562 assertEquals(STDEVP(1, 2, 3, 4, 5, 6, 7), 2);
563 assertEquals(STDEVP([1, 2, 3, 4, 5, 6, 7]), 2);
564 assertEquals(STDEVP(1, 2, 3, [4, 5], 6, 7), 2);
565 assertEquals(STDEVP(33, 44), 5.5);
566 assertEquals(STDEVP(33, 44, 0, 1, 0, 1), 18.197222010210485);
567 assertEquals(STDEVP(33, 44, false, true, false, true), 18.197222010210485);
568 catchAndAssertEquals(function() {
569 STDEVP();
570 }, ERRORS.NA_ERROR);
571 catchAndAssertEquals(function() {
572 STDEVP([10, 10, [], 10]);
573 }, ERRORS.REF_ERROR);
574});
575
576test("STDEVPA", function() {
577 assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7, 123), 39.39999206852712);
578 assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7, "123"), 39.39999206852712);
579 assertEquals(STDEVPA(1, 2, 3, 4, 5, 6, 7), 2);
580 assertEquals(STDEVPA([1, 2, 3, 4, 5, 6, 7]), 2);
581 assertEquals(STDEVPA(1, 2, 3, [4, 5], 6, 7), 2);
582 assertEquals(STDEVPA(33, 44), 5.5);
583 assertEquals(STDEVPA(33, 44, 0, 1, 0, 1), 18.197222010210485);
584 assertEquals(STDEVPA(33, 44, false, true, false, true), 18.197222010210485);
585 catchAndAssertEquals(function() {
586 STDEVPA(1, 2, 3, 4, 5, 6, 7, "string");
587 }, ERRORS.VALUE_ERROR);
588 catchAndAssertEquals(function() {
589 STDEVPA();
590 }, ERRORS.NA_ERROR);
591 catchAndAssertEquals(function() {
592 STDEVPA([10, 10, [], 10]);
593 }, ERRORS.REF_ERROR);
594});
595
596test("TRIMMEAN", function() {
597 assertEquals(TRIMMEAN([1.1, 2, 3, 44, 20, 21, 7], 0.05), 14.014285714285714);
598 assertEquals(TRIMMEAN([1.1, 2, 3, 44, 20, 21, 7, 1, 22], 0.1), 13.455555555555556);
599 assertEquals(TRIMMEAN([1], 0.1), 1);
600 catchAndAssertEquals(function() {
601 TRIMMEAN([], 0.1);
602 }, ERRORS.REF_ERROR);
603 catchAndAssertEquals(function() {
604 TRIMMEAN([10], 1);
605 }, ERRORS.NUM_ERROR);
606 catchAndAssertEquals(function() {
607 TRIMMEAN([10], -1);
608 }, ERRORS.NUM_ERROR);
609});
610
611test("SLOPE", function() {
612 assertEquals(SLOPE([1, 2.2, 4, 5.5, 6, 8], [1.9, 22.2, 44, 55.5, 88, 99.1]), 0.06727907586278936);
613 assertEquals(SLOPE([1.1, 2.44, 5, 10.5, 600, 800], [1.9, 22.2, 44, 55.5, 88, 99.1]), 8.50783378332324);
614 assertEquals(SLOPE([1.1, 2.44, 5, 10.5, 600, "ignore", 800], [1.9, 22.2, 44, 55.5, 88, 99.1]), 8.50783378332324);
615 assertEquals(SLOPE([600, 800], [44, 4.1]), -5.012531328320802);
616 assertEquals(SLOPE([1, 2.2, 4, 5.5, 6, 8, true], [1.9, 22.2, 44, 55.5, 88, 99.1, true]), 0.06743685772979165);
617 catchAndAssertEquals(function() {
618 SLOPE([1], [0]);
619 }, ERRORS.DIV_ZERO_ERROR);
620 catchAndAssertEquals(function() {
621 SLOPE([1], [1]);
622 }, ERRORS.DIV_ZERO_ERROR);
623 catchAndAssertEquals(function() {
624 SLOPE([1, 3], [1]);
625 }, ERRORS.NA_ERROR);
626});
627
628test("STANDARDIZE", function() {
629 assertEquals(STANDARDIZE(10, 2, 1), 8);
630 assertEquals(STANDARDIZE(44, 2.1, 99), 0.42323232323232324);
631 assertEquals(STANDARDIZE(10, 2, [1, []]), 8);
632 assertEquals(STANDARDIZE(44, 0, 10), 4.4);
633 assertEquals(STANDARDIZE(0, 0, 1), 0);
634 catchAndAssertEquals(function() {
635 STANDARDIZE(44, 2.1, 0);
636 }, ERRORS.NUM_ERROR);
637 catchAndAssertEquals(function() {
638 STANDARDIZE(44, 2.1, -10);
639 }, ERRORS.NUM_ERROR);
640 catchAndAssertEquals(function() {
641 STANDARDIZE.apply(this, [4, 3, 4, 4]);
642 }, ERRORS.NA_ERROR);
643 catchAndAssertEquals(function() {
644 STANDARDIZE.apply(this, [4, 3]);
645 }, ERRORS.NA_ERROR);
646});
647
648test("SMALL", function() {
649 assertEquals(SMALL([2, 12, 22, 1, 0.1, 44, "77", "hello"], 3), 2);
650 assertEquals(SMALL([2, 12, 22, 1, 0.1, 44, "77", "hello"], 4), 12);
651 assertEquals(SMALL([2, 12, 22, 1, 0.1, 44, "77", "hello"], 5), 22);
652 catchAndAssertEquals(function() {
653 SMALL([44, 2.1, "str"], 3);
654 }, ERRORS.NUM_ERROR);
655 catchAndAssertEquals(function() {
656 SMALL([44, 2.1], 3);
657 }, ERRORS.NUM_ERROR);
658 catchAndAssertEquals(function() {
659 SMALL.apply(this, [[44, 2.1], 3, 4]);
660 }, ERRORS.NA_ERROR);
661});
662
663test("LARGE", function() {
664 assertEquals(LARGE([2, 12, 22, 1, 0.1, 44, "77", "hello"], 2), 22);
665 assertEquals(LARGE([2, 12, 22, 1, 0.1, 44, "77", "hello"], 3), 12);
666 assertEquals(LARGE([2, 12, 22, 1, 0.1, 44, "77", "hello"], 4), 2);
667 catchAndAssertEquals(function() {
668 LARGE([44, 2.1, "str"], 3);
669 }, ERRORS.NUM_ERROR);
670 catchAndAssertEquals(function() {
671 LARGE([44, 2.1], 3);
672 }, ERRORS.NUM_ERROR);
673 catchAndAssertEquals(function() {
674 LARGE.apply(this, [[44, 2.1], 3, 4]);
675 }, ERRORS.NA_ERROR);
676});
677
678test("KURT", function() {
679 assertEquals(KURT(3, 4, 5, 6, 9, 11, 15), -0.23508087990005144);
680 assertEquals(KURT(3, 4, 5, 6, 9, 11, 15, "ignore"), -0.23508087990005144);
681 assertEquals(KURT(11, 15, 11, 1), 2.602498034762867);
682 catchAndAssertEquals(function() {
683 KURT(1, 2, 3);
684 }, ERRORS.NA_ERROR);
685 catchAndAssertEquals(function() {
686 KURT(1, 2, 3, "ignore");
687 }, ERRORS.DIV_ZERO_ERROR);
688});
689
690test("INTERCEPT", function() {
691 assertEquals(INTERCEPT([1, 2, 3, 4], [10, 20, 33, 44]), 0.1791776688042246);
692 assertEquals(INTERCEPT([true, 2, 3, 4], [10, 20, 33, "ignore", 44]), 0.1791776688042246);
693 assertEquals(INTERCEPT([1, 2], [10, 20]), 0);
694 catchAndAssertEquals(function() {
695 INTERCEPT([1], [10])
696 }, ERRORS.DIV_ZERO_ERROR);
697 catchAndAssertEquals(function() {
698 INTERCEPT([1, "ignore"], [10, "ignore"])
699 }, ERRORS.DIV_ZERO_ERROR);
700 catchAndAssertEquals(function() {
701 INTERCEPT.apply(this, [[1, 2, 3]]);
702 }, ERRORS.NA_ERROR);
703 catchAndAssertEquals(function() {
704 INTERCEPT.apply(this, [[1, 2, 3], [1, 2, 3], [1, 2, 3]]);
705 }, ERRORS.NA_ERROR);
706});
707
708test("FORCAST", function() {
709 assertEquals(FORECAST(0, [1, 2, 3, 4], [10, 20, 33, 44]), 0.1791776688042246);
710 assertEquals(FORECAST(1, [1, 2, 3, 4], [10, 20, 33, 44]), 0.2659373821199545);
711 assertEquals(FORECAST(22, [1, 2, 3, 4], [10, 20, 33, 44]), 2.087891361750283);
712 assertEquals(FORECAST(-10, [1, 2, 3, 4], [10, 20, 33, 44]), -0.6884194643530746);
713 assertEquals(FORECAST(0, [true, 2, 3, 4], [10, 20, 33, "ignore", 44]), 0.1791776688042246);
714 assertEquals(FORECAST(0, [1, 2], [10, 20]), 0);
715 catchAndAssertEquals(function() {
716 FORECAST(0, [1], [10])
717 }, ERRORS.DIV_ZERO_ERROR);
718 catchAndAssertEquals(function() {
719 FORECAST(0, [1, "ignore"], [10, "ignore"])
720 }, ERRORS.DIV_ZERO_ERROR);
721 catchAndAssertEquals(function() {
722 FORECAST.apply(this, [[1, 2, 3]]);
723 }, ERRORS.NA_ERROR);
724 catchAndAssertEquals(function() {
725 FORECAST.apply(this, [0, [1, 2, 3], [1, 2, 3], [1, 2, 3]]);
726 }, ERRORS.NA_ERROR);
727});
728
729
730test("POISSON", function() {
731 assertEquals(POISSON(3, 500, true), 1.4932281660406588e-210);
732 assertEquals(POISSON(30, 500, true), 2.660801877634623e-169);
733 assertEquals(POISSON(3, 5, true), 0.2650259152973617);
734 assertEquals(POISSON(3, 5, false), 0.14037389581428056);
735 assertEquals(POISSON(3, 5), 0.14037389581428056);
736 catchAndAssertEquals(function() {
737 POISSON(-3, 5);
738 }, ERRORS.NUM_ERROR);
739 catchAndAssertEquals(function() {
740 POISSON(3, -5);
741 }, ERRORS.NUM_ERROR);
742 catchAndAssertEquals(function() {
743 POISSON.apply(this, [1, 2, 3, 4]);
744 }, ERRORS.NA_ERROR);
745 catchAndAssertEquals(function() {
746 POISSON.apply(this, [1]);
747 }, ERRORS.NA_ERROR);
748});
749
750
751test("PERCENTRANK", function() {
752 assertEquals(PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 4), 0.583);
753 assertEquals(PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 5), 0.666);
754 assertEquals(PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 0), 0);
755 assertEquals(PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1, -4], -1), 0.057);
756 assertEquals(PERCENTRANK([1], 1), 1);
757 assertEquals(PERCENTRANK([44], 44), 1);
758 catchAndAssertEquals(function() {
759 PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 10);
760 }, ERRORS.NA_ERROR);
761 catchAndAssertEquals(function() {
762 PERCENTRANK([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], -1);
763 }, ERRORS.NA_ERROR);
764});
765
766
767test("PERCENTRANK$EXC", function() {
768 assertEquals(PERCENTRANK$EXC([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 4), 0.571);
769 assertEquals(PERCENTRANK$EXC([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 5), 0.642);
770 assertEquals(PERCENTRANK$EXC([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 7), 0.785);
771 assertEquals(PERCENTRANK$EXC([1], 1), 1);
772 assertEquals(PERCENTRANK$EXC([22], 22), 1);
773 catchAndAssertEquals(function() {
774 PERCENTRANK$EXC([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], 10);
775 }, ERRORS.NA_ERROR);
776 catchAndAssertEquals(function() {
777 PERCENTRANK$EXC([1, 5, 3, 7, 3, 2, 6, 8, 4, 9, 0, 3, 1], -1);
778 }, ERRORS.NA_ERROR);
779});
780
781
782test("NORMSINV", function() {
783 assertEquals(NORMSINV(0.1), -1.2815515655446006);
784 assertEquals(NORMSINV(0.4), -0.25334710313580006);
785 catchAndAssertEquals(function() {
786 NORMSINV(0);
787 }, ERRORS.NUM_ERROR);
788 catchAndAssertEquals(function() {
789 NORMSINV(1);
790 }, ERRORS.NUM_ERROR);
791 catchAndAssertEquals(function() {
792 NORMSINV.apply(this, [1, 2]);
793 }, ERRORS.NA_ERROR);
794});
795
796
797test("NORMSDIST", function() {
798 assertEquals(NORMSDIST(0.1), 0.5398278372770289);
799 assertEquals(NORMSDIST(0.4), 0.6554217416103242);
800 assertEquals(NORMSDIST(1), 0.8413447460685429);
801 assertEquals(NORMSDIST(11), 1);
802 assertEquals(NORMSDIST(-11), 0);
803 catchAndAssertEquals(function() {
804 NORMSDIST.apply(this, []);
805 }, ERRORS.NA_ERROR);
806 catchAndAssertEquals(function() {
807 NORMSDIST.apply(this, [1, 2]);
808 }, ERRORS.NA_ERROR);
809});
810
811
812test("NORMDIST", function() {
813 assertEquals(NORMDIST(1, 0, 6, true), 0.5661838326109037);
814 assertEquals(NORMDIST(1, 0, 6, false), 0.06557328601698999);
815 assertEquals(NORMDIST(0.5, 0.44, 8, true), 0.5029920390526184);
816 assertEquals(NORMDIST(0.5, 0.44, 8, false), 0.049866382538447475);
817 assertEquals(NORMDIST(-0.5, 0.44, 8, true), 0.4532319220221437);
818 assertEquals(NORMDIST(-0.5, -100, 100, true), 0.840131867824506);
819 catchAndAssertEquals(function() {
820 NORMDIST(-0.5, 0.44, 0, true);
821 }, ERRORS.NUM_ERROR);
822 catchAndAssertEquals(function() {
823 NORMDIST.apply(this, [1, 0, 6]);
824 }, ERRORS.NA_ERROR);
825 catchAndAssertEquals(function() {
826 NORMDIST.apply(this, [1, 0, 6, true, 5]);
827 }, ERRORS.NA_ERROR);
828});
829
830
831test("NORMINV", function() {
832 assertEquals(NORMINV(0.8, 0, 6), 5.0497274014374876);
833 assertEquals(NORMINV(0.2, 0, 6), -5.049727401437487);
834 assertEquals(NORMINV(0.4, 1, 6), -0.5200826188148002);
835 catchAndAssertEquals(function() {
836 NORMINV(-0.5, 0.44, 1);
837 }, ERRORS.NUM_ERROR);
838 catchAndAssertEquals(function() {
839 NORMINV(0.5, 0.44, 0);
840 }, ERRORS.NUM_ERROR);
841 catchAndAssertEquals(function() {
842 NORMINV.apply(this, [0.2, 0.8]);
843 }, ERRORS.NA_ERROR);
844 catchAndAssertEquals(function() {
845 NORMINV.apply(this, [0.2, 0.8, 6, 1]);
846 }, ERRORS.NA_ERROR);
847});
848
849
850test("NEGBINOMDIST", function() {
851 assertEquals(NEGBINOMDIST(5, 3, 0.2), 0.05505024000000004);
852 assertEquals(NEGBINOMDIST(10, 3, 0.2), 0.05669356830720007);
853 assertEquals(NEGBINOMDIST(10, 7, 0.8), 0.00017197049053183967);
854 catchAndAssertEquals(function() {
855 NEGBINOMDIST.apply(this, [-10, 7, 0.8]);
856 }, ERRORS.NUM_ERROR);
857 catchAndAssertEquals(function() {
858 NEGBINOMDIST.apply(this, [10, -7, 0.8]);
859 }, ERRORS.NUM_ERROR);
860 catchAndAssertEquals(function() {
861 NEGBINOMDIST.apply(this, [10, 7, -0.8]);
862 }, ERRORS.NUM_ERROR);
863 catchAndAssertEquals(function() {
864 NEGBINOMDIST.apply(this, [0.2, 0.8]);
865 }, ERRORS.NA_ERROR);
866 catchAndAssertEquals(function() {
867 NEGBINOMDIST.apply(this, [0.2, 0.8, 6, 1]);
868 }, ERRORS.NA_ERROR);
869});
870
871
872test("GEOMEAN", function() {
873 assertEquals(GEOMEAN(10, 4, 6, 3, 6, 7, 1, 1), 3.6313885790189477);
874 assertEquals(GEOMEAN(10, 4, 6, [3, 6, [7]], 1, 1), 3.6313885790189477);
875 assertEquals(GEOMEAN(10), 10);
876 catchAndAssertEquals(function() {
877 GEOMEAN(10, 2, 4, 5, 2, 0);
878 }, ERRORS.NUM_ERROR);
879 catchAndAssertEquals(function() {
880 GEOMEAN.apply(this, []);
881 }, ERRORS.NA_ERROR);
882});
883
884
885test("HARMEAN", function() {
886 assertEquals(HARMEAN(10, 4, 6, 3, 6, 7, 1, 1), 2.532027128862095);
887 assertEquals(HARMEAN(10, 4, 6, [3, 6, [7]], 1, 1), 2.532027128862095);
888 assertEquals(GEOMEAN(10), 10);
889 catchAndAssertEquals(function() {
890 HARMEAN(10, 2, 4, 5, 2, 0);
891 }, ERRORS.NUM_ERROR);
892 catchAndAssertEquals(function() {
893 HARMEAN.apply(this, []);
894 }, ERRORS.NA_ERROR);
895});
896
897test("CONFIDENCE", function() {
898 assertEquals(CONFIDENCE(0.04, 6.48, 25), 2.6616585881788426);
899 assertEquals(CONFIDENCE(0.0001, 101.1, 24281), 2.5242568756291566);
900 assertEquals(CONFIDENCE(0.8, 101.1, 24281), 0.1643742612132184);
901 catchAndAssertEquals(function() {
902 CONFIDENCE(0, 101.1, 24281);
903 }, ERRORS.NUM_ERROR);
904 catchAndAssertEquals(function() {
905 CONFIDENCE(0.1, 0, 24281);
906 }, ERRORS.NUM_ERROR);
907 catchAndAssertEquals(function() {
908 CONFIDENCE(0.1, 2.1, 0);
909 }, ERRORS.NUM_ERROR);
910 catchAndAssertEquals(function() {
911 CONFIDENCE.apply(this, [0.8, 101.1]);
912 }, ERRORS.NA_ERROR);
913 catchAndAssertEquals(function() {
914 CONFIDENCE.apply(this, [0.8, 101.1, 24281, 22]);
915 }, ERRORS.NA_ERROR);
916});
917
918test("BINOMDIST", function() {
919 assertEquals(BINOMDIST(20, 22, 0.04, true), 0.9999999999999998);
920 assertEquals(BINOMDIST(14, 22, 0.4, true), 0.9929516025629364);
921 assertEquals(BINOMDIST(14, 22, 0.4, false), 0.014417421604478797);
922 catchAndAssertEquals(function() {
923 BINOMDIST(21, 20, 0.4, false);
924 }, ERRORS.NUM_ERROR);
925 catchAndAssertEquals(function() {
926 BINOMDIST(20, 20, -1, false);
927 }, ERRORS.NUM_ERROR);
928 catchAndAssertEquals(function() {
929 BINOMDIST(20, 0, -1, false);
930 }, ERRORS.NUM_ERROR);
931 catchAndAssertEquals(function() {
932 BINOMDIST.apply(this, [20, 20, 1]);
933 }, ERRORS.NA_ERROR);
934 catchAndAssertEquals(function() {
935 BINOMDIST.apply(this, [20, 20, 1, true, 10]);
936 }, ERRORS.NA_ERROR);
937});
938
939test("COVAR", function() {
940 assertEquals(COVAR([2, 4, 5, 1, 3], [7, 3, 1, 3, 4]), -1.5999999999999999);
941 assertEquals(COVAR([2, 4, 5, 1], [7, 3, 1, 3]), -2);
942 catchAndAssertEquals(function() {
943 COVAR([2, 4, 5, 1], [7, 3, 1, 3, 4]);
944 }, ERRORS.NA_ERROR);
945 catchAndAssertEquals(function() {
946 COVAR.apply(this, [[10, 10, 10]]);
947 }, ERRORS.NA_ERROR);
948 catchAndAssertEquals(function() {
949 COVAR.apply(this, [[10, 10, 10], [1, 2, 4], 1000000]);
950 }, ERRORS.NA_ERROR);
951});
952
953test("WEIBULL", function() {
954 assertEquals(WEIBULL(2.4, 2, 4, true), 0.302323673928969);
955 assertEquals(WEIBULL(3.1, 4, 4, true), 0.3028470073265427);
956 assertEquals(WEIBULL(0.16, 1, 4, false), 0.2401973597880808);
957 catchAndAssertEquals(function() {
958 WEIBULL(-10, 2, 4, true);
959 }, ERRORS.NUM_ERROR);
960 catchAndAssertEquals(function() {
961 WEIBULL(10, 0, 4, true);
962 }, ERRORS.NUM_ERROR);
963 catchAndAssertEquals(function() {
964 WEIBULL(10, 1, 0, true);
965 }, ERRORS.NUM_ERROR);
966 catchAndAssertEquals(function() {
967 WEIBULL.apply(this, [10, 10, 10]);
968 }, ERRORS.NA_ERROR);
969 catchAndAssertEquals(function() {
970 WEIBULL.apply(this, [10, 10, 10, 10, 10]);
971 }, ERRORS.NA_ERROR);
972});
973
974test("VARPA", function() {
975 assertEquals(VARPA(1, 2, 3, 4, 5, 6, 7, 8), 5.25);
976 assertEquals(VARPA(1, 2, 3, 4, [5, [6]], 7, 8), 5.25);
977 assertEquals(VARPA(1, 2, 3, 4, 5, 6, 7, 8, "0"), 6.666666666666667);
978 assertEquals(VARPA(1, 2, 3, 4, 5, 6, 7, 8, "10"), 7.654320987654322);
979 assertEquals(VARPA(1, 2, 3, 4, 5, 6, 7, 8, false), 6.666666666666667);
980 catchAndAssertEquals(function() {
981 VARPA(1);
982 }, ERRORS.DIV_ZERO_ERROR);
983 catchAndAssertEquals(function() {
984 VARPA(1, 2, 3, 4, 5, 6, 7, 8, "ignore");
985 }, ERRORS.VALUE_ERROR);
986 catchAndAssertEquals(function() {
987 VARPA.apply(this, []);
988 }, ERRORS.NA_ERROR);
989});
990
991test("VARP", function() {
992 assertEquals(VARP(1, 2, 3, 4, 5, 6, 7, 8), 5.25);
993 assertEquals(VARP(1, 2, 3, 4, [5, [6]], 7, 8), 5.25);
994 assertEquals(VARP(1, 2, 3, 4, 5, 6, 7, 8, "0"), 6.666666666666667);
995 assertEquals(VARP(1, 2, 3, 4, 5, 6, 7, 8, "10"), 7.654320987654322);
996 assertEquals(VARP(1, 2, 3, 4, 5, 6, 7, 8, false), 6.666666666666667);
997 catchAndAssertEquals(function() {
998 VARP(1);
999 }, ERRORS.DIV_ZERO_ERROR);
1000 catchAndAssertEquals(function() {
1001 VARP(1, 2, 3, 4, 5, 6, 7, 8, "ignore");
1002 }, ERRORS.VALUE_ERROR);
1003 catchAndAssertEquals(function() {
1004 VARP.apply(this, []);
1005 }, ERRORS.NA_ERROR);
1006});
1007
1008test("VARA", function() {
1009 assertEquals(VARA(1, 2, 3, 4, 5, 6, 7, 8), 6);
1010 assertEquals(VARA(1, 2, 3, 4, 5, 6, 7, 8, "0"), 7.5);
1011 assertEquals(VARA(1, 2, 3, 4, 5, 6, 7, 8, false), 7.5);
1012 assertEquals(VARA(1, 2, 3, 4, 5, 6, 7, 8, "10"), 8.611111111111112);
1013 catchAndAssertEquals(function() {
1014 VARA(1);
1015 }, ERRORS.DIV_ZERO_ERROR);
1016 catchAndAssertEquals(function() {
1017 VARA(1, 2, 3, 4, 5, 6, 7, 8, "ignore");
1018 }, ERRORS.VALUE_ERROR);
1019 catchAndAssertEquals(function() {
1020 VARA.apply(this, []);
1021 }, ERRORS.NA_ERROR);
1022});
1023
1024test("VAR", function() {
1025 assertEquals(VAR(1, 2, 3, 4, 5, 6, 7, 8), 6);
1026 assertEquals(VAR(1, 2, 3, 4, 5, 6, 7, 8, "0"), 7.5);
1027 assertEquals(VAR(1, 2, 3, 4, 5, 6, 7, 8, false), 7.5);
1028 assertEquals(VAR(1, 2, 3, 4, 5, 6, 7, 8, "10"), 8.611111111111112);
1029 catchAndAssertEquals(function() {
1030 VAR(1);
1031 }, ERRORS.DIV_ZERO_ERROR);
1032 catchAndAssertEquals(function() {
1033 VAR(1, 2, 3, 4, 5, 6, 7, 8, "ignore");
1034 }, ERRORS.VALUE_ERROR);
1035 catchAndAssertEquals(function() {
1036 VAR.apply(this, []);
1037 }, ERRORS.NA_ERROR);
1038});
1039
1040test("PERMUT", function() {
1041 assertEquals(PERMUT(4, 2), 12);
1042 assertEquals(PERMUT(44, 2), 1892);
1043 assertEquals(PERMUT(11, 1), 11);
1044 assertEquals(PERMUT(4, 0), 1);
1045 assertEquals(PERMUT(0, 0), 1);
1046 catchAndAssertEquals(function() {
1047 PERMUT(4, 20);
1048 }, ERRORS.NUM_ERROR);
1049 catchAndAssertEquals(function() {
1050 PERMUT.apply(this, [1]);
1051 }, ERRORS.NA_ERROR);
1052 catchAndAssertEquals(function() {
1053 PERMUT.apply(this, [1, 2, 3]);
1054 }, ERRORS.NA_ERROR);
1055});
1056
1057test("RSQ", function() {
1058 assertEquals(RSQ([10, 22, 4], [1, 3, 7]), 0.2500000000000001);
1059 assertEquals(RSQ([10, 22], [1, 3]), 1);
1060 catchAndAssertEquals(function() {
1061 RSQ([1, 2, 3], [1, 2]);
1062 }, ERRORS.NA_ERROR);
1063 catchAndAssertEquals(function() {
1064 RSQ(1, 1);
1065 }, ERRORS.DIV_ZERO_ERROR);
1066 catchAndAssertEquals(function() {
1067 RSQ.apply(this, [[1], [1], [1]]);
1068 }, ERRORS.NA_ERROR);
1069 catchAndAssertEquals(function() {
1070 RSQ.apply(this, [[1]]);
1071 }, ERRORS.NA_ERROR);
1072});
1073
1074test("SKEW", function() {
1075 assertEquals(SKEW(1, 2, 3, 4, 5, 6), 0);
1076 assertEquals(SKEW(1, 2, 3,[4, 5], 6), 0);
1077 assertEquals(SKEW(1, 2, 3, 4, 5, 6, 100), 2.6336050735387375);
1078 catchAndAssertEquals(function() {
1079 SKEW(1)
1080 }, ERRORS.DIV_ZERO_ERROR);
1081 catchAndAssertEquals(function() {
1082 SKEW.apply(this, []);
1083 }, ERRORS.NA_ERROR);
1084});
1085
1086test("STEYX", function() {
1087 assertEquals(STEYX([1, 2, 3, 4], [1, 3, 5, 2]), 1.4638501094227998);
1088 assertEquals(STEYX([1, 2, 3, 4, "str"], [1, 3, 5, 2, "str"]), 1.4638501094227998);
1089 assertEquals(STEYX([1, 2, 3], [1, 3, 5]), 0);
1090 catchAndAssertEquals(function() {
1091 STEYX([1, 2], [1, 3]);
1092 }, ERRORS.DIV_ZERO_ERROR);
1093 catchAndAssertEquals(function() {
1094 STEYX([1, 2, 3, 4], [1, 2, 3]);
1095 }, ERRORS.NA_ERROR);
1096 catchAndAssertEquals(function() {
1097 STEYX.apply(this, [[1, 2, 3]]);
1098 }, ERRORS.NA_ERROR);
1099 catchAndAssertEquals(function() {
1100 STEYX.apply(this, [[1, 2, 3], [1, 2, 3], [1, 2, 3]]);
1101 }, ERRORS.NA_ERROR);
1102});
1103
1104test("PROB", function() {
1105 assertEquals(PROB([1, 2, 3, 4], [0.25, 0.25, 0.25, 0.25], 3), 0.25);
1106 assertEquals(PROB([1], [1], 3), 0);
1107 assertEquals(PROB([1], [1], 0.1, 100), 1);
1108 assertEquals(PROB([1, 2, 3], [0.25, 0.25, 0.5], 3), 0.5);
1109 assertEquals(PROB([1, 2, 4], [0.25, 0.25, 0.5], 3), 0);
1110 assertEquals(PROB([1, 2, 3], [0.25, 0.25, 0.5], 3, 100), 0.5);
1111 assertEquals(PROB([1, 2, 3], [0.25, 0.25, 0.5], 0.1, 100), 1);
1112 catchAndAssertEquals(function() {
1113 PROB([1, 2, 3, 4], [0.25, 0.25, 0.25], 3);
1114 }, ERRORS.NA_ERROR);
1115 catchAndAssertEquals(function() {
1116 PROB([1, 2, 3, 4], [0.25, 0.25, 0.25, 0.99], 3);
1117 }, ERRORS.VALUE_ERROR);
1118 catchAndAssertEquals(function() {
1119 PROB.apply(this, [[1, 2, 3, 4], [0.25, 0.25, 0.25]]);
1120 }, ERRORS.NA_ERROR);
1121 catchAndAssertEquals(function() {
1122 PROB.apply(this, [[1, 2, 3, 4], [0.25, 0.25, 0.25], 10, 10, 10]);
1123 }, ERRORS.NA_ERROR);
1124});
1125
1126test("MODE", function() {
1127 assertEquals(MODE(1, 6, 7, 7, 8), 7);
1128 assertEquals(MODE(1, 6, 6, 7, 7, 8), 6);
1129 assertEquals(MODE(1, 6, 6, 7, 8), 6);
1130 assertEquals(MODE(1, 6, 6, 7, "10"), 6);
1131 assertEquals(MODE(1), 1);
1132 catchAndAssertEquals(function() {
1133 MODE(1, 2, 8);
1134 }, ERRORS.NA_ERROR);
1135 catchAndAssertEquals(function() {
1136 MODE();
1137 }, ERRORS.NA_ERROR);
1138});
1139
1140test("RANK", function() {
1141 assertEquals(RANK(2, [1, 2, 3, 4, 5, 6, 7, 8, 9], true), 2);
1142 assertEquals(RANK(3, [1, 3, 4, 5, 6, 7, 8, 9]), 7);
1143 assertEquals(RANK(3, [1, 3, 4, 5, 6, 7, 8, 9], true), 2);
1144 assertEquals(RANK(2, [7, 1, 2, 4, 100, 8, 9], true), 2);
1145 catchAndAssertEquals(function() {
1146 RANK(44, [7, 1]);
1147 }, ERRORS.NA_ERROR);
1148 catchAndAssertEquals(function() {
1149 RANK.apply(this, [44]);
1150 }, ERRORS.NA_ERROR);
1151 catchAndAssertEquals(function() {
1152 RANK.apply(this, [44, [7, 1], true, false]);
1153 }, ERRORS.NA_ERROR);
1154});
1155
1156test("RANK.AVG", function() {
1157 assertEquals(RANK$AVG(2, [1, 2, 2, 3, 4, 5, 6, 7, 8, 9], true), 2.5);
1158 assertEquals(RANK$AVG(2, [1, 2, 2, 3, 4, 5, 6, 7, 8, 9]), 8.5);
1159 assertEquals(RANK$AVG(2, [2]), 1);
1160 assertEquals(RANK$AVG(2, [1, 2, 3, 4, 5, 6, 7, 8, 9], true), 2);
1161 assertEquals(RANK$AVG(3, [1, 3, 4, 5, 6, 7, 8, 9]), 7);
1162 assertEquals(RANK$AVG(3, [1, 3, 4, 5, 6, 7, 8, 9], true), 2);
1163 assertEquals(RANK$AVG(2, [7, 1, 2, 4, 100, 8, 9], true), 2);
1164 catchAndAssertEquals(function() {
1165 RANK$AVG(44, [7, 1]);
1166 }, ERRORS.NA_ERROR);
1167 catchAndAssertEquals(function() {
1168 RANK$AVG.apply(this, [44]);
1169 }, ERRORS.NA_ERROR);
1170 catchAndAssertEquals(function() {
1171 RANK$AVG.apply(this, [44, [7, 1], true, false]);
1172 }, ERRORS.NA_ERROR);
1173});
1174
1175test("RANK.EQ", function() {
1176 assertEquals(RANK$EQ(2, [1, 2, 3, 4, 5, 6, 7, 8, 9], true), 2);
1177 assertEquals(RANK$EQ(4, [2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9], true), 6);
1178 assertEquals(RANK$EQ(2, [1, 2, 2, 3, 3, 4, 5, 6, 7, 8, 9], true), 2);
1179 assertEquals(RANK$EQ(3, [2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9], true), 3);
1180 assertEquals(RANK$EQ(3, [1, 3, 4, 5, 6, 7, 8, 9]), 7);
1181 assertEquals(RANK$EQ(3, [1, 3, 4, 5, 6, 7, 8, 9], true), 2);
1182 assertEquals(RANK$EQ(2, [7, 1, 2, 4, 100, 8, 9], true), 2);
1183 catchAndAssertEquals(function() {
1184 RANK$EQ(44, [7, 1]);
1185 }, ERRORS.NA_ERROR);
1186 catchAndAssertEquals(function() {
1187 RANK$EQ.apply(this, [44]);
1188 }, ERRORS.NA_ERROR);
1189 catchAndAssertEquals(function() {
1190 RANK$EQ.apply(this, [44, [7, 1], true, false]);
1191 }, ERRORS.NA_ERROR);
1192});
1193
1194test("LOGNORMDIST", function() {
1195 assertEquals(LOGNORMDIST(4, 4, 6), 0.33155709720516946);
1196 assertEquals(LOGNORMDIST(1, 4, 6), 0.2524925375469229);
1197 assertEquals(LOGNORMDIST(2, 4, 6), 0.29076812115284056);
1198 assertEquals(LOGNORMDIST(20, 100, 6), 0);
1199 catchAndAssertEquals(function() {
1200 LOGNORMDIST(0, 4, 6);
1201 }, ERRORS.NUM_ERROR);
1202 catchAndAssertEquals(function() {
1203 LOGNORMDIST(-10, 4, 6);
1204 }, ERRORS.NUM_ERROR);
1205 catchAndAssertEquals(function() {
1206 LOGNORMDIST(1, 4, -6);
1207 }, ERRORS.NUM_ERROR);
1208 catchAndAssertEquals(function() {
1209 LOGNORMDIST(1, 4, 0);
1210 }, ERRORS.NUM_ERROR);
1211 catchAndAssertEquals(function() {
1212 LOGNORMDIST.apply(this, []);
1213 }, ERRORS.NA_ERROR);
1214 catchAndAssertEquals(function() {
1215 LOGNORMDIST.apply(this, [4, 4, 4, 4]);
1216 }, ERRORS.NA_ERROR);
1217});
1218
1219test("TDIST", function() {
1220 assertEquals(TDIST(0.55, 1, 2), 0.6798800684756632);
1221 assertEquals(TDIST(0.55, 1, 1), 0.3399400342378316);
1222 assertEquals(TDIST(0.55, 100, 1), 0.29177287888140824);
1223 catchAndAssertEquals(function() {
1224 TDIST(0.55, -1, 1);
1225 }, ERRORS.NUM_ERROR);
1226 catchAndAssertEquals(function() {
1227 TDIST(0.55, 1, 44);
1228 }, ERRORS.NUM_ERROR);
1229 catchAndAssertEquals(function() {
1230 TDIST(0.55, 1, 0);
1231 }, ERRORS.NUM_ERROR);
1232 catchAndAssertEquals(function() {
1233 TDIST(-1, 1, 1);
1234 }, ERRORS.NUM_ERROR);
1235 catchAndAssertEquals(function() {
1236 TDIST.apply(this, [4, 4, 4, 4]);
1237 }, ERRORS.NA_ERROR);
1238 catchAndAssertEquals(function() {
1239 TDIST.apply(this, [4, 4]);
1240 }, ERRORS.NA_ERROR);
1241 catchAndAssertEquals(function() {
1242 TDIST.apply(this, []);
1243 }, ERRORS.NA_ERROR);
1244});
1245
1246test("HYPGEOMDIST", function() {
1247 assertEquals(HYPGEOMDIST(4, 12, 20, 44), 0.16895408557348432);
1248 assertEquals(HYPGEOMDIST(5, 12, 20, 40), 0.21512468231044427);
1249 assertEquals(HYPGEOMDIST(1, 12, 29, 40), 5.190757213128131e-9);
1250 catchAndAssertEquals(function() {
1251 HYPGEOMDIST(1, 12, 30, 40);
1252 }, ERRORS.NUM_ERROR);
1253 catchAndAssertEquals(function() {
1254 HYPGEOMDIST(1, 12, 35, 40);
1255 }, ERRORS.NUM_ERROR);
1256 catchAndAssertEquals(function() {
1257 HYPGEOMDIST(1, 12, 35, 40);
1258 }, ERRORS.NUM_ERROR);
1259 catchAndAssertEquals(function() {
1260 HYPGEOMDIST(-1, 12, 20, 44);
1261 }, ERRORS.NUM_ERROR);
1262 catchAndAssertEquals(function() {
1263 HYPGEOMDIST(13, 12, 20, 44);
1264 }, ERRORS.NUM_ERROR);
1265 catchAndAssertEquals(function() {
1266 HYPGEOMDIST.apply(this, [5, 12, 20]);
1267 }, ERRORS.NA_ERROR);
1268 catchAndAssertEquals(function() {
1269 HYPGEOMDIST.apply(this, [5, 12, 20, 40, 44]);
1270 }, ERRORS.NA_ERROR);
1271});
1272
1273test("ZTEST", function() {
1274 assertEquals(ZTEST([1, 2, 3, 4, 5, 6, 7], 5.6, 1.1), 0.9999405457342111);
1275 assertEquals(ZTEST([1, 2, 3, 4], 10.1, 1.1), 1);
1276 assertEquals(ZTEST([1, 2, 3, 4, 5, 6, 7], 5.6, 22), 0.5762927116053485);
1277 assertEquals(ZTEST([1, 2, 3, 4, 5, 6, 7], -100, -100), 0.9970345857641326);
1278 catchAndAssertEquals(function() {
1279 ZTEST.apply(this, [5]);
1280 }, ERRORS.NA_ERROR);
1281 catchAndAssertEquals(function() {
1282 ZTEST.apply(this, [1, 2, 3, 4]);
1283 }, ERRORS.NA_ERROR);
1284});