spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
starting to test RawFormulas without a spreadsheet
author
Ben Vogt <[email protected]>
date
2017-01-14 21:57:27
stats
3 file(s) changed, 72 insertions(+), 3 deletions(-)
files
src/Formulas.ts
src/RawFormulas.ts
tests/FormulasTest.ts
  1diff --git a/src/Formulas.ts b/src/Formulas.ts
  2index aab1a73..59561de 100644
  3--- a/src/Formulas.ts
  4+++ b/src/Formulas.ts
  5@@ -23,7 +23,6 @@ const SUPPORTED_FORMULAS = [
  6 ];
  7 
  8 const CustomFormulas = {
  9-  ABS: RawFormulas.ABS,
 10   "F.DIST": Formula["FDIST"],
 11   "F.INV": Formula["FINV"],
 12   ATAN2: function (x, y) {
 13@@ -212,9 +211,12 @@ const CustomFormulas = {
 14 
 15 var Formulas = {
 16   exists: function(fn: string) {
 17-    return ((fn in CustomFormulas) || SUPPORTED_FORMULAS.indexOf(fn) > -1);
 18+    return ((fn in CustomFormulas) || SUPPORTED_FORMULAS.indexOf(fn) > -1 || (fn in RawFormulas));
 19   },
 20   get: function(fn: string) {
 21+    if (fn in RawFormulas) {
 22+      return RawFormulas[fn];
 23+    }
 24     if (fn in CustomFormulas) {
 25       return CustomFormulas[fn];
 26     }
 27diff --git a/src/RawFormulas.ts b/src/RawFormulas.ts
 28index 33f661b..c367af7 100644
 29--- a/src/RawFormulas.ts
 30+++ b/src/RawFormulas.ts
 31@@ -2,9 +2,40 @@ import * as Formula from "formulajs"
 32 
 33 var ABS = Formula["ABS"];
 34 var ACOS = Formula["ACOS"];
 35-
 36+var ACOSH = Formula["ACOSH"];
 37+var ACOTH = Formula["ACOTH"];
 38+var AND = Formula["AND"];
 39+var ARABIC = Formula["ARABIC"];
 40+var ASIN = Formula["ASIN"];
 41+var ASINH = Formula["ASINH"];
 42+var ATAN = Formula["ATAN"];
 43+var ATAN2 = function (x, y) {
 44+  return Math.atan2(y, x);
 45+};
 46+var ATANH = Formula["ATANH"];
 47+var AVEDEV = Formula["AVEDEV"];
 48+var AVERAGE = Formula["AVERAGE"];
 49+var AVERAGEA = Formula["AVERAGEA"];
 50+var AVERAGEIF = Formula["AVERAGEIF"];
 51+var BASE = Formula["BASE"];
 52+var BIN2DEC = Formula["BIN2DEC"];
 53 
 54 export {
 55   ABS,
 56-  ACOS
 57+  ACOS,
 58+  ACOSH,
 59+  ACOTH,
 60+  AND,
 61+  ARABIC,
 62+  ASIN,
 63+  ASINH,
 64+  ATAN,
 65+  ATAN2,
 66+  ATANH,
 67+  AVEDEV,
 68+  AVERAGE,
 69+  AVERAGEA,
 70+  AVERAGEIF,
 71+  BASE,
 72+  BIN2DEC
 73 }
 74\ No newline at end of file
 75diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
 76index d680dfb..d0c0864 100644
 77--- a/tests/FormulasTest.ts
 78+++ b/tests/FormulasTest.ts
 79@@ -1,9 +1,39 @@
 80-import { ABS, ACOS } from "../src/RawFormulas"
 81+import { ABS, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2, ATANH, AVEDEV, AVERAGE,
 82+  AVERAGEA, AVERAGEIF, BASE, BIN2DEC } from "../src/RawFormulas"
 83 import { assertEquals } from "./utils/Asserts"
 84 
 85-// Test ABS formula
 86 assertEquals(ABS(-10), 10);
 87 assertEquals(ABS(0), 0);
 88 
 89-// Test ACOS formula
 90 assertEquals(ACOS(0), 1.5707963267948966);
 91+
 92+assertEquals(ACOSH(22), 3.783672704329451);
 93+
 94+assertEquals(ACOTH(22), 0.04548588910286339);
 95+
 96+assertEquals(AND(10, 10), true);
 97+assertEquals(AND(10, 0), false);
 98+
 99+assertEquals(ARABIC("XIV"), 14);
100+
101+assertEquals(ASIN(0.1), 0.1001674211615598);
102+
103+assertEquals(ASINH(0.1), 0.09983407889920758);
104+
105+assertEquals(ATAN(0.1), 0.09966865249116204);
106+
107+assertEquals(ATAN2(4, 3), 0.6435011087932844);
108+
109+assertEquals(ATANH(0.44), 0.47223080442042564);
110+
111+assertEquals(AVEDEV(1, 2, 4, 56.7), 20.3875);
112+
113+assertEquals(AVERAGE(10, 20, 4.1), 11.366666666666667);
114+
115+assertEquals(AVERAGEA(10, 20, 4.1), 11.366666666666667);
116+
117+assertEquals(AVERAGEIF([1, 5, 10], '>2'), 7.5);
118+
119+assertEquals(BASE(15, 2, 10), '0000001111');
120+
121+assertEquals(BIN2DEC(1010101010), -342);