commit
message
Formulas.POWER written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-04 22:04:42
stats
2 file(s) changed,
33 insertions(+),
0 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index ea86778..3299bda 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -163,7 +163,20 @@ var OR = function (...values) {
6 return false;
7 };
8
9-var POWER = Formula["POWER"];
10+/**
11+ * Returns a number raised to a power.
12+ * @param values[0] The number to raise to the exponent power.
13+ * @param values[1] The exponent to raise base to.
14+ * @returns {number} resulting number
15+ * @constructor
16+ */
17+var POWER = function (...values) : number {
18+ checkArgumentsLength(values, 2);
19+ var n = firstValueAsNumber(values[0]);
20+ var p = firstValueAsNumber(values[1]);
21+ return Math.pow(n, p);
22+};
23+
24 var ROUND = Formula["ROUND"];
25 var ROUNDDOWN = Formula["ROUNDDOWN"];
26 var ROUNDUP = Formula["ROUNDUP"];
27diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
28index b86f508..22288c7 100644
29--- a/tests/FormulasTest.ts
30+++ b/tests/FormulasTest.ts
31@@ -836,7 +836,26 @@ catchAndAssertEquals(function() {
32
33 assertEquals(PI(), 3.141592653589793);
34
35+
36+// Test POWER
37 assertEquals(POWER(4, 10), 1048576);
38+assertEquals(POWER(4, false), 1);
39+assertEquals(POWER(4, true), 4);
40+assertEquals(POWER([4], [10]), 1048576);
41+assertEquals(POWER([4], [10, "str"]), 1048576);
42+catchAndAssertEquals(function() {
43+ POWER(4, "str");
44+}, ERRORS.VALUE_ERROR);
45+catchAndAssertEquals(function() {
46+ POWER();
47+}, ERRORS.NA_ERROR);
48+catchAndAssertEquals(function() {
49+ POWER(4);
50+}, ERRORS.NA_ERROR);
51+catchAndAssertEquals(function() {
52+ POWER(4, 10, 22);
53+}, ERRORS.NA_ERROR);
54+
55
56 assertEquals(ROUND(99.44, 1), 99.4);
57