commit
message
Formulas.ISODD written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 03:37:07
stats
2 file(s) changed,
32 insertions(+),
0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index 40c4497..a9a5034 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -223,7 +223,23 @@ var ISEVEN = function (...values) : boolean {
6 return Math.floor(x) % 2 === 0;
7 };
8
9-var ISODD = Formula["ISODD"];
10+
11+/**
12+ * Checks whether the provided value is odd.
13+ * @param values[0] The value to be verified as odd.
14+ * @returns {boolean} whether this value is odd or not
15+ * @constructor
16+ */
17+var ISODD = function (...values) : boolean {
18+ checkArgumentsLength(values, 1);
19+ if (values[0] === "") {
20+ throw new CellError(ERRORS.VALUE_ERROR, "Function ISODD 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 === 1;
24+};
25+
26+
27 var LN = Formula["LN"];
28 var LOG = Formula["LOG"];
29 var LOG10 = Formula["LOG10"];
30diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
31index 35750b2..2bcd2e8 100644
32--- a/tests/FormulasTest.ts
33+++ b/tests/FormulasTest.ts
34@@ -612,7 +612,22 @@ catchAndAssertEquals(function() {
35 }, ERRORS.VALUE_ERROR);
36
37
38+// Test ISODD
39+assertEquals(ISODD(4), false);
40 assertEquals(ISODD(3), true);
41+assertEquals(ISODD(4.1), false);
42+assertEquals(ISODD(false), false);
43+assertEquals(ISODD(true), true);
44+assertEquals(ISODD([4]), false);
45+catchAndAssertEquals(function() {
46+ ISODD(100, 10);
47+}, ERRORS.NA_ERROR);
48+catchAndAssertEquals(function() {
49+ ISODD();
50+}, ERRORS.NA_ERROR);
51+catchAndAssertEquals(function() {
52+ ISODD("");
53+}, ERRORS.VALUE_ERROR);
54
55 assertEquals(LN(100), 4.605170185988092);
56