spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Logical] Breaking out Logcial.ts tests into seperate file
author
Ben Vogt <[email protected]>
date
2017-04-29 21:52:46
stats
2 file(s) changed, 161 insertions(+), 148 deletions(-)
files
tests/FormulasTest.ts
tests/LogicalTest.ts
  1diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
  2index 305b4cf..3099102 100644
  3--- a/tests/FormulasTest.ts
  4+++ b/tests/FormulasTest.ts
  5@@ -1,13 +1,12 @@
  6-import { ABS, ACCRINT, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2, ATANH, AVEDEV, AVERAGE,
  7+import { ABS, ACOS, ACOSH, ACOTH, ARABIC, ASIN, ASINH, ATAN, ATAN2, ATANH, AVEDEV, AVERAGE,
  8     AVERAGEA, AVERAGEIF, CEILING,
  9     CHAR, CODE, COMBIN, CONCATENATE, CONVERT, PEARSON,
 10     CORREL, COS, PI, COSH, COT, COTH, COUNT, COUNTA, COUNTIF, COUNTIFS, COUNTUNIQUE,
 11-    CUMIPMT, CUMPRINC,
 12-    DB, DDB, DEGREES, DEVSQ, DOLLAR, DOLLARDE, DOLLARFR,
 13-    EFFECT, ERF, ERFC, EVEN, EXACT, EXPONDIST, FINV, FALSE, FLOOR, __COMPLEX, FISHER, FISHERINV, IF,
 14-    INT, ISEVEN, ISODD, LN, LOG, LOG10, MAX, MAXA, MEDIAN, MIN, MINA, MOD, NOT, TRUE, ODD, OR,
 15+    DEGREES, DEVSQ,
 16+    ERF, ERFC, EVEN, EXPONDIST, FINV, FLOOR, __COMPLEX, FISHER, FISHERINV, IF,
 17+    INT, ISEVEN, ISODD, LN, LOG, LOG10, MAX, MAXA, MEDIAN, MIN, MINA, MOD, ODD,
 18     POWER, ROUND, ROUNDDOWN, ROUNDUP, SIN, SINH, SPLIT, SQRT, SQRTPI, SUM, SUMIF, SUMPRODUCT, RADIANS,
 19-    SUMSQ, SUMX2MY2, SUMX2PY2, TAN, TANH, TRUNC, XOR, DATE } from "../src/RawFormulas/RawFormulas"
 20+    SUMSQ, SUMX2MY2, SUMX2PY2, TAN, TANH, TRUNC } from "../src/RawFormulas/RawFormulas";
 21 import * as ERRORS from "../src/Errors"
 22 import {assertEquals, assertArrayEquals} from "./utils/Asserts"
 23 
 24@@ -84,27 +83,6 @@ catchAndAssertEquals(function() {
 25 }, ERRORS.NUM_ERROR);
 26 
 27 
 28-// Test AND
 29-assertEquals(AND(10, 10), true);
 30-assertEquals(AND(10, 0), false);
 31-assertEquals(AND(10, false), false);
 32-assertEquals(AND(0, 0), false);
 33-catchAndAssertEquals(function() {
 34-  AND(1, "");
 35-}, ERRORS.VALUE_ERROR);
 36-catchAndAssertEquals(function() {
 37-  AND();
 38-}, ERRORS.NA_ERROR);
 39-catchAndAssertEquals(function() {
 40-  AND(1, "str");
 41-}, ERRORS.VALUE_ERROR);
 42-assertEquals(AND(0, [1, 1]), false);
 43-assertEquals(AND(1, [1, 1]), true);
 44-catchAndAssertEquals(function() {
 45-  AND(1, [1, "str"]);
 46-}, ERRORS.VALUE_ERROR);
 47-
 48-
 49 // Test ARABIC
 50 assertEquals(ARABIC("XIV"), 14);
 51 assertEquals(ARABIC("M"), 1000);
 52@@ -674,10 +652,6 @@ catchAndAssertEquals(function() {
 53 }, ERRORS.REF_ERROR);
 54 
 55 
 56-// Test AND
 57-assertEquals(AND(10), true);
 58-
 59-
 60 // Test ERF
 61 assertEquals(ERF(2), 0.9953222650189527);
 62 assertEquals(ERF("2"), 0.9953222650189527);
 63@@ -730,32 +704,6 @@ catchAndAssertEquals(function() {
 64   EVEN("str");
 65 }, ERRORS.VALUE_ERROR);
 66 
 67-// Test EXACT
 68-assertEquals(EXACT("m", "M"), false);
 69-assertEquals(EXACT("m", "m"), true);
 70-assertEquals(EXACT("m", false), false);
 71-assertEquals(EXACT(false, false), true);
 72-assertEquals(EXACT(10, 10), true);
 73-assertEquals(EXACT(10, "10"), true);
 74-assertEquals(EXACT(10, "str"), false);
 75-assertEquals(EXACT([10], [10]), true);
 76-assertEquals(EXACT(["str"], [10, 22]), false);
 77-catchAndAssertEquals(function() {
 78-  EXACT([], []);
 79-}, ERRORS.REF_ERROR);
 80-catchAndAssertEquals(function() {
 81-  EXACT([]);
 82-}, ERRORS.NA_ERROR);
 83-catchAndAssertEquals(function() {
 84-  EXACT("m");
 85-}, ERRORS.NA_ERROR);
 86-catchAndAssertEquals(function() {
 87-  EXACT(10, 10, 10);
 88-}, ERRORS.NA_ERROR);
 89-catchAndAssertEquals(function() {
 90-  EXACT(false);
 91-}, ERRORS.NA_ERROR);
 92-
 93 
 94 // Test EXPONDIST
 95 assertEquals(EXPONDIST(4, 0.5, false), 0.06766764161830635);
 96@@ -781,10 +729,6 @@ catchAndAssertEquals(function() {
 97 }, ERRORS.NA_ERROR);
 98 
 99 
100-// Test FALSE
101-assertEquals(FALSE(), false);
102-
103-
104 // Test F.DIST
105 assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, false), 0.0003451054686025578);
106 assertEquals(__COMPLEX["F.DIST"](15.35, 7, 6, true), 0.9980694465675269);
107@@ -1121,44 +1065,6 @@ assertEquals(MOD(10.1, 3), 1.0999999999999996);
108 assertEquals(MOD(10, 3.1), 0.6999999999999997);
109 
110 
111-// Test NOT
112-assertEquals(NOT(TRUE()), false);
113-assertEquals(NOT(""), true);
114-catchAndAssertEquals(function() {
115-  NOT(" ");
116-}, ERRORS.VALUE_ERROR);
117-assertEquals(NOT(100), false);
118-assertEquals(NOT(0), true);
119-assertEquals(NOT(-1), false);
120-assertEquals(NOT(1), false);
121-catchAndAssertEquals(function() {
122-  NOT("0");
123-}, ERRORS.VALUE_ERROR);
124-catchAndAssertEquals(function() {
125-  NOT([]);
126-}, ERRORS.REF_ERROR);
127-assertEquals(NOT([10]), false);
128-assertEquals(NOT([0, 0]), true);
129-assertEquals(NOT([0, false]), true);
130-assertEquals(NOT([false, 0]), true);
131-assertEquals(NOT([10, "str"]), false);
132-catchAndAssertEquals(function() {
133-  NOT("str");
134-}, ERRORS.VALUE_ERROR);
135-assertEquals(NOT([""]), true);
136-assertEquals(NOT([0]), true);
137-assertEquals(NOT([1]), false);
138-assertEquals(NOT([0, 1]), true);
139-catchAndAssertEquals(function() {
140-  NOT("1.2");
141-}, ERRORS.VALUE_ERROR);
142-catchAndAssertEquals(function() {
143-  NOT();
144-}, ERRORS.NA_ERROR);
145-catchAndAssertEquals(function() {
146-  NOT(false, false);
147-}, ERRORS.NA_ERROR);
148-
149 
150 // Test ODD
151 assertEquals(ODD(2), 3);
152@@ -1180,31 +1086,7 @@ catchAndAssertEquals(function() {
153 }, ERRORS.VALUE_ERROR);
154 
155 
156-// Test OR
157-assertEquals(OR(true, false), true);
158-assertEquals(OR(false, false), false);
159-assertEquals(OR(1, 0), true);
160-assertEquals(OR([1, 0]), true);
161-assertEquals(OR(false, 0, -10), true);
162-assertEquals(OR([false, 0, -10]), true);
163-assertEquals(OR([false, 0, [-10]]), true);
164-catchAndAssertEquals(function() {
165-  OR([false, 0, []]);
166-}, ERRORS.REF_ERROR);
167-catchAndAssertEquals(function() {
168-  OR(false, "d");
169-}, ERRORS.VALUE_ERROR);
170-catchAndAssertEquals(function() {
171-  OR(false, "10");
172-}, ERRORS.VALUE_ERROR);
173-catchAndAssertEquals(function() {
174-  OR(false, "1.1");
175-}, ERRORS.VALUE_ERROR);
176-catchAndAssertEquals(function() {
177-  OR();
178-}, ERRORS.NA_ERROR);
179-
180-
181+// Test PI
182 assertEquals(PI(), 3.141592653589793);
183 
184 
185@@ -1573,10 +1455,6 @@ assertEquals(TANH([1, 44]), 0.7615941559557649);
186 assertEquals(TANH([1, "str"]), 0.7615941559557649);
187 
188 
189-// Test TRUE
190-assertEquals(TRUE(), true);
191-
192-
193 // Test TRUNC
194 assertEquals(TRUNC(PI(), 2), 3.14);
195 assertEquals(TRUNC("3.141592653589793", "2"), 3.14);
196@@ -1594,24 +1472,3 @@ catchAndAssertEquals(function() {
197 catchAndAssertEquals(function() {
198   TRUNC(3.1, 1, 1);
199 }, ERRORS.NA_ERROR);
200-
201-
202-// Test XOR
203-assertEquals(XOR(1, 1), false);
204-assertEquals(XOR(1, 0), true);
205-assertEquals(XOR(0, 0, 0), false);
206-assertEquals(XOR(0, 0, 1), true);
207-assertEquals(XOR(0, 0, [0, 0, 1]), true);
208-assertEquals(XOR(0, 1, [0, 0, 1]), false);
209-catchAndAssertEquals(function() {
210-  XOR("str");
211-}, ERRORS.VALUE_ERROR);
212-catchAndAssertEquals(function() {
213-  XOR();
214-}, ERRORS.NA_ERROR);
215-catchAndAssertEquals(function() {
216-  XOR(1, []);
217-}, ERRORS.REF_ERROR);
218-catchAndAssertEquals(function() {
219-  XOR([]);
220-}, ERRORS.REF_ERROR);
221diff --git a/tests/LogicalTest.ts b/tests/LogicalTest.ts
222new file mode 100644
223index 0000000..05ae802
224--- /dev/null
225+++ b/tests/LogicalTest.ts
226@@ -0,0 +1,156 @@
227+import {
228+  AND,
229+  EXACT,
230+  TRUE,
231+  FALSE,
232+  NOT,
233+  OR,
234+  XOR
235+} from "../src/RawFormulas/Logical";
236+import * as ERRORS from "../src/Errors"
237+import {
238+  assertEquals,
239+  catchAndAssertEquals
240+} from "./utils/Asserts";
241+
242+
243+// Test AND
244+assertEquals(AND(10), true);
245+assertEquals(AND(10, 10), true);
246+assertEquals(AND(10, 0), false);
247+assertEquals(AND(10, false), false);
248+assertEquals(AND(0, 0), false);
249+catchAndAssertEquals(function() {
250+  AND(1, "");
251+}, ERRORS.VALUE_ERROR);
252+catchAndAssertEquals(function() {
253+  AND();
254+}, ERRORS.NA_ERROR);
255+catchAndAssertEquals(function() {
256+  AND(1, "str");
257+}, ERRORS.VALUE_ERROR);
258+assertEquals(AND(0, [1, 1]), false);
259+assertEquals(AND(1, [1, 1]), true);
260+catchAndAssertEquals(function() {
261+  AND(1, [1, "str"]);
262+}, ERRORS.VALUE_ERROR);
263+
264+
265+// Test EXACT
266+assertEquals(EXACT("m", "M"), false);
267+assertEquals(EXACT("m", "m"), true);
268+assertEquals(EXACT("m", false), false);
269+assertEquals(EXACT(false, false), true);
270+assertEquals(EXACT(10, 10), true);
271+assertEquals(EXACT(10, "10"), true);
272+assertEquals(EXACT(10, "str"), false);
273+assertEquals(EXACT([10], [10]), true);
274+assertEquals(EXACT(["str"], [10, 22]), false);
275+catchAndAssertEquals(function() {
276+  EXACT([], []);
277+}, ERRORS.REF_ERROR);
278+catchAndAssertEquals(function() {
279+  EXACT([]);
280+}, ERRORS.NA_ERROR);
281+catchAndAssertEquals(function() {
282+  EXACT("m");
283+}, ERRORS.NA_ERROR);
284+catchAndAssertEquals(function() {
285+  EXACT(10, 10, 10);
286+}, ERRORS.NA_ERROR);
287+catchAndAssertEquals(function() {
288+  EXACT(false);
289+}, ERRORS.NA_ERROR);
290+
291+
292+// Test TRUE
293+assertEquals(TRUE(), true);
294+
295+
296+// Test FALSE
297+assertEquals(FALSE(), false);
298+
299+
300+// Test NOT
301+assertEquals(NOT(TRUE()), false);
302+assertEquals(NOT(""), true);
303+catchAndAssertEquals(function() {
304+  NOT(" ");
305+}, ERRORS.VALUE_ERROR);
306+assertEquals(NOT(100), false);
307+assertEquals(NOT(0), true);
308+assertEquals(NOT(-1), false);
309+assertEquals(NOT(1), false);
310+catchAndAssertEquals(function() {
311+  NOT("0");
312+}, ERRORS.VALUE_ERROR);
313+catchAndAssertEquals(function() {
314+  NOT([]);
315+}, ERRORS.REF_ERROR);
316+assertEquals(NOT([10]), false);
317+assertEquals(NOT([0, 0]), true);
318+assertEquals(NOT([0, false]), true);
319+assertEquals(NOT([false, 0]), true);
320+assertEquals(NOT([10, "str"]), false);
321+catchAndAssertEquals(function() {
322+  NOT("str");
323+}, ERRORS.VALUE_ERROR);
324+assertEquals(NOT([""]), true);
325+assertEquals(NOT([0]), true);
326+assertEquals(NOT([1]), false);
327+assertEquals(NOT([0, 1]), true);
328+catchAndAssertEquals(function() {
329+  NOT("1.2");
330+}, ERRORS.VALUE_ERROR);
331+catchAndAssertEquals(function() {
332+  NOT();
333+}, ERRORS.NA_ERROR);
334+catchAndAssertEquals(function() {
335+  NOT(false, false);
336+}, ERRORS.NA_ERROR);
337+
338+
339+// Test OR
340+assertEquals(OR(true, false), true);
341+assertEquals(OR(false, false), false);
342+assertEquals(OR(1, 0), true);
343+assertEquals(OR([1, 0]), true);
344+assertEquals(OR(false, 0, -10), true);
345+assertEquals(OR([false, 0, -10]), true);
346+assertEquals(OR([false, 0, [-10]]), true);
347+catchAndAssertEquals(function() {
348+  OR([false, 0, []]);
349+}, ERRORS.REF_ERROR);
350+catchAndAssertEquals(function() {
351+  OR(false, "d");
352+}, ERRORS.VALUE_ERROR);
353+catchAndAssertEquals(function() {
354+  OR(false, "10");
355+}, ERRORS.VALUE_ERROR);
356+catchAndAssertEquals(function() {
357+  OR(false, "1.1");
358+}, ERRORS.VALUE_ERROR);
359+catchAndAssertEquals(function() {
360+  OR();
361+}, ERRORS.NA_ERROR);
362+
363+
364+// Test XOR
365+assertEquals(XOR(1, 1), false);
366+assertEquals(XOR(1, 0), true);
367+assertEquals(XOR(0, 0, 0), false);
368+assertEquals(XOR(0, 0, 1), true);
369+assertEquals(XOR(0, 0, [0, 0, 1]), true);
370+assertEquals(XOR(0, 1, [0, 0, 1]), false);
371+catchAndAssertEquals(function() {
372+  XOR("str");
373+}, ERRORS.VALUE_ERROR);
374+catchAndAssertEquals(function() {
375+  XOR();
376+}, ERRORS.NA_ERROR);
377+catchAndAssertEquals(function() {
378+  XOR(1, []);
379+}, ERRORS.REF_ERROR);
380+catchAndAssertEquals(function() {
381+  XOR([]);
382+}, ERRORS.REF_ERROR);
383\ No newline at end of file