spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Statistical,Text] Breaking out tests into seperate files
author
Ben Vogt <[email protected]>
date
2017-04-29 22:05:27
stats
3 file(s) changed, 149 insertions(+), 121 deletions(-)
files
README.md
tests/FormulasTest.ts
tests/StatisticalTest.ts
tests/TextTest.ts
  1diff --git a/README.md b/README.md
  2index b5b5950..8f2e811 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -55,8 +55,6 @@ Right now we're just using the number of days since 1900, but we should check th
  6 
  7 ### Numbers with commas in them should still parse to numbers.
  8 
  9-### Break tests out by category.
 10-
 11 
 12 ## Testing Guidelines
 13 
 14diff --git a/tests/FormulasTest.ts b/tests/StatisticalTest.ts
 15similarity index 72%
 16rename from tests/FormulasTest.ts
 17rename to tests/StatisticalTest.ts
 18index cf7888a..15ec9a8 100644
 19--- a/tests/FormulasTest.ts
 20+++ b/tests/StatisticalTest.ts
 21@@ -1,44 +1,29 @@
 22-import { ARABIC, AVEDEV, AVERAGE,
 23-    AVERAGEA, AVERAGEIF,
 24-    CHAR, CODE, CONCATENATE, CONVERT, PEARSON,
 25-    CORREL, COUNT, COUNTA,
 26-    DEVSQ,
 27-    EXPONDIST, FINV, __COMPLEX, FISHER, FISHERINV,
 28-    MAX, MAXA, MEDIAN, MIN, MINA,
 29-    SPLIT } from "../src/RawFormulas/RawFormulas";
 30+import {
 31+  AVERAGE,
 32+  AVERAGEA,
 33+  AVERAGEIF,
 34+  AVEDEV,
 35+  CORREL,
 36+  COUNT,
 37+  COUNTA,
 38+  PEARSON,
 39+  MEDIAN,
 40+  DEVSQ,
 41+  EXPONDIST,
 42+  FDIST$LEFTTAILED,
 43+  FINV,
 44+  FISHER,
 45+  FISHERINV,
 46+  MAX,
 47+  MAXA,
 48+  MIN,
 49+  MINA
 50+} from "../src/RawFormulas/Statistical";
 51 import * as ERRORS from "../src/Errors"
 52-import {assertEquals, assertArrayEquals} from "./utils/Asserts"
 53-
 54-function catchAndAssertEquals(toExecute, expected) {
 55-  var toThrow = null;
 56-  try {
 57-    toExecute();
 58-    toThrow = true;
 59-  } catch (actualError) {
 60-    if (actualError.name != expected) {
 61-      console.log(expected, "not equal to", actualError.name);
 62-    }
 63-  }
 64-  if (toThrow) {
 65-    throw new Error("expected error: " + expected);
 66-  }
 67-}
 68-
 69-
 70-
 71-// Test ARABIC
 72-assertEquals(ARABIC("XIV"), 14);
 73-assertEquals(ARABIC("M"), 1000);
 74-assertEquals(ARABIC("-IV"), -4);
 75-catchAndAssertEquals(function() {
 76-  ARABIC("b");
 77-}, ERRORS.VALUE_ERROR);
 78-catchAndAssertEquals(function() {
 79-  ARABIC(false);
 80-}, ERRORS.VALUE_ERROR);
 81-catchAndAssertEquals(function() {
 82-  ARABIC(10);
 83-}, ERRORS.VALUE_ERROR);
 84+import {
 85+  assertEquals,
 86+  catchAndAssertEquals
 87+} from "./utils/Asserts";
 88 
 89 
 90 // Test AVEDEV
 91@@ -138,70 +123,6 @@ catchAndAssertEquals(function() {
 92 }, ERRORS.DIV_ZERO_ERROR);
 93 
 94 
 95-// Test CHAR
 96-assertEquals(CHAR(97), "a");
 97-assertEquals(CHAR("97"), "a");
 98-assertEquals(CHAR([97, "m"]), "a");
 99-assertEquals(CHAR([[97], "m"]), "a");
100-catchAndAssertEquals(function() {
101-  CHAR([[], [97], "m"]);
102-}, ERRORS.REF_ERROR);
103-catchAndAssertEquals(function() {
104-  CHAR(false);
105-}, ERRORS.NUM_ERROR);
106-catchAndAssertEquals(function() {
107-  CHAR(10000000);
108-}, ERRORS.NUM_ERROR);
109-catchAndAssertEquals(function() {
110-  CHAR(0);
111-}, ERRORS.NUM_ERROR);
112-catchAndAssertEquals(function() {
113-  CHAR();
114-}, ERRORS.NA_ERROR);
115-
116-
117-// Test CODE
118-assertEquals(CODE('a'), 97);
119-assertEquals(CODE('aa'), 97);
120-assertEquals(CODE('aM'), 97);
121-assertEquals(CODE('#'), 35);
122-assertEquals(CODE(false), 70);
123-assertEquals(CODE(true), 84);
124-catchAndAssertEquals(function() {
125-  CODE();
126-}, ERRORS.NA_ERROR);
127-catchAndAssertEquals(function() {
128-  CODE("a", "m");
129-}, ERRORS.NA_ERROR);
130-catchAndAssertEquals(function() {
131-  CODE("");
132-}, ERRORS.VALUE_ERROR);
133-assertEquals(CODE(['a']), 97);
134-assertEquals(CODE([['a'], 'p']), 97);
135-
136-
137-// Test CONCATENATE
138-assertEquals(CONCATENATE("hey", " ", "there"), "hey there");
139-assertEquals(CONCATENATE(["hey", " ", "there"]), "hey there");
140-assertEquals(CONCATENATE("hey"), "hey");
141-assertEquals(CONCATENATE("hey", 2), "hey2");
142-assertEquals(CONCATENATE("hey", false), "heyFALSE");
143-assertEquals(CONCATENATE([22, 14, "m", false]), "2214mFALSE");
144-assertEquals(CONCATENATE([22, 14, ["m", false]]), "2214mFALSE");
145-catchAndAssertEquals(function() {
146-  CONCATENATE();
147-}, ERRORS.NA_ERROR);
148-catchAndAssertEquals(function() {
149-  CONCATENATE("10", 4, false, []);
150-}, ERRORS.REF_ERROR);
151-catchAndAssertEquals(function() {
152-  CONCATENATE([]);
153-}, ERRORS.REF_ERROR);
154-
155-
156-// Test CONVERT
157-assertEquals(CONVERT(5.1, "mm", "m"), 0.0050999999999999995);
158-
159 // Test CORREL
160 assertEquals(CORREL([9, 5],[10, 4]), 1);
161 assertEquals(CORREL([10, 5, 16],[9, 3, 22]), 0.9876779373054069);
162@@ -305,26 +226,6 @@ catchAndAssertEquals(function() {
163 }, ERRORS.NA_ERROR);
164 
165 
166-// Test F.DIST
167-assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, false), 0.0003451054686025578);
168-assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, true), 0.9980694465675269);
169-assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, 1), 0.9980694465675269);
170-assertEquals(__COMPLEX["F.DIST"](15.35, "7", [6], 1), 0.9980694465675269);
171-assertEquals(__COMPLEX["F.DIST"](15.35, "7", [6], 10), 0.9980694465675269);
172-catchAndAssertEquals(function() {
173-  __COMPLEX["F.DIST"](15.35, 7, 6, "10");
174-}, ERRORS.VALUE_ERROR);
175-catchAndAssertEquals(function() {
176-  __COMPLEX["F.DIST"](-15.35, 7, 6, 1);
177-}, ERRORS.NUM_ERROR);
178-catchAndAssertEquals(function() {
179-  __COMPLEX["F.DIST"](15.35, 7, 6);
180-}, ERRORS.NA_ERROR);
181-catchAndAssertEquals(function() {
182-  __COMPLEX["F.DIST"]();
183-}, ERRORS.NA_ERROR);
184-
185-
186 // Test FINV
187 assertEquals(FINV(0.42, 2, 3), 1.174597274485816);
188 
189@@ -454,16 +355,21 @@ catchAndAssertEquals(function() {
190 assertEquals(MINA(100, 22, 44), 22);
191 
192 
193-// Test SPLIT
194-assertArrayEquals(SPLIT("1,2,3", ","), ['1', '2', '3']);
195-assertArrayEquals(SPLIT("little kitty cat", "i"), ['l', 'ttle k', 'tty cat']);
196-assertArrayEquals(SPLIT("father sister berzerker", "er", true), ['fath', ' sist', ' b', 'z', 'k']);
197-assertArrayEquals(SPLIT("father sister berzerker", "er", [true]), ['fath', ' sist', ' b', 'z', 'k']);
198-assertArrayEquals(SPLIT("father  sister   berzerker", "er", true), ['fath', '  sist', '   b', 'z', 'k']);
199-assertArrayEquals(SPLIT(["father sister berzerker"], ["er"], true), ['fath', ' sist', ' b', 'z', 'k']);
200+// Test F.DIST
201+assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, false), 0.0003451054686025578);
202+assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, true), 0.9980694465675269);
203+assertEquals(FDIST$LEFTTAILED(15.35, 7, 6, 1), 0.9980694465675269);
204+assertEquals(FDIST$LEFTTAILED(15.35, "7", [6], 1), 0.9980694465675269);
205+assertEquals(FDIST$LEFTTAILED(15.35, "7", [6], 10), 0.9980694465675269);
206 catchAndAssertEquals(function() {
207-  SPLIT([], "er");
208-}, ERRORS.REF_ERROR);
209+  FDIST$LEFTTAILED(15.35, 7, 6, "10");
210+}, ERRORS.VALUE_ERROR);
211+catchAndAssertEquals(function() {
212+  FDIST$LEFTTAILED(-15.35, 7, 6, 1);
213+}, ERRORS.NUM_ERROR);
214+catchAndAssertEquals(function() {
215+  FDIST$LEFTTAILED(15.35, 7, 6);
216+}, ERRORS.NA_ERROR);
217 catchAndAssertEquals(function() {
218-  SPLIT("er", "er", true, 10);
219+  FDIST$LEFTTAILED();
220 }, ERRORS.NA_ERROR);
221\ No newline at end of file
222diff --git a/tests/TextTest.ts b/tests/TextTest.ts
223new file mode 100644
224index 0000000..23ff056
225--- /dev/null
226+++ b/tests/TextTest.ts
227@@ -0,0 +1,111 @@
228+import {
229+  CONVERT
230+} from "../src/RawFormulas/RawFormulas";
231+import {
232+  ARABIC,
233+  CHAR,
234+  CODE,
235+  CONCATENATE,
236+  SPLIT
237+} from "../src/RawFormulas/Text";
238+import * as ERRORS from "../src/Errors";
239+import {
240+  assertEquals,
241+  assertArrayEquals,
242+  catchAndAssertEquals
243+} from "./utils/Asserts";
244+
245+
246+// Test SPLIT
247+assertArrayEquals(SPLIT("1,2,3", ","), ['1', '2', '3']);
248+assertArrayEquals(SPLIT("little kitty cat", "i"), ['l', 'ttle k', 'tty cat']);
249+assertArrayEquals(SPLIT("father sister berzerker", "er", true), ['fath', ' sist', ' b', 'z', 'k']);
250+assertArrayEquals(SPLIT("father sister berzerker", "er", [true]), ['fath', ' sist', ' b', 'z', 'k']);
251+assertArrayEquals(SPLIT("father  sister   berzerker", "er", true), ['fath', '  sist', '   b', 'z', 'k']);
252+assertArrayEquals(SPLIT(["father sister berzerker"], ["er"], true), ['fath', ' sist', ' b', 'z', 'k']);
253+catchAndAssertEquals(function() {
254+  SPLIT([], "er");
255+}, ERRORS.REF_ERROR);
256+catchAndAssertEquals(function() {
257+  SPLIT("er", "er", true, 10);
258+}, ERRORS.NA_ERROR);
259+
260+
261+// Test CHAR
262+assertEquals(CHAR(97), "a");
263+assertEquals(CHAR("97"), "a");
264+assertEquals(CHAR([97, "m"]), "a");
265+assertEquals(CHAR([[97], "m"]), "a");
266+catchAndAssertEquals(function() {
267+  CHAR([[], [97], "m"]);
268+}, ERRORS.REF_ERROR);
269+catchAndAssertEquals(function() {
270+  CHAR(false);
271+}, ERRORS.NUM_ERROR);
272+catchAndAssertEquals(function() {
273+  CHAR(10000000);
274+}, ERRORS.NUM_ERROR);
275+catchAndAssertEquals(function() {
276+  CHAR(0);
277+}, ERRORS.NUM_ERROR);
278+catchAndAssertEquals(function() {
279+  CHAR();
280+}, ERRORS.NA_ERROR);
281+
282+
283+// Test CODE
284+assertEquals(CODE('a'), 97);
285+assertEquals(CODE('aa'), 97);
286+assertEquals(CODE('aM'), 97);
287+assertEquals(CODE('#'), 35);
288+assertEquals(CODE(false), 70);
289+assertEquals(CODE(true), 84);
290+catchAndAssertEquals(function() {
291+  CODE();
292+}, ERRORS.NA_ERROR);
293+catchAndAssertEquals(function() {
294+  CODE("a", "m");
295+}, ERRORS.NA_ERROR);
296+catchAndAssertEquals(function() {
297+  CODE("");
298+}, ERRORS.VALUE_ERROR);
299+assertEquals(CODE(['a']), 97);
300+assertEquals(CODE([['a'], 'p']), 97);
301+
302+
303+// Test CONCATENATE
304+assertEquals(CONCATENATE("hey", " ", "there"), "hey there");
305+assertEquals(CONCATENATE(["hey", " ", "there"]), "hey there");
306+assertEquals(CONCATENATE("hey"), "hey");
307+assertEquals(CONCATENATE("hey", 2), "hey2");
308+assertEquals(CONCATENATE("hey", false), "heyFALSE");
309+assertEquals(CONCATENATE([22, 14, "m", false]), "2214mFALSE");
310+assertEquals(CONCATENATE([22, 14, ["m", false]]), "2214mFALSE");
311+catchAndAssertEquals(function() {
312+  CONCATENATE();
313+}, ERRORS.NA_ERROR);
314+catchAndAssertEquals(function() {
315+  CONCATENATE("10", 4, false, []);
316+}, ERRORS.REF_ERROR);
317+catchAndAssertEquals(function() {
318+  CONCATENATE([]);
319+}, ERRORS.REF_ERROR);
320+
321+
322+// Test CONVERT
323+assertEquals(CONVERT(5.1, "mm", "m"), 0.0050999999999999995);
324+
325+
326+// Test ARABIC
327+assertEquals(ARABIC("XIV"), 14);
328+assertEquals(ARABIC("M"), 1000);
329+assertEquals(ARABIC("-IV"), -4);
330+catchAndAssertEquals(function() {
331+  ARABIC("b");
332+}, ERRORS.VALUE_ERROR);
333+catchAndAssertEquals(function() {
334+  ARABIC(false);
335+}, ERRORS.VALUE_ERROR);
336+catchAndAssertEquals(function() {
337+  ARABIC(10);
338+}, ERRORS.VALUE_ERROR);
339\ No newline at end of file