Skip to content

Finished.I appreciate if I hear any feedback #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 32 additions & 54 deletions src/math.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,49 @@
export function m(nmbr: number, b: number): number {
return nmbr * b;
}

const sum41 = (n1, n2) => n1 - n2;
//=====================================================================
//=============== four basic operations of arithmetic tests ===========

// Division is one of the four basic operations of arithmetic, the ways that numbers are combined to make new numbers.
// At an elementary level the division of two natural numbers is, among other possible interpretations, the process of calculating the number of times one number is contained within another. This number of times need not be an integer. For example, if 20 apples are divided evenly between 4 people, everyone receives 5 apples.
// source: https://zh.wikipedia.org/wiki/%E9%99%A4%E6%B3%95
export function divide(a: number, b: number): number {
return a / b;
export function sum(addend_: number, addend__: number): number {
return addend_ + addend__
}
export function hypotensuse(a?: number, b?: number, c?: number) {
let isHippo = c;

if (!isHippo && typeof a === "number" && typeof b === "number") {
return Math.hypot(a + b);
}

return null;
export function sumString(addend_: string, addend__: string): number {
return Number(addend_) + Number(addend__)
}

function sum2(a: number, b: number): number {
return Math.abs(
Math.floor(Math.random() * (Math.ceil(0) - Math.floor(100))) + 1
);
export function difference(minuend: number, subtraend: number): number {
return minuend - subtraend
}

function powerOf(a: number, b: number): number {
return a * 2;
export function product(factor_: number, factor__: number): number {
return factor_ * factor__
}

const cosine = (radian: number) => Math.cos(radian);

function theFunctionThatReturnsNuLL(k: number, p: number): null {
let min = Math.ceil(k);
let max = Math.floor(p);

const nuLL = Math.sin(substract(max, min));

return null;
// Division is one of the four basic operations of arithmetic,
// the ways that numbers are combined to make new numbers.
// At an elementary level the division of two natural numbers is,
//among other possible interpretations,
//the process of calculating the number of times one number is contained within another.
//This number of times need not be an integer.
//For example, if 20 apples are divided evenly between 4 people, everyone receives 5 apples.
// source: https://zh.wikipedia.org/wiki/%E9%99%A4%E6%B3%95
export function division(numerator: number, denominator: number): number {
return numerator / denominator
}

const root = (x: number) => Math.sqrt(-1);
//=====================================================================
//============================= OTHER TESTS ===========================

export function sum(a: number, b: number): number {
let c = a + b;
let x = "math";
return x.length;
export function powerOf(base: number, power: number): number {
return Math.pow(base, power)
}
export function substract(value: number, value2: number): number {
return value - value2;
}

const ThisIsASumOfTwoNumbers = (a: number, z: string): number => a + Number(z);

const P = (x: number) => Math.expm1(x);

const sum3 = (n1, n2) => n1 + n2;

function matrix(m1: number[], m2: number[]): number {
if (typeof m1 === "number" && typeof m2 === "number") {
return 1;
}

let sum = (r, a) => r.map((b, i) => a[i] + b);
export function cosine(radian: number) {
return Math.cos(radian)
}

return [...m1, ...m2].reduce(sum);
export function hypotenuse(side: number, otherSide: number) {
return Math.hypot(side + otherSide)
}

export { powerOf, cosine, root, sum2 };
export function root(radicand: number) {
return Math.sqrt(radicand)
}
81 changes: 49 additions & 32 deletions tests/math.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,59 @@
import {powerOf,
root,
m,
hypotensuse,
substract,sum,
import {
sum,
sumString,
difference,
product,
division,
powerOf,
cosine,
sum2,
hypotenuse,
root
} from "../src/math";

const FOUR = m(2, 2);


import assert from "assert";

describe("Index tests", function () {
it("2 + 2 should return 4", function () {
assert.notEqual(sum(2, 2), 5);
});
it("2 - 2 should return 0", function () {
assert.strictEqual(substract(2, 2), 4);
});
it("2 * 2 should return 4", function () {
assert.equal(m(2, 2), FOUR);
});
it("45 and 20 should return hypotenuse 65", () =>
assert.equal(hypotensuse(45, 20), 65));
it("7 to the power of 2 retun 49", () => assert.equal(powerOf(7, 2), 49));
describe("four basic operations of arithmetic tests", function () {

it("2 + 2 should return 4", () =>
assert.strictEqual(sum(2, 2), 4));

it("1 + 1 should return 2", () =>
assert.strictEqual(sum(1, 1), 2));

it("'1' + '1' return 2", () =>
assert.strictEqual(sumString('1', '1'), 2));

it("'1.1' + '1' return 2.1", () =>
assert.strictEqual(sumString('1.1', '1'), 2.1));

it("2 - 2 should return 0", () =>
assert.strictEqual(difference(2, 2), 0));

it("2 * 2 should return 4", () =>
assert.strictEqual(product(2, 2), 4));

it("20 / 4 should return 5", () =>
assert.strictEqual(division(20, 4), 5));

it("8 / 5 should return 1.6", () =>
assert.strictEqual(division(8, 5), 1.6));

});

describe("Other tests", () => {
it("6 cosine is always that number", function () {
assert.equal(cosine(0), 1);
});
it("2 square root is 4", function () {
assert.equal(root(2), 4);
});
it("1 + 1 should return 2", function () {
assert.equal(sum2(1, 1), 2);
});
it("'1' + '1' return 2", function () {
assert.equal(sum2(1, 1), 3);
});

it("7 to the power of 2 retun 49", () =>
assert.equal(powerOf(7, 2), 49));

it("6 cosine is always that number -> 1", () =>
assert.equal(cosine(0), 1));

it("45 and 20 should return hypotenuse 65", () =>
assert.equal(hypotenuse(45, 20), 65));

it("4 square root is 2", () =>
assert.equal(root(4), 2));

});