spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Cleaning up some of the testing functions.
author
Ben Vogt <[email protected]>
date
2017-04-01 02:02:00
stats
3 file(s) changed, 49 insertions(+), 18 deletions(-)
files
tests/DateFormulasTest.ts
tests/FormulasTest.ts
tests/utils/Asserts.ts
  1diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
  2index 44d2964..b5b2e76 100644
  3--- a/tests/DateFormulasTest.ts
  4+++ b/tests/DateFormulasTest.ts
  5@@ -44,7 +44,7 @@ assertEquals(DATE(-1900, 1, 1).toNumber(), 2);
  6 
  7 
  8 // Test DATEVALUE
  9-// MM/DD/YYYY
 10+// YEAR_MONTHDIG_DAY, YYYY(fd)MM(fd)DD =================================================================================
 11 assertEquals(DATEVALUE("6/24/92"), 33779);
 12 assertEquals(DATEVALUE("6/24/1992"), 33779);
 13 assertEquals(DATEVALUE("06/24/1992"), 33779);
 14@@ -84,7 +84,7 @@ assertEquals(DATEVALUE("12/31/100"), -657070);
 15 assertEquals(DATEVALUE("11/10/122"), -649086);
 16 assertEquals(DATEVALUE("1/22/2222"), 117631);
 17 assertEquals(DATEVALUE("1/22/222"), -612854);
 18-// MM/DD/YYYY delimiter tests
 19+// delimiter tests
 20 assertEquals(DATEVALUE("6-24-92"), 33779);
 21 assertEquals(DATEVALUE("6/24/92"), 33779);
 22 assertEquals(DATEVALUE("6 24 92"), 33779);
 23@@ -92,7 +92,22 @@ assertEquals(DATEVALUE("6.24.92"), 33779);
 24 assertEquals(DATEVALUE("6 . 24 . 92"), 33779);
 25 assertEquals(DATEVALUE("6 / 24 / 92"), 33779);
 26 assertEquals(DATEVALUE("6, 24, 92"), 33779);
 27-// YYYY/MM/DD
 28+// flex delimiter should not allow a comma without a space after it.
 29+catchAndAssertEquals(function() {
 30+  DATEVALUE("Sunday,6/24/92");
 31+}, ERRORS.VALUE_ERROR);
 32+// Leap day on non-leap years
 33+catchAndAssertEquals(function() {
 34+  DATEVALUE("2/29/2005");
 35+}, ERRORS.VALUE_ERROR);
 36+catchAndAssertEquals(function() {
 37+  DATEVALUE("2/29/2001");
 38+}, ERRORS.VALUE_ERROR);
 39+// Out of range day for any month
 40+catchAndAssertEquals(function() {
 41+  DATEVALUE("1/44/2005");
 42+}, ERRORS.VALUE_ERROR);
 43+// MONTHDIG_DAY_YEAR, MM(fd)DD(fd)YYYY =================================================================================
 44 assertEquals(DATEVALUE("1992/6/24"), 33779);
 45 assertEquals(DATEVALUE("1992/06/24"), 33779);
 46 assertEquals(DATEVALUE("1999/1/01"), 36161);
 47@@ -143,7 +158,7 @@ assertEquals(DATEVALUE("Thu 1992/6/24"), 33779);
 48 assertEquals(DATEVALUE("Fri 1992/6/24"), 33779);
 49 assertEquals(DATEVALUE("Sat 1992/6/24"), 33779);
 50 assertEquals(DATEVALUE("Sunday, 1992/6/24"), 33779);
 51-// YYYY/MM/DD delimiter tests
 52+// delimiter tests
 53 assertEquals(DATEVALUE("1992-6-24"), 33779);
 54 assertEquals(DATEVALUE("1992/6/24"), 33779);
 55 assertEquals(DATEVALUE("1992 6 24"), 33779);
 56@@ -151,16 +166,22 @@ assertEquals(DATEVALUE("1992 6 24"), 33779);
 57 assertEquals(DATEVALUE("1992 . 6 . 24"), 33779);
 58 assertEquals(DATEVALUE("1992 / 6 / 24"), 33779);
 59 assertEquals(DATEVALUE("1992, 6, 24"), 33779);
 60+// flex delimiter should not allow a comma without a space after it.
 61+catchAndAssertEquals(function() {
 62+  DATEVALUE("Sunday,1992/6/24");
 63+}, ERRORS.VALUE_ERROR);
 64+// Leap day on non-leap years
 65 catchAndAssertEquals(function() {
 66-  DATEVALUE("Sunday,1992/6/24");// flex delimiter should not allow a comma without a space after it.
 67+  DATEVALUE("2005/2/29");
 68 }, ERRORS.VALUE_ERROR);
 69 catchAndAssertEquals(function() {
 70-  DATEVALUE("2005/2/29");// Leap day on non-leap year.
 71+  DATEVALUE("2001/2/29");
 72 }, ERRORS.VALUE_ERROR);
 73+// Out of range day for any month
 74 catchAndAssertEquals(function() {
 75-  DATEVALUE("2005/1/44");// Out of range day for any month
 76+  DATEVALUE("2005/1/44");
 77 }, ERRORS.VALUE_ERROR);
 78-// DD/Month/YYYY
 79+// DAY_MONTHNAME_YEAR, DD(fd)Month(fd)YYYY =============================================================================
 80 assertEquals(DATEVALUE("Sun 09 Feb 2017"), 42775);
 81 assertEquals(DATEVALUE("Sun 9 Feb 2017"), 42775);
 82 assertEquals(DATEVALUE("Mon 09 Feb 2017"), 42775);
 83@@ -185,6 +206,7 @@ assertEquals(DATEVALUE("13 January 0099"), 36173);
 84 assertEquals(DATEVALUE("13 January 0000"), 36538);
 85 assertEquals(DATEVALUE("13 January 0101"), -657057);
 86 assertEquals(DATEVALUE("13 January 0100"), -657422);
 87+// delimiter tests
 88 assertEquals(DATEVALUE("Sun, 09, Feb, 2017"), 42775);
 89 assertEquals(DATEVALUE("Sun, 09/Feb/2017"), 42775);
 90 assertEquals(DATEVALUE("09/Feb/2017"), 42775);
 91@@ -192,8 +214,13 @@ assertEquals(DATEVALUE("09-Feb-2017"), 42775);
 92 assertEquals(DATEVALUE("09.Feb.2017"), 42775);
 93 assertEquals(DATEVALUE("09 Feb/2017"), 42775);
 94 assertEquals(DATEVALUE("09 . Feb . 2017"), 42775);
 95+// If the delimiters don't match the first one should be a space.
 96+catchAndAssertEquals(function() {
 97+  DATEVALUE("09.Feb/2017");
 98+}, ERRORS.VALUE_ERROR);
 99+// Comma delimiters should be followed by spaces.
100 catchAndAssertEquals(function() {
101-  DATEVALUE("09.Feb/2017"); // If the delimiters don't match the first one should be a space.
102+  DATEVALUE("09,Feb,2017");
103 }, ERRORS.VALUE_ERROR);
104 
105 
106diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
107index 09ebb43..bd1cfdf 100644
108--- a/tests/FormulasTest.ts
109+++ b/tests/FormulasTest.ts
110@@ -1,5 +1,3 @@
111-/// <reference path="../node_modules/moment/moment.d.ts"/>
112-import * as moment from "moment";
113 import { ABS, ACCRINT, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2, ATANH, AVEDEV, AVERAGE,
114     AVERAGEA, AVERAGEIF, BIN2DEC, BIN2HEX, BIN2OCT, CEILING,
115     CHAR, CODE, COMBIN, CONCATENATE, CONVERT, PEARSON,
116@@ -11,7 +9,7 @@ import { ABS, ACCRINT, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2
117     POWER, ROUND, ROUNDDOWN, ROUNDUP, SIN, SINH, SPLIT, SQRT, SQRTPI, SUM, SUMIF, SUMPRODUCT, RADIANS,
118     SUMSQ, SUMX2MY2, SUMX2PY2, TAN, TANH, TRUNC, XOR, YEARFRAC } from "../src/RawFormulas/RawFormulas"
119 import * as ERRORS from "../src/Errors"
120-import {assertEquals, assertEqualsDates, assertArrayEquals} from "./utils/Asserts"
121+import {assertEquals, assertArrayEquals} from "./utils/Asserts"
122 
123 function catchAndAssertEquals(toExecute, expected) {
124   var toThrow = null;
125diff --git a/tests/utils/Asserts.ts b/tests/utils/Asserts.ts
126index c1c6623..dc681fd 100644
127--- a/tests/utils/Asserts.ts
128+++ b/tests/utils/Asserts.ts
129@@ -1,3 +1,8 @@
130+/**
131+ * Assert two params are equal using strict equality testing.
132+ * @param actual value
133+ * @param expected value
134+ */
135 function assertEquals(actual, expected) {
136   if (expected !== actual) {
137     console.log("expected:", expected, " actual:", actual);
138@@ -5,6 +10,11 @@ function assertEquals(actual, expected) {
139   }
140 }
141 
142+/**
143+ * Assert two arrays are equal using strict equality testing on individual items.
144+ * @param actual value
145+ * @param expected value
146+ */
147 function assertArrayEquals(actual: Array<any>, expected: Array<any>, ) {
148   if (expected.length != actual.length) {
149     console.log("expected: ", expected, " actual:", actual);
150@@ -18,12 +28,7 @@ function assertArrayEquals(actual: Array<any>, expected: Array<any>, ) {
151   }
152 }
153 
154-function assertEqualsDates(one: Date, expectation: Date) {
155-  assertEquals(one.getTime(), expectation.getTime());
156-}
157-
158 export {
159   assertEquals,
160-  assertArrayEquals,
161-  assertEqualsDates
162+  assertArrayEquals
163 }
164\ No newline at end of file