commit
message
[GT, GTE, LT, LTE, NE] formulas added and tested
author
Ben Vogt <[email protected]>
date
2017-05-26 18:55:53
stats
8 file(s) changed,
345 insertions(+),
8 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 0ceeead..2231bca 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -918,6 +918,55 @@
6 @constructor
7 ```
8
9+### GT
10+
11+```
12+ Returns true if the first argument is strictly greater than the second, and false otherwise. Equivalent to the `>` operator.
13+@param one - The value to test as being greater than `two`.
14+@param two - The second value.
15+@returns {boolean}
16+@constructor
17+```
18+
19+### GTE
20+
21+```
22+ Returns true if the first argument is greater than or equal to the second, and false otherwise. Equivalent to the `>=` operator.
23+@param one - The value to test as being greater than or equal to `two`.
24+@param two -The second value.
25+@returns {boolean}
26+@constructor
27+```
28+
29+### LT
30+
31+```
32+ Returns true if the first argument is strictly less than the second, and false otherwise. Equivalent to the `<` operator.
33+@param one - The value to test as being less than `two`.
34+@param two - The second value.
35+@returns {boolean}
36+@constructor
37+```
38+
39+### LTE
40+
41+```
42+ Returns true if the first argument is less than or equal to the second, and true otherwise. Equivalent to the `<=` operator.
43+@param one - The value to test as being less than or equal to `two`.
44+@param two - The second value.
45+@constructor
46+```
47+
48+### NE
49+
50+```
51+ Returns "TRUE" if two specified values are not equal and "FALSE" otherwise. Equivalent to the "<>" operator.
52+@param one - The value to test as being not equal to `two`.
53+@param two - The second valud.
54+@returns {boolean}
55+@constructor
56+```
57+
58 ### DIVIDE
59
60 ```
61diff --git a/TODO.md b/TODO.md
62index 5690bca..bdb1c3b 100644
63--- a/TODO.md
64+++ b/TODO.md
65@@ -56,11 +56,6 @@ For example 64 tbs to a qt.
66 * QUOTIENT
67 * SERIESSUM
68 * SUBTOTAL
69-* GT
70-* GTE
71-* LT
72-* LTE
73-* NE
74 * UMINUS
75 * UNARY_PERCENT
76 * UPLUS
77diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
78index abab0f6..6fa9dff 100644
79--- a/dist/Formulas/AllFormulas.js
80+++ b/dist/Formulas/AllFormulas.js
81@@ -59,6 +59,11 @@ exports.RANDBETWEEN = Math_1.RANDBETWEEN;
82 exports.SIGN = Math_1.SIGN;
83 exports.DIVIDE = Math_1.DIVIDE;
84 exports.EQ = Math_1.EQ;
85+exports.GT = Math_1.GT;
86+exports.GTE = Math_1.GTE;
87+exports.LT = Math_1.LT;
88+exports.LTE = Math_1.LTE;
89+exports.NE = Math_1.NE;
90 var Logical_1 = require("./Logical");
91 exports.AND = Logical_1.AND;
92 exports.EXACT = Logical_1.EXACT;
93diff --git a/dist/Formulas/Math.js b/dist/Formulas/Math.js
94index b8bb5e5..2df80ef 100644
95--- a/dist/Formulas/Math.js
96+++ b/dist/Formulas/Math.js
97@@ -782,6 +782,79 @@ var EQ = function (one, two) {
98 return x === y;
99 };
100 exports.EQ = EQ;
101+/**
102+ * Returns true if the first argument is strictly greater than the second, and false otherwise. Equivalent to the `>`
103+ * operator.
104+ * @param one - The value to test as being greater than `two`.
105+ * @param two - The second value.
106+ * @returns {boolean}
107+ * @constructor
108+ */
109+var GT = function (one, two) {
110+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "GT");
111+ var x = TypeConverter_1.TypeConverter.firstValue(one);
112+ var y = TypeConverter_1.TypeConverter.firstValue(two);
113+ return x > y;
114+};
115+exports.GT = GT;
116+/**
117+ * Returns true if the first argument is greater than or equal to the second, and false otherwise. Equivalent to the
118+ * `>=` operator.
119+ * @param one - The value to test as being greater than or equal to `two`.
120+ * @param two -The second value.
121+ * @returns {boolean}
122+ * @constructor
123+ */
124+var GTE = function (one, two) {
125+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "GTE");
126+ var x = TypeConverter_1.TypeConverter.firstValue(one);
127+ var y = TypeConverter_1.TypeConverter.firstValue(two);
128+ return x >= y;
129+};
130+exports.GTE = GTE;
131+/**
132+ * Returns true if the first argument is strictly less than the second, and false otherwise. Equivalent to the `<`
133+ * operator.
134+ * @param one - The value to test as being less than `two`.
135+ * @param two - The second value.
136+ * @returns {boolean}
137+ * @constructor
138+ */
139+var LT = function (one, two) {
140+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "LT");
141+ var x = TypeConverter_1.TypeConverter.firstValue(one);
142+ var y = TypeConverter_1.TypeConverter.firstValue(two);
143+ return x < y;
144+};
145+exports.LT = LT;
146+/**
147+ * Returns true if the first argument is less than or equal to the second, and true otherwise. Equivalent to the
148+ * `<=` operator.
149+ * @param one - The value to test as being less than or equal to `two`.
150+ * @param two - The second value.
151+ * @constructor
152+ */
153+var LTE = function (one, two) {
154+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "LTE");
155+ var x = TypeConverter_1.TypeConverter.firstValue(one);
156+ var y = TypeConverter_1.TypeConverter.firstValue(two);
157+ return x <= y;
158+};
159+exports.LTE = LTE;
160+/**
161+ * Returns "TRUE" if two specified values are not equal and "FALSE" otherwise. Equivalent to the "<>" operator.
162+ * @param one - The value to test as being not equal to `two`.
163+ * @param two - The second valud.
164+ * @returns {boolean}
165+ * @constructor
166+ */
167+var NE = function (one, two) {
168+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 2, "NE");
169+ var x = TypeConverter_1.TypeConverter.firstValue(one);
170+ var y = TypeConverter_1.TypeConverter.firstValue(two);
171+ return x !== y;
172+};
173+exports.NE = NE;
174 /**
175 * Returns one number divided by another. Equivalent to the `/` operator.
176 * @param dividend - The number to be divided.
177diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
178index 15b0c66..4ec5bf6 100644
179--- a/src/Formulas/AllFormulas.ts
180+++ b/src/Formulas/AllFormulas.ts
181@@ -56,7 +56,12 @@ import {
182 RANDBETWEEN,
183 SIGN,
184 DIVIDE,
185- EQ
186+ EQ,
187+ GT,
188+ GTE,
189+ LT,
190+ LTE,
191+ NE
192 } from "./Math";
193 import {
194 AND,
195@@ -281,5 +286,10 @@ export {
196 RANDBETWEEN,
197 SIGN,
198 DIVIDE,
199- EQ
200+ EQ,
201+ GT,
202+ GTE,
203+ LT,
204+ LTE,
205+ NE
206 }
207\ No newline at end of file
208diff --git a/src/Formulas/Math.ts b/src/Formulas/Math.ts
209index b223208..2d52704 100644
210--- a/src/Formulas/Math.ts
211+++ b/src/Formulas/Math.ts
212@@ -791,6 +791,84 @@ var EQ = function (one, two) {
213 };
214
215
216+/**
217+ * Returns true if the first argument is strictly greater than the second, and false otherwise. Equivalent to the `>`
218+ * operator.
219+ * @param one - The value to test as being greater than `two`.
220+ * @param two - The second value.
221+ * @returns {boolean}
222+ * @constructor
223+ */
224+var GT = function (one, two) {
225+ ArgsChecker.checkLength(arguments, 2, "GT");
226+ var x = TypeConverter.firstValue(one);
227+ var y = TypeConverter.firstValue(two);
228+ return x > y;
229+};
230+
231+
232+/**
233+ * Returns true if the first argument is greater than or equal to the second, and false otherwise. Equivalent to the
234+ * `>=` operator.
235+ * @param one - The value to test as being greater than or equal to `two`.
236+ * @param two -The second value.
237+ * @returns {boolean}
238+ * @constructor
239+ */
240+var GTE = function (one, two) {
241+ ArgsChecker.checkLength(arguments, 2, "GTE");
242+ var x = TypeConverter.firstValue(one);
243+ var y = TypeConverter.firstValue(two);
244+ return x >= y;
245+};
246+
247+
248+/**
249+ * Returns true if the first argument is strictly less than the second, and false otherwise. Equivalent to the `<`
250+ * operator.
251+ * @param one - The value to test as being less than `two`.
252+ * @param two - The second value.
253+ * @returns {boolean}
254+ * @constructor
255+ */
256+var LT = function (one, two) {
257+ ArgsChecker.checkLength(arguments, 2, "LT");
258+ var x = TypeConverter.firstValue(one);
259+ var y = TypeConverter.firstValue(two);
260+ return x < y;
261+};
262+
263+
264+/**
265+ * Returns true if the first argument is less than or equal to the second, and true otherwise. Equivalent to the
266+ * `<=` operator.
267+ * @param one - The value to test as being less than or equal to `two`.
268+ * @param two - The second value.
269+ * @constructor
270+ */
271+var LTE = function (one, two) {
272+ ArgsChecker.checkLength(arguments, 2, "LTE");
273+ var x = TypeConverter.firstValue(one);
274+ var y = TypeConverter.firstValue(two);
275+ return x <= y;
276+};
277+
278+
279+/**
280+ * Returns "TRUE" if two specified values are not equal and "FALSE" otherwise. Equivalent to the "<>" operator.
281+ * @param one - The value to test as being not equal to `two`.
282+ * @param two - The second valud.
283+ * @returns {boolean}
284+ * @constructor
285+ */
286+var NE = function (one, two) {
287+ ArgsChecker.checkLength(arguments, 2, "NE");
288+ var x = TypeConverter.firstValue(one);
289+ var y = TypeConverter.firstValue(two);
290+ return x !== y;
291+};
292+
293+
294 /**
295 * Returns one number divided by another. Equivalent to the `/` operator.
296 * @param dividend - The number to be divided.
297@@ -1157,5 +1235,10 @@ export {
298 RANDBETWEEN,
299 SIGN,
300 DIVIDE,
301- EQ
302+ EQ,
303+ GT,
304+ GTE,
305+ LT,
306+ LTE,
307+ NE
308 }
309\ No newline at end of file
310diff --git a/tests/Formulas/MathTest.ts b/tests/Formulas/MathTest.ts
311index b7cd2ea..7ef12dd 100644
312--- a/tests/Formulas/MathTest.ts
313+++ b/tests/Formulas/MathTest.ts
314@@ -54,7 +54,14 @@ import {
315 MINUS,
316 RAND,
317 RANDBETWEEN,
318- SIGN, DIVIDE, EQ
319+ SIGN,
320+ DIVIDE,
321+ EQ,
322+ GT,
323+ GTE,
324+ LT,
325+ LTE,
326+ NE
327 } from "../../src/Formulas/Math";
328 import * as ERRORS from "../../src/Errors";
329 import {
330@@ -1221,6 +1228,99 @@ test("EQ", function(){
331 });
332
333
334+test("GT", function(){
335+ assertEquals(GT(2, 2), false);
336+ assertEquals(GT(2, 3), false);
337+ assertEquals(GT(2, 1), true);
338+ assertEquals(GT("abc", "a"), true);
339+ assertEquals(GT("abc", "abcd"), false);
340+ assertEquals(GT(false, false), false);
341+ assertEquals(GT(true, false), true);
342+ catchAndAssertEquals(function() {
343+ GT.apply(this, [3]);
344+ }, ERRORS.NA_ERROR);
345+ catchAndAssertEquals(function() {
346+ GT.apply(this, [3, 3, 3]);
347+ }, ERRORS.NA_ERROR);
348+});
349+
350+
351+test("GTE", function(){
352+ assertEquals(GTE(2, 2), true);
353+ assertEquals(GTE(2, 3), false);
354+ assertEquals(GTE(2, 1), true);
355+ assertEquals(GTE("abc", "a"), true);
356+ assertEquals(GTE("abc", "abc"), true);
357+ assertEquals(GTE("abc", "abcd"), false);
358+ assertEquals(GTE(false, false), true);
359+ assertEquals(GTE(true, false), true);
360+ catchAndAssertEquals(function() {
361+ GTE.apply(this, [3]);
362+ }, ERRORS.NA_ERROR);
363+ catchAndAssertEquals(function() {
364+ GTE.apply(this, [3, 3, 3]);
365+ }, ERRORS.NA_ERROR);
366+});
367+
368+
369+test("LT", function(){
370+ assertEquals(LT(2, 2), false);
371+ assertEquals(LT(2, 3), true);
372+ assertEquals(LT(2, 1), false);
373+ assertEquals(LT("abc", "a"), false);
374+ assertEquals(LT("abc", "abc"), false);
375+ assertEquals(LT("abc", "abcd"), true);
376+ assertEquals(LT(false, false), false);
377+ assertEquals(LT(true, false), false);
378+ assertEquals(LT(false, true), true);
379+ catchAndAssertEquals(function() {
380+ LT.apply(this, [3]);
381+ }, ERRORS.NA_ERROR);
382+ catchAndAssertEquals(function() {
383+ LT.apply(this, [3, 3, 3]);
384+ }, ERRORS.NA_ERROR);
385+});
386+
387+
388+test("NE", function(){
389+ assertEquals(NE(2, 2), false);
390+ assertEquals(NE(2, 3), true);
391+ assertEquals(NE(2, 1), true);
392+ assertEquals(NE("abc", "a"), true);
393+ assertEquals(NE("abc", "abc"), false);
394+ assertEquals(NE("abc", "abcd"), true);
395+ assertEquals(NE(false, false), false);
396+ assertEquals(NE(true, false), true);
397+ assertEquals(NE(false, true), true);
398+ catchAndAssertEquals(function() {
399+ NE.apply(this, [3]);
400+ }, ERRORS.NA_ERROR);
401+ catchAndAssertEquals(function() {
402+ NE.apply(this, [3, 3, 3]);
403+ }, ERRORS.NA_ERROR);
404+});
405+
406+
407+test("LTE", function(){
408+ assertEquals(LTE(2, 2), true);
409+ assertEquals(LTE(2, 3), true);
410+ assertEquals(LTE(2, 1), false);
411+ assertEquals(LTE("abc", "a"), false);
412+ assertEquals(LTE("abc", "abc"), true);
413+ assertEquals(LTE("abc", "abcd"), true);
414+ assertEquals(LTE(false, false), true);
415+ assertEquals(LTE(true, false), false);
416+ assertEquals(LTE(false, true), true);
417+ assertEquals(LTE(true, true), true);
418+ catchAndAssertEquals(function() {
419+ LTE.apply(this, [3]);
420+ }, ERRORS.NA_ERROR);
421+ catchAndAssertEquals(function() {
422+ LTE.apply(this, [3, 3, 3]);
423+ }, ERRORS.NA_ERROR);
424+});
425+
426+
427 test("RAND", function(){
428 catchAndAssertEquals(function() {
429 RAND.apply(this, [3]);
430diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
431index 840cad9..d4616b3 100644
432--- a/tests/SheetFormulaTest.ts
433+++ b/tests/SheetFormulaTest.ts
434@@ -266,6 +266,27 @@ test("Sheet EQ", function(){
435 assertFormulaEquals('=EQ(22, 11)', false);
436 });
437
438+test("Sheet GT", function(){
439+ assertFormulaEquals('=GT(1, 0)', true);
440+});
441+
442+test("Sheet GTE", function(){
443+ assertFormulaEquals('=GTE(1, 1)', true);
444+});
445+
446+test("Sheet LT", function(){
447+ assertFormulaEquals('=LT(0, 1)', true);
448+});
449+
450+test("Sheet NE", function(){
451+ assertFormulaEquals('=NE(0, 1)', true);
452+});
453+
454+test("Sheet LTE", function(){
455+ assertFormulaEquals('=LTE(0, 0)', true);
456+});
457+
458+
459 test("Sheet SIGN", function(){
460 assertFormulaEquals('=SIGN(100)', 1);
461 });