commit
message
Formulas.COS written and tested.
author
Ben Vogt <[email protected]>
date
2017-02-02 00:07:48
stats
2 file(s) changed,
31 insertions(+),
1 deletions(-)
files
src/RawFormulas/RawFormulas.ts
tests/FormulasTest.ts
1diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
2index bb630b5..d64e672 100644
3--- a/src/RawFormulas/RawFormulas.ts
4+++ b/src/RawFormulas/RawFormulas.ts
5@@ -88,7 +88,19 @@ var COMPLEX = Formula["COMPLEX"];
6 var CONCATENATE = Formula["CONCATENATE"];
7 var CONVERT = Formula["CONVERT"];
8 var CORREL = Formula["CORREL"];
9-var COS = Formula["COS"];
10+
11+/**
12+ * Returns the cosine of an angle provided in radians.
13+ * @param values[0] The angle to find the cosine of, in radians.
14+ * @returns {number} cosine of angle
15+ * @constructor
16+ */
17+var COS = function (...values) : number {
18+ checkArgumentsLength(values, 1);
19+ var rad = firstValueAsNumber(values[0]);
20+ return Math.cos(rad);
21+};
22+
23 var COSH = Formula["COSH"];
24 var COT = Formula["COT"];
25 var COTH = Formula["COTH"];
26diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
27index 2d1662b..7bac297 100644
28--- a/tests/FormulasTest.ts
29+++ b/tests/FormulasTest.ts
30@@ -349,7 +349,25 @@ assertEquals(CONVERT(5.1, "mm", "m"), 0.0050999999999999995);
31
32 assertEquals(CORREL([9, 5],[10, 4]), 1);
33
34+
35+// Test COS
36 assertEquals(COS(PI()), -1);
37+assertEquals(COS(1), 0.5403023058681398);
38+assertEquals(COS(false), 1);
39+assertEquals(COS(true), 0.5403023058681398);
40+assertEquals(COS(""), 1);
41+assertEquals(COS("0"), 1);
42+catchAndAssertEquals(function() {
43+ COS("str");
44+}, ERRORS.VALUE_ERROR);
45+catchAndAssertEquals(function() {
46+ COS();
47+}, ERRORS.NA_ERROR);
48+catchAndAssertEquals(function() {
49+ COS(1, 1);
50+}, ERRORS.NA_ERROR);
51+assertEquals(COS([0, "str"]), 1);
52+
53
54 assertEquals(COSH(PI()), 11.591953275521522);
55