spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Formulas.ISEVEN written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 03:34:57
stats
2 file(s) changed, 32 insertions(+), 2 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
 1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 2index 7b879d6..40c4497 100644
 3--- a/src/RawFormulas/RawFormulas.ts
 4+++ b/src/RawFormulas/RawFormulas.ts
 5@@ -207,7 +207,22 @@ var INT = function (...values) : number {
 6   return Math.floor(x);
 7 };
 8 
 9-var ISEVEN = Formula["ISEVEN"];
10+
11+/**
12+ * Checks whether the provided value is even.
13+ * @param values[0] The value to be verified as even.
14+ * @returns {boolean} whether this value is even or not
15+ * @constructor
16+ */
17+var ISEVEN = function (...values) : boolean {
18+  checkArgumentsLength(values, 1);
19+  if (values[0] === "") {
20+    throw new CellError(ERRORS.VALUE_ERROR, "Function ISEVEN parameter 1 expects boolean values. But '" + values[0] + "' is a text and cannot be coerced to a boolean.")
21+  }
22+  var x = firstValueAsNumber(values[0]);
23+  return Math.floor(x) % 2 === 0;
24+};
25+
26 var ISODD = Formula["ISODD"];
27 var LN = Formula["LN"];
28 var LOG = Formula["LOG"];
29diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
30index b41400e..35750b2 100644
31--- a/tests/FormulasTest.ts
32+++ b/tests/FormulasTest.ts
33@@ -594,8 +594,23 @@ catchAndAssertEquals(function() {
34 }, ERRORS.VALUE_ERROR);
35 
36 
37-
38+// Test ISEVEN
39 assertEquals(ISEVEN(4), true);
40+assertEquals(ISEVEN(3), false);
41+assertEquals(ISEVEN(4.1), true);
42+assertEquals(ISEVEN(false), true);
43+assertEquals(ISEVEN(true), false);
44+assertEquals(ISEVEN([4]), true);
45+catchAndAssertEquals(function() {
46+  ISEVEN(100, 10);
47+}, ERRORS.NA_ERROR);
48+catchAndAssertEquals(function() {
49+  ISEVEN();
50+}, ERRORS.NA_ERROR);
51+catchAndAssertEquals(function() {
52+  ISEVEN("");
53+}, ERRORS.VALUE_ERROR);
54+
55 
56 assertEquals(ISODD(3), true);
57