commit
message
[Engineering] Breaking out Engineering.ts tests into seperate file
author
Ben Vogt <[email protected]>
date
2017-04-29 21:43:56
stats
2 file(s) changed,
220 insertions(+),
205 deletions(-)
files
tests/EngineeringTest.ts
tests/FormulasTest.ts
1diff --git a/tests/EngineeringTest.ts b/tests/EngineeringTest.ts
2new file mode 100644
3index 0000000..54c9a54
4--- /dev/null
5+++ b/tests/EngineeringTest.ts
6@@ -0,0 +1,218 @@
7+import {
8+ BIN2DEC,
9+ BIN2HEX,
10+ BIN2OCT,
11+ DEC2BIN,
12+ DEC2HEX,
13+ DEC2OCT,
14+ DELTA
15+} from "../src/RawFormulas/Engineering";
16+import * as ERRORS from "../src/Errors"
17+import {
18+ assertEquals,
19+ catchAndAssertEquals
20+} from "./utils/Asserts"
21+
22+
23+// Test BIN2DEC
24+assertEquals(BIN2DEC("1010101010"), -342);
25+assertEquals(BIN2DEC("10"), 2);
26+assertEquals(BIN2DEC(["10", "str"]), 2);
27+catchAndAssertEquals(function() {
28+ BIN2DEC(false);
29+}, ERRORS.VALUE_ERROR);
30+catchAndAssertEquals(function() {
31+ BIN2DEC("str");
32+}, ERRORS.NUM_ERROR);
33+catchAndAssertEquals(function() {
34+ BIN2DEC();
35+}, ERRORS.NA_ERROR);
36+catchAndAssertEquals(function() {
37+ BIN2DEC("10", "10");
38+}, ERRORS.NA_ERROR);
39+
40+
41+// Test BIN2HEX
42+assertEquals(BIN2HEX("1010101010"), "FFFFFFFEAA");
43+assertEquals(BIN2HEX("10"), "2");
44+assertEquals(BIN2HEX("10101010"), "AA");
45+assertEquals(BIN2HEX("10101010", 4), "00AA");
46+assertEquals(BIN2HEX(["10101010"], [4]), "00AA");
47+catchAndAssertEquals(function() {
48+ BIN2HEX("10101010", 22);
49+}, ERRORS.NUM_ERROR);
50+catchAndAssertEquals(function() {
51+ BIN2HEX(false);
52+}, ERRORS.VALUE_ERROR);
53+catchAndAssertEquals(function() {
54+ BIN2HEX("10101010", 0);
55+}, ERRORS.NUM_ERROR);
56+catchAndAssertEquals(function() {
57+ BIN2DEC("str");
58+}, ERRORS.NUM_ERROR);
59+catchAndAssertEquals(function() {
60+ BIN2DEC();
61+}, ERRORS.NA_ERROR);
62+catchAndAssertEquals(function() {
63+ BIN2DEC("10", 4, 4);
64+}, ERRORS.NA_ERROR);
65+
66+
67+// Test BIN2OCT
68+assertEquals(BIN2OCT("1010101010"), "7777777252");
69+assertEquals(BIN2OCT("10"), "2");
70+assertEquals(BIN2OCT("100"), "4");
71+assertEquals(BIN2OCT("10101010"), "252");
72+assertEquals(BIN2OCT("10101010", 4), "252");
73+assertEquals(BIN2OCT(["10101010"], [4]), "252");
74+catchAndAssertEquals(function() {
75+ BIN2OCT("10101010", 22);
76+}, ERRORS.NUM_ERROR);
77+catchAndAssertEquals(function() {
78+ BIN2OCT(false);
79+}, ERRORS.VALUE_ERROR);
80+catchAndAssertEquals(function() {
81+ BIN2OCT("10101010", 0);
82+}, ERRORS.NUM_ERROR);
83+catchAndAssertEquals(function() {
84+ BIN2OCT("str");
85+}, ERRORS.NUM_ERROR);
86+catchAndAssertEquals(function() {
87+ BIN2OCT();
88+}, ERRORS.NA_ERROR);
89+catchAndAssertEquals(function() {
90+ BIN2OCT("10", 4, 4);
91+}, ERRORS.NA_ERROR);
92+
93+
94+// Test DEC2BIN
95+assertEquals(DEC2BIN([100]), "1100100");
96+assertEquals(DEC2BIN(100), "1100100");
97+assertEquals(DEC2BIN(22), "10110");
98+assertEquals(DEC2BIN(22.11), "10110");
99+assertEquals(DEC2BIN(22.77), "10110");
100+assertEquals(DEC2BIN("22.77"), "10110");
101+assertEquals(DEC2BIN(100, 8), "01100100");
102+assertEquals(DEC2BIN([100], [8]), "01100100");
103+assertEquals(DEC2BIN(100, 7), "1100100");
104+assertEquals(DEC2BIN(100, 10), "0001100100");
105+assertEquals(DEC2BIN(-100), "1110011100");
106+assertEquals(DEC2BIN("-22.77"), "1111101010");
107+assertEquals(DEC2BIN(-22.11), "1111101010");
108+assertEquals(DEC2BIN(-22), "1111101010");
109+assertEquals(DEC2BIN(false), "0");
110+assertEquals(DEC2BIN(true), "1");
111+catchAndAssertEquals(function() {
112+ DEC2BIN(100, 0);
113+}, ERRORS.NUM_ERROR);
114+catchAndAssertEquals(function() {
115+ DEC2BIN(513, 10);
116+}, ERRORS.NUM_ERROR);
117+catchAndAssertEquals(function() {
118+ DEC2BIN(100, 100, 10);
119+}, ERRORS.NA_ERROR);
120+catchAndAssertEquals(function() {
121+ DEC2BIN();
122+}, ERRORS.NA_ERROR);
123+catchAndAssertEquals(function() {
124+ DEC2BIN("str");
125+}, ERRORS.VALUE_ERROR);
126+
127+
128+// Test DEC2HEX
129+assertEquals(DEC2HEX([100]), "64");
130+assertEquals(DEC2HEX(100), "64");
131+assertEquals(DEC2HEX(22), "16");
132+assertEquals(DEC2HEX(22.11), "16");
133+assertEquals(DEC2HEX(22.77), "16");
134+assertEquals(DEC2HEX("22.77"), "16");
135+assertEquals(DEC2HEX(100, 8), "00000064");
136+assertEquals(DEC2HEX([100], [8]), "00000064");
137+assertEquals(DEC2HEX(100, 7), "0000064");
138+assertEquals(DEC2HEX(100, 10), "0000000064");
139+assertEquals(DEC2HEX(-100), "FFFFFFFF9C");
140+assertEquals(DEC2HEX("-22.77"), "FFFFFFFFEA");
141+assertEquals(DEC2HEX(-22.11), "FFFFFFFFEA");
142+assertEquals(DEC2HEX(-22), "FFFFFFFFEA");
143+assertEquals(DEC2HEX(false), "0");
144+assertEquals(DEC2HEX(true), "1");
145+catchAndAssertEquals(function() {
146+ DEC2HEX(100, 0);
147+}, ERRORS.NUM_ERROR);
148+catchAndAssertEquals(function() {
149+ DEC2HEX(549755813889, 10);
150+}, ERRORS.NUM_ERROR);
151+catchAndAssertEquals(function() {
152+ DEC2HEX(54975581, -10);
153+}, ERRORS.NUM_ERROR);
154+catchAndAssertEquals(function() {
155+ DEC2HEX(100, 100, 10);
156+}, ERRORS.NA_ERROR);
157+catchAndAssertEquals(function() {
158+ DEC2HEX();
159+}, ERRORS.NA_ERROR);
160+catchAndAssertEquals(function() {
161+ DEC2HEX("str");
162+}, ERRORS.VALUE_ERROR);
163+
164+
165+// Test DEC2OCT
166+assertEquals(DEC2OCT([100]), "144");
167+assertEquals(DEC2OCT(100), "144");
168+assertEquals(DEC2OCT(22), "26");
169+assertEquals(DEC2OCT(22.11), "26");
170+assertEquals(DEC2OCT(22.77), "26");
171+assertEquals(DEC2OCT("22.77"), "26");
172+assertEquals(DEC2OCT(100, 8), "00000144");
173+assertEquals(DEC2OCT([100], [8]), "00000144");
174+assertEquals(DEC2OCT(100, 7), "0000144");
175+assertEquals(DEC2OCT(100, 10), "0000000144");
176+assertEquals(DEC2OCT(-100), "7777777634");
177+assertEquals(DEC2OCT("-22.77"), "7777777752");
178+assertEquals(DEC2OCT(-22.11), "7777777752");
179+assertEquals(DEC2OCT(-22), "7777777752");
180+assertEquals(DEC2OCT(false), "0");
181+assertEquals(DEC2OCT(true), "1");
182+catchAndAssertEquals(function() {
183+ DEC2OCT(100, 0);
184+}, ERRORS.NUM_ERROR);
185+catchAndAssertEquals(function() {
186+ DEC2OCT(536870913, 10);
187+}, ERRORS.NUM_ERROR);
188+catchAndAssertEquals(function() {
189+ DEC2OCT(536870910, -10);
190+}, ERRORS.NUM_ERROR);
191+catchAndAssertEquals(function() {
192+ DEC2OCT(100, 100, 10);
193+}, ERRORS.NA_ERROR);
194+catchAndAssertEquals(function() {
195+ DEC2OCT();
196+}, ERRORS.NA_ERROR);
197+catchAndAssertEquals(function() {
198+ DEC2OCT("str");
199+}, ERRORS.VALUE_ERROR);
200+
201+
202+// Test DELTA
203+assertEquals(DELTA(2, 2), 1);
204+assertEquals(DELTA(2, 1), 0);
205+assertEquals(DELTA(2), 0);
206+assertEquals(DELTA("", ""), 1);
207+assertEquals(DELTA(false), 1);
208+assertEquals(DELTA(true), 0);
209+assertEquals(DELTA(2.2, 2.1), 0);
210+assertEquals(DELTA(1, true), 1);
211+assertEquals(DELTA(0, false), 1);
212+assertEquals(DELTA(true, true), 1);
213+catchAndAssertEquals(function() {
214+ DELTA("str");
215+}, ERRORS.VALUE_ERROR);
216+catchAndAssertEquals(function() {
217+ DELTA("n", "n");
218+}, ERRORS.VALUE_ERROR);
219+catchAndAssertEquals(function() {
220+ DELTA();
221+}, ERRORS.NA_ERROR);
222+catchAndAssertEquals(function() {
223+ DELTA(1, 2, 3);
224+}, ERRORS.NA_ERROR);
225\ No newline at end of file
226diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
227index 6f38207..082a058 100644
228--- a/tests/FormulasTest.ts
229+++ b/tests/FormulasTest.ts
230@@ -1,9 +1,9 @@
231 import { ABS, ACCRINT, ACOS, ACOSH, ACOTH, AND, ARABIC, ASIN, ASINH, ATAN, ATAN2, ATANH, AVEDEV, AVERAGE,
232- AVERAGEA, AVERAGEIF, BIN2DEC, BIN2HEX, BIN2OCT, CEILING,
233+ AVERAGEA, AVERAGEIF, CEILING,
234 CHAR, CODE, COMBIN, CONCATENATE, CONVERT, PEARSON,
235 CORREL, COS, PI, COSH, COT, COTH, COUNT, COUNTA, COUNTIF, COUNTIFS, COUNTUNIQUE,
236 CUMIPMT, CUMPRINC,
237- DB, DDB, DEC2BIN, DEC2HEX, DEC2OCT, DEGREES, DELTA, DEVSQ, DOLLAR, DOLLARDE, DOLLARFR,
238+ DB, DDB, DEGREES, DEVSQ, DOLLAR, DOLLARDE, DOLLARFR,
239 EFFECT, ERF, ERFC, EVEN, EXACT, EXPONDIST, FINV, FALSE, FLOOR, __COMPLEX, FISHER, FISHERINV, IF,
240 INT, ISEVEN, ISODD, LN, LOG, LOG10, MAX, MAXA, MEDIAN, MIN, MINA, MOD, NOT, TRUE, ODD, OR,
241 POWER, ROUND, ROUNDDOWN, ROUNDUP, SIN, SINH, SPLIT, SQRT, SQRTPI, SUM, SUMIF, SUMPRODUCT, RADIANS,
242@@ -313,77 +313,6 @@ catchAndAssertEquals(function() {
243 }, ERRORS.DIV_ZERO_ERROR);
244
245
246-// Test BIN2DEC
247-assertEquals(BIN2DEC("1010101010"), -342);
248-assertEquals(BIN2DEC("10"), 2);
249-assertEquals(BIN2DEC(["10", "str"]), 2);
250-catchAndAssertEquals(function() {
251- BIN2DEC(false);
252-}, ERRORS.VALUE_ERROR);
253-catchAndAssertEquals(function() {
254- BIN2DEC("str");
255-}, ERRORS.NUM_ERROR);
256-catchAndAssertEquals(function() {
257- BIN2DEC();
258-}, ERRORS.NA_ERROR);
259-catchAndAssertEquals(function() {
260- BIN2DEC("10", "10");
261-}, ERRORS.NA_ERROR);
262-
263-
264-// Test BIN2HEX
265-assertEquals(BIN2HEX("1010101010"), "FFFFFFFEAA");
266-assertEquals(BIN2HEX("10"), "2");
267-assertEquals(BIN2HEX("10101010"), "AA");
268-assertEquals(BIN2HEX("10101010", 4), "00AA");
269-assertEquals(BIN2HEX(["10101010"], [4]), "00AA");
270-catchAndAssertEquals(function() {
271- BIN2HEX("10101010", 22);
272-}, ERRORS.NUM_ERROR);
273-catchAndAssertEquals(function() {
274- BIN2HEX(false);
275-}, ERRORS.VALUE_ERROR);
276-catchAndAssertEquals(function() {
277- BIN2HEX("10101010", 0);
278-}, ERRORS.NUM_ERROR);
279-catchAndAssertEquals(function() {
280- BIN2DEC("str");
281-}, ERRORS.NUM_ERROR);
282-catchAndAssertEquals(function() {
283- BIN2DEC();
284-}, ERRORS.NA_ERROR);
285-catchAndAssertEquals(function() {
286- BIN2DEC("10", 4, 4);
287-}, ERRORS.NA_ERROR);
288-
289-
290-// Test BIN2OCT
291-assertEquals(BIN2OCT("1010101010"), "7777777252");
292-assertEquals(BIN2OCT("10"), "2");
293-assertEquals(BIN2OCT("100"), "4");
294-assertEquals(BIN2OCT("10101010"), "252");
295-assertEquals(BIN2OCT("10101010", 4), "252");
296-assertEquals(BIN2OCT(["10101010"], [4]), "252");
297-catchAndAssertEquals(function() {
298- BIN2OCT("10101010", 22);
299-}, ERRORS.NUM_ERROR);
300-catchAndAssertEquals(function() {
301- BIN2OCT(false);
302-}, ERRORS.VALUE_ERROR);
303-catchAndAssertEquals(function() {
304- BIN2OCT("10101010", 0);
305-}, ERRORS.NUM_ERROR);
306-catchAndAssertEquals(function() {
307- BIN2OCT("str");
308-}, ERRORS.NUM_ERROR);
309-catchAndAssertEquals(function() {
310- BIN2OCT();
311-}, ERRORS.NA_ERROR);
312-catchAndAssertEquals(function() {
313- BIN2OCT("10", 4, 4);
314-}, ERRORS.NA_ERROR);
315-
316-
317 // Test CEILING
318 assertEquals(CEILING(10.1), 11);
319 assertEquals(CEILING("10.1"), 11);
320@@ -818,113 +747,6 @@ catchAndAssertEquals(function() {
321 }, ERRORS.NUM_ERROR);
322
323
324-// Test DEC2BIN
325-assertEquals(DEC2BIN([100]), "1100100");
326-assertEquals(DEC2BIN(100), "1100100");
327-assertEquals(DEC2BIN(22), "10110");
328-assertEquals(DEC2BIN(22.11), "10110");
329-assertEquals(DEC2BIN(22.77), "10110");
330-assertEquals(DEC2BIN("22.77"), "10110");
331-assertEquals(DEC2BIN(100, 8), "01100100");
332-assertEquals(DEC2BIN([100], [8]), "01100100");
333-assertEquals(DEC2BIN(100, 7), "1100100");
334-assertEquals(DEC2BIN(100, 10), "0001100100");
335-assertEquals(DEC2BIN(-100), "1110011100");
336-assertEquals(DEC2BIN("-22.77"), "1111101010");
337-assertEquals(DEC2BIN(-22.11), "1111101010");
338-assertEquals(DEC2BIN(-22), "1111101010");
339-assertEquals(DEC2BIN(false), "0");
340-assertEquals(DEC2BIN(true), "1");
341-catchAndAssertEquals(function() {
342- DEC2BIN(100, 0);
343-}, ERRORS.NUM_ERROR);
344-catchAndAssertEquals(function() {
345- DEC2BIN(513, 10);
346-}, ERRORS.NUM_ERROR);
347-catchAndAssertEquals(function() {
348- DEC2BIN(100, 100, 10);
349-}, ERRORS.NA_ERROR);
350-catchAndAssertEquals(function() {
351- DEC2BIN();
352-}, ERRORS.NA_ERROR);
353-catchAndAssertEquals(function() {
354- DEC2BIN("str");
355-}, ERRORS.VALUE_ERROR);
356-
357-// Test DEC2HEX
358-assertEquals(DEC2HEX([100]), "64");
359-assertEquals(DEC2HEX(100), "64");
360-assertEquals(DEC2HEX(22), "16");
361-assertEquals(DEC2HEX(22.11), "16");
362-assertEquals(DEC2HEX(22.77), "16");
363-assertEquals(DEC2HEX("22.77"), "16");
364-assertEquals(DEC2HEX(100, 8), "00000064");
365-assertEquals(DEC2HEX([100], [8]), "00000064");
366-assertEquals(DEC2HEX(100, 7), "0000064");
367-assertEquals(DEC2HEX(100, 10), "0000000064");
368-assertEquals(DEC2HEX(-100), "FFFFFFFF9C");
369-assertEquals(DEC2HEX("-22.77"), "FFFFFFFFEA");
370-assertEquals(DEC2HEX(-22.11), "FFFFFFFFEA");
371-assertEquals(DEC2HEX(-22), "FFFFFFFFEA");
372-assertEquals(DEC2HEX(false), "0");
373-assertEquals(DEC2HEX(true), "1");
374-catchAndAssertEquals(function() {
375- DEC2HEX(100, 0);
376-}, ERRORS.NUM_ERROR);
377-catchAndAssertEquals(function() {
378- DEC2HEX(549755813889, 10);
379-}, ERRORS.NUM_ERROR);
380-catchAndAssertEquals(function() {
381- DEC2HEX(54975581, -10);
382-}, ERRORS.NUM_ERROR);
383-catchAndAssertEquals(function() {
384- DEC2HEX(100, 100, 10);
385-}, ERRORS.NA_ERROR);
386-catchAndAssertEquals(function() {
387- DEC2HEX();
388-}, ERRORS.NA_ERROR);
389-catchAndAssertEquals(function() {
390- DEC2HEX("str");
391-}, ERRORS.VALUE_ERROR);
392-
393-
394-// Test DEC2OCT
395-assertEquals(DEC2OCT([100]), "144");
396-assertEquals(DEC2OCT(100), "144");
397-assertEquals(DEC2OCT(22), "26");
398-assertEquals(DEC2OCT(22.11), "26");
399-assertEquals(DEC2OCT(22.77), "26");
400-assertEquals(DEC2OCT("22.77"), "26");
401-assertEquals(DEC2OCT(100, 8), "00000144");
402-assertEquals(DEC2OCT([100], [8]), "00000144");
403-assertEquals(DEC2OCT(100, 7), "0000144");
404-assertEquals(DEC2OCT(100, 10), "0000000144");
405-assertEquals(DEC2OCT(-100), "7777777634");
406-assertEquals(DEC2OCT("-22.77"), "7777777752");
407-assertEquals(DEC2OCT(-22.11), "7777777752");
408-assertEquals(DEC2OCT(-22), "7777777752");
409-assertEquals(DEC2OCT(false), "0");
410-assertEquals(DEC2OCT(true), "1");
411-catchAndAssertEquals(function() {
412- DEC2OCT(100, 0);
413-}, ERRORS.NUM_ERROR);
414-catchAndAssertEquals(function() {
415- DEC2OCT(536870913, 10);
416-}, ERRORS.NUM_ERROR);
417-catchAndAssertEquals(function() {
418- DEC2OCT(536870910, -10);
419-}, ERRORS.NUM_ERROR);
420-catchAndAssertEquals(function() {
421- DEC2OCT(100, 100, 10);
422-}, ERRORS.NA_ERROR);
423-catchAndAssertEquals(function() {
424- DEC2OCT();
425-}, ERRORS.NA_ERROR);
426-catchAndAssertEquals(function() {
427- DEC2OCT("str");
428-}, ERRORS.VALUE_ERROR);
429-
430-
431 // Test DEGREES
432 assertEquals(DEGREES(PI()), 180);
433 assertEquals(DEGREES([PI(), "str"]), 180);
434@@ -943,31 +765,6 @@ catchAndAssertEquals(function() {
435 }, ERRORS.NA_ERROR);
436
437
438-// Test DELTA
439-assertEquals(DELTA(2, 2), 1);
440-assertEquals(DELTA(2, 1), 0);
441-assertEquals(DELTA(2), 0);
442-assertEquals(DELTA("", ""), 1);
443-assertEquals(DELTA(false), 1);
444-assertEquals(DELTA(true), 0);
445-assertEquals(DELTA(2.2, 2.1), 0);
446-assertEquals(DELTA(1, true), 1);
447-assertEquals(DELTA(0, false), 1);
448-assertEquals(DELTA(true, true), 1);
449-catchAndAssertEquals(function() {
450- DELTA("str");
451-}, ERRORS.VALUE_ERROR);
452-catchAndAssertEquals(function() {
453- DELTA("n", "n");
454-}, ERRORS.VALUE_ERROR);
455-catchAndAssertEquals(function() {
456- DELTA();
457-}, ERRORS.NA_ERROR);
458-catchAndAssertEquals(function() {
459- DELTA(1, 2, 3);
460-}, ERRORS.NA_ERROR);
461-
462-
463 // Test DEVSQ
464 assertEquals(DEVSQ(1, 2), 0.5);
465 assertEquals(DEVSQ([1, 2]), 0.5);