Skip to content
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ You can also check in your browser a report saved at `./coverage/index.html`:
>
> ― Martin Fowler

- [ ] Clean the code!
- [ ] Make tests go green!
- [ ] Open a PR!
- [X] Clean the code!
- [X] Make tests go green!
- [X] Open a PR!

## The book is on the screen

Expand Down
5 changes: 5 additions & 0 deletions README2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# reality-desafio-clean-code
# SMTC s01e04: https://www.youtube.com/watch?v=wmlMag5YTrY
# Show me your team dynamics
# ToDo: Find the errors; Fix; clean-code; Make tests go green; Open a PR
# -node; typescript; tests*
124 changes: 69 additions & 55 deletions src/math.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,85 @@
export function m(nmbr: number, b: number): number {
return nmbr * b;
// returns the sum of 2 values
export function sum(a, b): number {
return Number(a) + Number(b);
}

const sum41 = (n1, n2) => n1 - n2;

// 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;
// returns the minuend of two numbers
export function substract(a: number, b: number): number {
return a - b;
}
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;
// returns the product of 2 numbers
export function product(a: number, b: number): number {
return a * b;
}

function sum2(a: number, b: number): number {
return Math.abs(
Math.floor(Math.random() * (Math.ceil(0) - Math.floor(100))) + 1
);
// returns the quotient of two numbers
export function divide(a: number, b: number): number {
return a / b;
}

function powerOf(a: number, b: number): number {
return a * 2;
// returns the hypotensuse of two numbers
export function hypotensuse(a: number, b: number): number {
return Math.hypot(a + b);
}

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;
// returns the power of two numbers
export function powerOf(a: number, b: number): number {
return Math.pow(a,b);
}

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

export function sum(a: number, b: number): number {
let c = a + b;
let x = "math";
return x.length;
// returns the cosine of a given number
export function cosine(radian: number): number {
return Math.cos(radian);
}
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);

return [...m1, ...m2].reduce(sum);
// returns the root of a given number
export function root(a: number): number {
return Math.sqrt(a);
}

export { powerOf, cosine, root, sum2 };
// deprecated
// export { powerOf, cosine, root, sum2 };
// deprecated
/* Functions or constants not used
*****
***** export function sum2(a: number, b: number): number {
***** return a + b;
***** // return Math.abs(
***** // Math.floor(Math.random() * (Math.ceil(0) - Math.floor(100))) + 1
***** // );
***** }
*****
*****
***** const sum41 = (n1, n2) => n1 - n2;
*****
***** function theFunctionThatReturnsNuLL(k: number, p: number): number {
***** let min = Math.ceil(k);
***** let max = Math.floor(p);
*****
***** const nulo = Math.sin(substract(max, min));
*****
***** return nulo;
***** }
*****
***** 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);
*****
***** return [...m1, ...m2].reduce(sum);
***** }
*****
***** // 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
*****
*/
66 changes: 35 additions & 31 deletions tests/math.spec.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import {powerOf,
root,
m,
import {
sum,
substract,
product,
divide,
hypotensuse,
substract,sum,
powerOf,
cosine,
sum2,
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);
});
describe("Index tests", () => {
it("2 + 2 should return 4", () =>
assert.equal(sum(2, 2), 4));

it("2 - 2 should return 0", () =>
assert.equal(substract(2, 2), 0));

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

it("4 / 2 should return 2", () =>
assert.equal(divide(4, 2), 2));

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));

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

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("0 cosine is always 1", () =>
assert.equal(cosine(0), 1));

it("Square root of 9 is 3", () =>
assert.equal(root(9), 3));

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

it("'1' + '1' return 2", () =>
assert.equal(sum('1', '1'), 2));
});