spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ArgsChecker, Filter] adding tests
author
Ben Vogt <[email protected]>
date
2017-05-11 03:04:57
stats
17 file(s) changed, 112 insertions(+), 20 deletions(-)
files
README.md
src/Utilities/ArgsChecker.ts
tests/CellTest.ts
tests/Formulas/DateFormulasTest.ts
tests/Formulas/DateFormulasTestTimeOverride.ts
tests/Formulas/EngineeringTest.ts
tests/Formulas/FinancialTest.ts
tests/Formulas/LogicalTest.ts
tests/Formulas/MathTest.ts
tests/Formulas/StatisticalTest.ts
tests/Formulas/TextTest.ts
tests/SheetFormulaTest.ts
tests/SheetParseTest.ts
tests/SheetTest.ts
tests/Utilities/ArgsCheckerTest.ts
tests/Utilities/FilterTest.ts
tests/utils/Asserts.ts
tests/Utils/Asserts.ts
  1diff --git a/README.md b/README.md
  2index d3d9d9e..d0154ff 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -52,7 +52,8 @@ Right now we're just using the number of days since 1900, but we should check th
  6 
  7 
  8 ### Percentage inputs should be parsed to numbers
  9-Input like `10%` should be parsed and stored as a number.
 10+Input like `10%` should be parsed and stored as a number. It should be X*0.01, not X/100. For example `=2 * 1 * 10%` is
 11+0.2, while `=2 * 1 * 10/1` is 20.
 12 
 13 
 14 ### Sheet.ts and Helpers.ts should be check conversion capabilities in same way as TypeConverter
 15@@ -69,15 +70,9 @@ TypeConverter.
 16 ### Ensure all formulas are tested inside of SheetFormulaTest.ts
 17 
 18 
 19-### Test ArgsChecker
 20-
 21-
 22 ### Test CriteriaFunctionFactory
 23 
 24 
 25-### Test Filter
 26-
 27-
 28 ### Test Serilaizer
 29 
 30 
 31diff --git a/src/Utilities/ArgsChecker.ts b/src/Utilities/ArgsChecker.ts
 32index be90c76..d8c6c0d 100644
 33--- a/src/Utilities/ArgsChecker.ts
 34+++ b/src/Utilities/ArgsChecker.ts
 35@@ -24,7 +24,7 @@ class ArgsChecker {
 36    */
 37   static checkAtLeastLength(args: any, length: number) {
 38     if (args.length < length) {
 39-      throw new NAError("Wrong number of arguments to ___. Expected 1 arguments, but got " + args.length + " arguments.");
 40+      throw new NAError("Wrong number of arguments to ___. Expected " + length + " arguments, but got " + args.length + " arguments.");
 41     }
 42   }
 43 
 44diff --git a/tests/CellTest.ts b/tests/CellTest.ts
 45index 690d928..911b1a8 100644
 46--- a/tests/CellTest.ts
 47+++ b/tests/CellTest.ts
 48@@ -5,7 +5,7 @@ import {
 49   assertEquals,
 50   assertArrayEquals,
 51   test
 52-} from "./utils/Asserts";
 53+} from "./Utils/Asserts";
 54 
 55 test("Cell.constructor", function(){
 56   var cell = new Cell("A1");
 57diff --git a/tests/Formulas/DateFormulasTest.ts b/tests/Formulas/DateFormulasTest.ts
 58index 5b381bc..a6c49ba 100644
 59--- a/tests/Formulas/DateFormulasTest.ts
 60+++ b/tests/Formulas/DateFormulasTest.ts
 61@@ -27,7 +27,7 @@ import {
 62   assertEquals,
 63   catchAndAssertEquals,
 64   test
 65-} from "../utils/Asserts"
 66+} from "../Utils/Asserts"
 67 
 68 
 69 test("WORKDAY.INTL", function () {
 70diff --git a/tests/Formulas/DateFormulasTestTimeOverride.ts b/tests/Formulas/DateFormulasTestTimeOverride.ts
 71index 55c6945..b5c2ba9 100644
 72--- a/tests/Formulas/DateFormulasTestTimeOverride.ts
 73+++ b/tests/Formulas/DateFormulasTestTimeOverride.ts
 74@@ -8,7 +8,7 @@ import {
 75   assertEquals,
 76   catchAndAssertEquals,
 77   test
 78-} from "../utils/Asserts"
 79+} from "../Utils/Asserts"
 80 
 81 
 82 // WARNING: Locking in Date by overriding prototypes.
 83diff --git a/tests/Formulas/EngineeringTest.ts b/tests/Formulas/EngineeringTest.ts
 84index 773f705..521513d 100644
 85--- a/tests/Formulas/EngineeringTest.ts
 86+++ b/tests/Formulas/EngineeringTest.ts
 87@@ -12,7 +12,7 @@ import {
 88   assertEquals,
 89   catchAndAssertEquals,
 90   test
 91-} from "../utils/Asserts";
 92+} from "../Utils/Asserts";
 93 
 94 
 95 test("BIN2DEC", function(){
 96diff --git a/tests/Formulas/FinancialTest.ts b/tests/Formulas/FinancialTest.ts
 97index 6244a23..e9b6e41 100644
 98--- a/tests/Formulas/FinancialTest.ts
 99+++ b/tests/Formulas/FinancialTest.ts
100@@ -20,7 +20,7 @@ import {
101   assertEquals,
102   catchAndAssertEquals,
103   test
104-} from "../utils/Asserts";
105+} from "../Utils/Asserts";
106 
107 
108 test("ACCRINT", function(){
109diff --git a/tests/Formulas/LogicalTest.ts b/tests/Formulas/LogicalTest.ts
110index 40e7d71..e3ba392 100644
111--- a/tests/Formulas/LogicalTest.ts
112+++ b/tests/Formulas/LogicalTest.ts
113@@ -12,7 +12,7 @@ import {
114   assertEquals,
115   catchAndAssertEquals,
116   test
117-} from "../utils/Asserts";
118+} from "../Utils/Asserts";
119 
120 
121 test("AND", function(){
122diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
123index 4606a89..bd10cdb 100644
124--- a/tests/Formulas/MathTest.ts
125+++ b/tests/Formulas/MathTest.ts
126@@ -56,7 +56,7 @@ import {
127   assertEquals,
128   catchAndAssertEquals,
129   test
130-} from "../utils/Asserts";
131+} from "../Utils/Asserts";
132 
133 
134 test("ABS", function(){
135diff --git a/tests/Formulas/StatisticalTest.ts b/tests/Formulas/StatisticalTest.ts
136index 3b000fb..b9f2208 100644
137--- a/tests/Formulas/StatisticalTest.ts
138+++ b/tests/Formulas/StatisticalTest.ts
139@@ -24,7 +24,7 @@ import {
140   assertEquals,
141   catchAndAssertEquals,
142   test
143-} from "../utils/Asserts";
144+} from "../Utils/Asserts";
145 
146 
147 test("AVEDEV", function(){
148diff --git a/tests/Formulas/TextTest.ts b/tests/Formulas/TextTest.ts
149index 2534f5e..bc617da 100644
150--- a/tests/Formulas/TextTest.ts
151+++ b/tests/Formulas/TextTest.ts
152@@ -12,7 +12,7 @@ import {
153   assertArrayEquals,
154   catchAndAssertEquals,
155   test
156-} from "../utils/Asserts";
157+} from "../Utils/Asserts";
158 
159 
160 test("SPLIT", function(){
161diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
162index 26dbb19..1ded579 100644
163--- a/tests/SheetFormulaTest.ts
164+++ b/tests/SheetFormulaTest.ts
165@@ -4,7 +4,7 @@ import {
166 import {
167   assertEquals,
168   test
169-} from "./utils/Asserts";
170+} from "./Utils/Asserts";
171 import {DIV_ZERO_ERROR, VALUE_ERROR} from "../src/Errors";
172 
173 function assertFormulaEqualsError(formula: string, errorString: string) {
174diff --git a/tests/SheetParseTest.ts b/tests/SheetParseTest.ts
175index 272fd8b..60a4238 100644
176--- a/tests/SheetParseTest.ts
177+++ b/tests/SheetParseTest.ts
178@@ -4,7 +4,7 @@ import {
179 import {
180   assertEquals,
181   test
182-} from "./utils/Asserts";
183+} from "./Utils/Asserts";
184 
185 
186 test("Sheet parsing math formulas", function(){
187diff --git a/tests/SheetTest.ts b/tests/SheetTest.ts
188index d9b845e..fb4f419 100644
189--- a/tests/SheetTest.ts
190+++ b/tests/SheetTest.ts
191@@ -5,7 +5,7 @@ import {
192   assertEquals,
193   assertArrayEquals,
194   test
195-} from "./utils/Asserts";
196+} from "./Utils/Asserts";
197 import {
198   REF_ERROR,
199   NAME_ERROR
200diff --git a/tests/Utilities/ArgsCheckerTest.ts b/tests/Utilities/ArgsCheckerTest.ts
201new file mode 100644
202index 0000000..9c66105
203--- /dev/null
204+++ b/tests/Utilities/ArgsCheckerTest.ts
205@@ -0,0 +1,44 @@
206+import {
207+  assertEquals,
208+  catchAndAssertEquals,
209+  test
210+} from "../Utils/Asserts";
211+import {
212+  ArgsChecker
213+} from "../../src/Utilities/ArgsChecker";
214+import {NA_ERROR} from "../../src/Errors";
215+
216+
217+test("ArgsChecker.checkLength", function () {
218+  assertEquals(ArgsChecker.checkLength(["A", "B"], 2), undefined);
219+  assertEquals(ArgsChecker.checkLength(["A"], 1), undefined);
220+  assertEquals(ArgsChecker.checkLength([], 0), undefined);
221+  catchAndAssertEquals(function () {
222+    ArgsChecker.checkLength(["A", "B"], 100);
223+  }, NA_ERROR);
224+});
225+
226+
227+test("ArgsChecker.checkAtLeastLength", function () {
228+  assertEquals(ArgsChecker.checkAtLeastLength(["A", "B"], 2), undefined);
229+  assertEquals(ArgsChecker.checkAtLeastLength(["A", "B"], 1), undefined);
230+  assertEquals(ArgsChecker.checkAtLeastLength(["A"], 1), undefined);
231+  assertEquals(ArgsChecker.checkAtLeastLength(["A"], 0), undefined);
232+  assertEquals(ArgsChecker.checkAtLeastLength([], 0), undefined);
233+  catchAndAssertEquals(function () {
234+    ArgsChecker.checkAtLeastLength(["A", "B"], 3);
235+  }, NA_ERROR);
236+});
237+
238+
239+test("ArgsChecker.checkLengthWithin", function () {
240+  assertEquals(ArgsChecker.checkLengthWithin(["A", "B"], 2, 10), undefined);
241+  assertEquals(ArgsChecker.checkLengthWithin(["A", "B"], 1, 4), undefined);
242+  assertEquals(ArgsChecker.checkLengthWithin(["A", "B", "C", "D"], 1, 4), undefined);
243+  assertEquals(ArgsChecker.checkLengthWithin(["A", "B", "C", "D"], 1, 6), undefined);
244+  catchAndAssertEquals(function () {
245+    ArgsChecker.checkLengthWithin(["A", "B"], 3, 10);
246+    ArgsChecker.checkLengthWithin(["A", "B"], 5, 10);
247+    ArgsChecker.checkLengthWithin(["A", "B", "C", "D"], 5, 6);
248+  }, NA_ERROR);
249+});
250diff --git a/tests/Utilities/FilterTest.ts b/tests/Utilities/FilterTest.ts
251new file mode 100644
252index 0000000..4c97989
253--- /dev/null
254+++ b/tests/Utilities/FilterTest.ts
255@@ -0,0 +1,53 @@
256+import {
257+  catchAndAssertEquals,
258+  assertArrayEquals,
259+  test
260+} from "../Utils/Asserts";
261+import {
262+  Filter
263+} from "../../src/Utilities/Filter";
264+import {REF_ERROR} from "../../src/Errors";
265+
266+test("Filter.flatten", function () {
267+  assertArrayEquals(Filter.flatten([0, 1, 2, 3, [4, 5], [], [[]], [[[6]]], 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
268+  assertArrayEquals(Filter.flatten([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
269+  assertArrayEquals(Filter.flatten([0, 1, 2, 3, 4, 5, 6, undefined]), [0, 1, 2, 3, 4, 5, 6, undefined]);
270+});
271+
272+
273+test("Filter.filterOutNonNumberValues", function () {
274+  // TODO: This function seems to be questionable. Look at where it's used and if it can be made more specific.
275+  assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined]);
276+  assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
277+});
278+
279+
280+test("Filter.filterOutStringValues", function () {
281+  assertArrayEquals(Filter.filterOutStringValues([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined]);
282+  assertArrayEquals(Filter.filterOutStringValues([0, 1, 2, 3, "0", "dsadas"]), [0, 1, 2, 3]);
283+  assertArrayEquals(Filter.filterOutStringValues(["M", "0", "dsadas"]), []);
284+  assertArrayEquals(Filter.filterOutNonNumberValues([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
285+});
286+
287+
288+test("Filter.flattenAndThrow", function () {
289+  assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, [4, 5], [6], [[7]], [[[8]]], 9]), [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
290+  assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
291+  assertArrayEquals(Filter.flattenAndThrow([0, 1, 2, 3, 4, 5, 6, undefined]), [0, 1, 2, 3, 4, 5, 6, undefined]);
292+  catchAndAssertEquals(function () {
293+    Filter.flattenAndThrow([0, 1, 2, 3, [4, 5], [], [[]], [[[6]]], 7]);
294+  }, REF_ERROR);
295+  catchAndAssertEquals(function () {
296+    Filter.flattenAndThrow([[]])
297+  }, REF_ERROR);
298+});
299+
300+
301+test("Filter.stringValuesToZeros", function () {
302+  assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, undefined, "0"]), [0, 1, 2, 3, undefined, 0]);
303+  assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, "0", "dsadas"]), [0, 1, 2, 3, 0, 0]);
304+  assertArrayEquals(Filter.stringValuesToZeros(["M", "0", "dsadas"]), [0, 0, 0]);
305+  assertArrayEquals(Filter.stringValuesToZeros([0, 1, 2, 3, 4, 5, 6, 7]), [0, 1, 2, 3, 4, 5, 6, 7]);
306+});
307+
308+
309diff --git a/tests/utils/Asserts.ts b/tests/Utils/Asserts.ts
310similarity index 100%
311rename from tests/utils/Asserts.ts
312rename to tests/Utils/Asserts.ts