commit
message
[NA] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-05-29 18:07:23
stats
8 file(s) changed,
79 insertions(+),
4 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Info.js
src/Formulas/AllFormulas.ts
src/Formulas/Info.ts
tests/Formulas/InfoTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 2231bca..43c43fe 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -438,6 +438,15 @@
6 @returns {number}
7 @constructor TODO: This function is based off of the open-source versions I was able to dig up online. We should implement a TODO: second version that is closer to what MSExcel does and is named something like `ACCRINT.MS`.
8 ```
9+## Info
10+
11+
12+### NA
13+
14+```
15+ Returns the "value not available" error, "#NA".
16+@constructor
17+```
18 ## Logical
19
20
21diff --git a/TODO.md b/TODO.md
22index bdb1c3b..cb52986 100644
23--- a/TODO.md
24+++ b/TODO.md
25@@ -28,7 +28,6 @@ For example 64 tbs to a qt.
26 * ISTEXT
27 * ISURL
28 * N
29-* NA
30 * TYPE
31 * CELL
32 * IFERROR
33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
34index 6fa9dff..94e934d 100644
35--- a/dist/Formulas/AllFormulas.js
36+++ b/dist/Formulas/AllFormulas.js
37@@ -64,6 +64,8 @@ exports.GTE = Math_1.GTE;
38 exports.LT = Math_1.LT;
39 exports.LTE = Math_1.LTE;
40 exports.NE = Math_1.NE;
41+var Info_1 = require("./Info");
42+exports.NA = Info_1.NA;
43 var Logical_1 = require("./Logical");
44 exports.AND = Logical_1.AND;
45 exports.EXACT = Logical_1.EXACT;
46diff --git a/dist/Formulas/Info.js b/dist/Formulas/Info.js
47new file mode 100644
48index 0000000..a2ff652
49--- /dev/null
50+++ b/dist/Formulas/Info.js
51@@ -0,0 +1,13 @@
52+"use strict";
53+exports.__esModule = true;
54+var ArgsChecker_1 = require("../Utilities/ArgsChecker");
55+var Errors_1 = require("../Errors");
56+/**
57+ * Returns the "value not available" error, "#N/A".
58+ * @constructor
59+ */
60+var NA = function () {
61+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "NA");
62+ throw new Errors_1.NAError("NA Error thrown.");
63+};
64+exports.NA = NA;
65diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
66index 4ec5bf6..bc2e10c 100644
67--- a/src/Formulas/AllFormulas.ts
68+++ b/src/Formulas/AllFormulas.ts
69@@ -63,6 +63,9 @@ import {
70 LTE,
71 NE
72 } from "./Math";
73+import {
74+ NA
75+} from "./Info";
76 import {
77 AND,
78 EXACT,
79@@ -291,5 +294,6 @@ export {
80 GTE,
81 LT,
82 LTE,
83- NE
84+ NE,
85+ NA
86 }
87\ No newline at end of file
88diff --git a/src/Formulas/Info.ts b/src/Formulas/Info.ts
89new file mode 100644
90index 0000000..d03c506
91--- /dev/null
92+++ b/src/Formulas/Info.ts
93@@ -0,0 +1,25 @@
94+import {
95+ ArgsChecker
96+} from "../Utilities/ArgsChecker";
97+import {
98+ NumError,
99+ DivZeroError,
100+ RefError,
101+ ValueError,
102+ NAError
103+} from "../Errors";
104+
105+
106+/**
107+ * Returns the "value not available" error, "#N/A".
108+ * @constructor
109+ */
110+var NA = function () {
111+ ArgsChecker.checkLength(arguments, 1, "NA");
112+ throw new NAError("NA Error thrown.");
113+};
114+
115+
116+export {
117+ NA
118+}
119\ No newline at end of file
120diff --git a/tests/Formulas/InfoTest.ts b/tests/Formulas/InfoTest.ts
121new file mode 100644
122index 0000000..32bd4a0
123--- /dev/null
124+++ b/tests/Formulas/InfoTest.ts
125@@ -0,0 +1,15 @@
126+import {
127+ NA
128+} from "../../src/Formulas/Info";
129+import * as ERRORS from "../../src/Errors";
130+import {
131+ catchAndAssertEquals,
132+ test
133+} from "../Utils/Asserts";
134+
135+
136+test("NA", function(){
137+ catchAndAssertEquals(function() {
138+ NA();
139+ }, ERRORS.NA_ERROR);
140+});
141diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
142index d4616b3..7d56ccf 100644
143--- a/tests/SheetFormulaTest.ts
144+++ b/tests/SheetFormulaTest.ts
145@@ -5,7 +5,11 @@ import {
146 assertEquals,
147 test
148 } from "./Utils/Asserts";
149-import {DIV_ZERO_ERROR, VALUE_ERROR} from "../src/Errors";
150+import {
151+ DIV_ZERO_ERROR,
152+ VALUE_ERROR,
153+ NA_ERROR
154+} from "../src/Errors";
155
156 function assertFormulaEqualsError(formula: string, errorString: string) {
157 var sheet = new Sheet();
158@@ -590,6 +594,10 @@ test("Sheet WORKDAY.INTL", function(){
159 assertFormulaEquals('=WORKDAY.INTL(DATE(1999, 2, 2), 10)', 36207);
160 });
161
162+test("Sheet NA", function(){
163+ assertFormulaEqualsError('=NA()', NA_ERROR);
164+});
165+
166 test("Sheet *", function(){
167 assertFormulaEquals('= 10 * 10', 100);
168 assertFormulaEquals('= 10 * 0', 0);