spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[EQ] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-05-25 03:55:17
stats
8 file(s) changed, 71 insertions(+), 6 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Math.js
src/Formulas/AllFormulas.ts
src/Formulas/Math.ts
tests/Formulas/MathTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 72ddb0a..0ceeead 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -908,6 +908,16 @@
  6 @constructor
  7 ```
  8 
  9+### EQ 
 10+
 11+```
 12+  Returns true if two specified values are equal and true otherwise. Equivalent to the "=" operator. 
 13+@param one - First value to check. 
 14+@param two - Second value to check. 
 15+@returns {boolean} true if values are equal, false if they are not equal. 
 16+@constructor
 17+```
 18+
 19 ### DIVIDE 
 20 
 21 ```
 22diff --git a/TODO.md b/TODO.md
 23index ffe3d3b..5690bca 100644
 24--- a/TODO.md
 25+++ b/TODO.md
 26@@ -56,7 +56,6 @@ For example 64 tbs to a qt.
 27 * QUOTIENT
 28 * SERIESSUM
 29 * SUBTOTAL
 30-* EQ
 31 * GT
 32 * GTE
 33 * LT
 34diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 35index e1bf23b..abab0f6 100644
 36--- a/dist/Formulas/AllFormulas.js
 37+++ b/dist/Formulas/AllFormulas.js
 38@@ -58,6 +58,7 @@ exports.RAND = Math_1.RAND;
 39 exports.RANDBETWEEN = Math_1.RANDBETWEEN;
 40 exports.SIGN = Math_1.SIGN;
 41 exports.DIVIDE = Math_1.DIVIDE;
 42+exports.EQ = Math_1.EQ;
 43 var Logical_1 = require("./Logical");
 44 exports.AND = Logical_1.AND;
 45 exports.EXACT = Logical_1.EXACT;
 46diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
 47index d5df9dd..b8bb5e5 100644
 48--- a/dist/Formulas/Math.js
 49+++ b/dist/Formulas/Math.js
 50@@ -768,6 +768,20 @@ var MINUS = function (one, two) {
 51     return x - y;
 52 };
 53 exports.MINUS = MINUS;
 54+/**
 55+ * Returns true if two specified values are equal and true otherwise. Equivalent to the "=" operator.
 56+ * @param one - First value to check.
 57+ * @param two - Second value to check.
 58+ * @returns {boolean} true if values are equal, false if they are not equal.
 59+ * @constructor
 60+ */
 61+var EQ = function (one, two) {
 62+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "EQ");
 63+    var x = TypeConverter_1.TypeConverter.firstValue(one);
 64+    var y = TypeConverter_1.TypeConverter.firstValue(two);
 65+    return x === y;
 66+};
 67+exports.EQ = EQ;
 68 /**
 69  * Returns one number divided by another. Equivalent to the `/` operator.
 70  * @param dividend - The number to be divided.
 71diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 72index 560838e..15b0c66 100644
 73--- a/src/Formulas/AllFormulas.ts
 74+++ b/src/Formulas/AllFormulas.ts
 75@@ -55,7 +55,8 @@ import {
 76   RAND,
 77   RANDBETWEEN,
 78   SIGN,
 79-  DIVIDE
 80+  DIVIDE,
 81+  EQ
 82 } from "./Math";
 83 import {
 84   AND,
 85@@ -279,5 +280,6 @@ export {
 86   RAND,
 87   RANDBETWEEN,
 88   SIGN,
 89-  DIVIDE
 90+  DIVIDE,
 91+  EQ
 92 }
 93\ No newline at end of file
 94diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
 95index d179daa..b223208 100644
 96--- a/src/Formulas/Math.ts
 97+++ b/src/Formulas/Math.ts
 98@@ -776,6 +776,21 @@ var MINUS = function (one, two) {
 99 };
100 
101 
102+/**
103+ * Returns true if two specified values are equal and true otherwise. Equivalent to the "=" operator.
104+ * @param one - First value to check.
105+ * @param two - Second value to check.
106+ * @returns {boolean} true if values are equal, false if they are not equal.
107+ * @constructor
108+ */
109+var EQ = function (one, two) {
110+  ArgsChecker.checkLength(arguments, 2, "EQ");
111+  var x = TypeConverter.firstValue(one);
112+  var y = TypeConverter.firstValue(two);
113+  return x === y;
114+};
115+
116+
117 /**
118  * Returns one number divided by another. Equivalent to the `/` operator.
119  * @param dividend - The number to be divided.
120@@ -1141,5 +1156,6 @@ export {
121   RAND,
122   RANDBETWEEN,
123   SIGN,
124-  DIVIDE
125+  DIVIDE,
126+  EQ
127 }
128\ No newline at end of file
129diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
130index bfad2d2..b7cd2ea 100644
131--- a/tests/Formulas/MathTest.ts
132+++ b/tests/Formulas/MathTest.ts
133@@ -54,7 +54,7 @@ import {
134   MINUS,
135   RAND,
136   RANDBETWEEN,
137-  SIGN, DIVIDE
138+  SIGN, DIVIDE, EQ
139 } from "../../src/Formulas/Math";
140 import * as ERRORS from "../../src/Errors";
141 import {
142@@ -1203,6 +1203,24 @@ test("DIVIDE", function(){
143 });
144 
145 
146+test("EQ", function(){
147+  assertEquals(EQ(2, 2), true);
148+  assertEquals(EQ("2", 2), false);
149+  assertEquals(EQ("2", "2"), true);
150+  assertEquals(EQ("abc", "abc"), true);
151+  assertEquals(EQ(true, true), true);
152+  assertEquals(EQ(false, true), false);
153+  assertEquals(EQ(false, false), true);
154+  assertEquals(EQ(0, 0), true);
155+  catchAndAssertEquals(function() {
156+    EQ.apply(this, [3.1, 1, 1]);
157+  }, ERRORS.NA_ERROR);
158+  catchAndAssertEquals(function() {
159+    EQ.apply(this, [1]);
160+  }, ERRORS.NA_ERROR);
161+});
162+
163+
164 test("RAND", function(){
165   catchAndAssertEquals(function() {
166     RAND.apply(this, [3]);
167diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
168index 7183548..840cad9 100644
169--- a/tests/SheetFormulaTest.ts
170+++ b/tests/SheetFormulaTest.ts
171@@ -262,6 +262,10 @@ test("Sheet DIVIDE", function(){
172   assertFormulaEquals('=DIVIDE(22, 11)', 2);
173 });
174 
175+test("Sheet EQ", function(){
176+  assertFormulaEquals('=EQ(22, 11)', false);
177+});
178+
179 test("Sheet SIGN", function(){
180   assertFormulaEquals('=SIGN(100)', 1);
181 });