Skip to content

Commit

Permalink
updated test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Nov 24, 2022
1 parent 3b4519b commit 7f0f2b9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
eulers_number,
exp,
factorial,
fraction,
floor,
// gregory_leibniz,
is_factorial,
Expand All @@ -37,13 +38,15 @@ const {
long_subtraction,
multiply,
multiply_range,
primes,
pow,
pow_positive,
remainder,
root,
root_integer_digits,
round,
round_last_decimal,
simplify_fraction,
sign,
softmax,
sort,
Expand All @@ -55,6 +58,61 @@ const {

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

test("primes", ({ eq }) => {
const results1 = primes("0", "10");
eq(results1, ["2", "3", "5", "7"]);

const results2 = primes("0", "100");
eq(results2, [
"2",
"3",
"5",
"7",
"11",
"13",
"17",
"19",
"23",
"29",
"31",
"37",
"41",
"43",
"47",
"53",
"59",
"61",
"67",
"71",
"73",
"79",
"83",
"89",
"97"
]);

const start = performance.now();
const results3 = primes("0", "1000");
const duration = performance.now() - start;
eq(duration < 1000, true);
eq(results3.length, 192);
});

test("simplify_fraction", ({ eq }) => {
eq(simplify_fraction("10", "100"), ["1", "10"]);
eq(simplify_fraction("4", "10"), ["2", "5"]);
eq(simplify_fraction("11", "22"), ["1", "2"]);
eq(simplify_fraction("1234", "22"), ["617", "11"]);
eq(simplify_fraction("57142635", "4125"), ["346319", "25"]);
});

test("fraction", ({ eq }) => {
eq(fraction(".1"), ["1", "10"]);
eq(fraction("0.25"), ["25", "100"]);
eq(fraction("0.12345678"), ["12345678", "100000000"]);
eq(fraction("12345678.9"), ["123456789", "10"]);
});

test("softmax", ({ eq }) => {
const actual = ["1", "2", "3", "4", "1", "2", "3"];
const expected = ["0.02364054", "0.06426166", "0.1746813", "0.474833", "0.02364054", "0.06426166", "0.1746813"];
Expand Down

0 comments on commit 7f0f2b9

Please sign in to comment.