Skip to content

Commit

Permalink
added more tests to test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Dec 11, 2022
1 parent 081d05c commit 239d54a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ const {
compare,
compare_positive,
constants,
cosine_radians,
count_decimal_digits,
count_integer_digits,
cube,
cube_root,
divide,
eulers_number,
Expand Down Expand Up @@ -50,6 +52,7 @@ const {
round_last_decimal,
simplify_fraction,
sign,
sine_radians,
softmax,
sort,
square,
Expand All @@ -61,6 +64,22 @@ const {

// const nthroot = (radicand, root) => Math.pow(radicand, 1 / root);

test("cosine_radians", ({ eq }) => {
eq(cosine_radians("0.4014257", { steps: 10 }).startsWith("0.9205048643767727"), true);
eq(cosine_radians("-0"), "0");
eq(cosine_radians("0"), "0");
eq(Number(cosine_radians("1", { max_decimal_digits: 200, steps: 10 })), 0.5403023058681398);
eq(round(cosine_radians((2 * Math.PI).toString()), 10), "1");
});

test("sine", ({ eq }) => {
eq(sine_radians("0.4014257", { steps: 10 }).startsWith("0.3907311027531584"), true);
eq(sine_radians("-0"), "0");
eq(sine_radians("0"), "0");
eq(sine_radians("1").startsWith("0.8414709848078965"), true);
eq(Number(sine_radians((Math.PI / 2).toString())), 1);
});

test("hypotenuse", ({ eq }) => {
// some examples from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
eq(hypotenuse(), "0");
Expand Down Expand Up @@ -163,6 +182,10 @@ test("softmax", ({ eq }) => {
eq(softmax(actual, { max_decimal_digits: 8 }), expected);
});

test("root_integer_digits", ({ eq }) => {
eq(root_integer_digits("100", "2"), "2");
});

test("root", ({ eq }) => {
eq(root("-9", "1"), "-9");
eq(root("-0.25", "1"), "-0.25");
Expand All @@ -173,11 +196,29 @@ test("root", ({ eq }) => {
eq(root("-343", "3"), "-7");
});

test("cube", ({ eq }) => {
eq(cube("8"), "512");
eq(cube("-343", { max_decimal_digits: 4 }), "-40353607");
});

test("cube_root", ({ eq }) => {
eq(cube_root("8"), "2");
eq(cube_root("-343", { max_decimal_digits: 4 }), "-7");
});

test("square", ({ eq }) => {
eq(square("-9i"), "81");
eq(square("-9"), "81");
eq(square("-2", { max_decimal_digits: 4 }), "4");
eq(square("-1"), "1");
eq(square("-0.25"), "0.0625");
eq(square("-0"), "0");
eq(square("0"), "0");
eq(square("1"), "1");
eq(square("4"), "16");
eq(square("9"), "81");
});

test("square_root", ({ eq }) => {
eq(square_root("-9"), "3i");
eq(square_root("-2", { max_decimal_digits: 4 }), "1.4142i");
Expand Down

0 comments on commit 239d54a

Please sign in to comment.