Skip to content

Commit

Permalink
node teste em function
Browse files Browse the repository at this point in the history
  • Loading branch information
luizchaves committed Mar 10, 2024
1 parent 2165dde commit e278fc1
Show file tree
Hide file tree
Showing 90 changed files with 754 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
function areaOfCircle(radius) {
export function areaOfCircle(radius) {
// TODO A = πr²
}

export { areaOfCircle };
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { areaOfCircle } from './area-of-circle.js';

describe('Circle Tools', () => {
describe('areaOfCircle()', () => {
it('should calculate the area of the circle', () => {
assert.equal(areaOfCircle(10), 314.1592653589793);
});

it('should calculate the area of the circle', () => {
assert.equal(areaOfCircle(1), 3.141592653589793);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { areaOfCircle } from "./area-of-circle-fn.js";
import { areaOfCircle } from './area-of-circle-fn.js';

// Circle Tools

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import {
areaOfCircle
} from './area-of-circle.js'
import { areaOfCircle } from './area-of-circle.js';

describe('Circle Tools', () => {

test('Area of the circle of radius 10 is of 31.41592653589793', () => {
expect(areaOfCircle(10)).toBe(314.1592653589793)
})
expect(areaOfCircle(10)).toBe(314.1592653589793);
});

test('Area of the circle of radius 1 is of 3.141592653589793', () => {
expect(areaOfCircle(1)).toBe(3.141592653589793)
})

})
expect(areaOfCircle(1)).toBe(3.141592653589793);
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// A = πr²

function areaOfCircle(radius) {
export function areaOfCircle(radius) {
return Math.PI * radius ** 2;
}

const areaOfCircleWithAnonymous = function(radius) {
export const areaOfCircleWithAnonymous = function (radius) {
return Math.PI * radius ** 2;
};

const areaOfCircleWithArrow = radius => Math.PI * radius ** 2;

export { areaOfCircle, areaOfCircleWithAnonymous, areaOfCircleWithArrow };
export const areaOfCircleWithArrow = (radius) => Math.PI * radius ** 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { areaOfCircle } from './area-of-circle.js';

describe('Circle Tools', () => {
describe('areaOfCircle()', () => {
it('should calculate the area of the circle', () => {
assert.equal(areaOfCircle(10), 314.1592653589793);
});

it('should calculate the area of the circle', () => {
assert.equal(areaOfCircle(1), 3.141592653589793);
});
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
areaOfCircle
} from './area-of-circle.js'
import { areaOfCircle } from './area-of-circle.js';

// Circle Tools

// Area of the circle of radius 10 is of 31.41592653589793
console.log(areaOfCircle(10))
console.log(314.1592653589793)
console.log(areaOfCircle(10));
console.log(314.1592653589793);

// Area of the circle of radius 1 is of 3.141592653589793
console.log(areaOfCircle(1))
console.log(3.141592653589793)
console.log(areaOfCircle(1));
console.log(3.141592653589793);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
4 changes: 1 addition & 3 deletions src/pages/exercises/function-calc/_codes/js/code/calc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/**
* operator: '+', '-', '*', '/'
*/
function calc(operand1, operand2, operator) {
export function calc(operand1, operand2, operator) {
// TODO
}

export { calc };
27 changes: 27 additions & 0 deletions src/pages/exercises/function-calc/_codes/js/code/calc.node.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { calc } from './calc.js';

describe('Calculator', () => {
describe('calc()', () => {
it('should add values', () => {
assert.equal(calc(1, 1, '+'), 2);
assert.equal(calc(10, 5, '+'), 15);
});

it('should subtract values', () => {
assert.equal(calc(1, 1, '-'), 0);
assert.equal(calc(10, 5, '-'), 5);
});

it('should multiply values', () => {
assert.equal(calc(1, 1, '*'), 1);
assert.equal(calc(10, 5, '*'), 50);
});

it('should divide values', () => {
assert.equal(calc(1, 1, '/'), 1);
assert.equal(calc(10, 5, '/'), 2);
});
});
});
3 changes: 3 additions & 0 deletions src/pages/exercises/function-calc/_codes/js/code/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
6 changes: 2 additions & 4 deletions src/pages/exercises/function-calc/_codes/js/response/calc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* operator: '+', '-', '*', '/'
*/
function calc(operand1, operand2, operator) {
export function calc(operand1, operand2, operator) {
switch (operator) {
case '+':
return parseInt(operand1) + parseInt(operand2);
Expand All @@ -16,8 +16,6 @@ function calc(operand1, operand2, operator) {

/* alternative answer. to undersand how eval works:
* https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/eval */
function calcWithEval(operand1, operand2, operator) {
export function calcWithEval(operand1, operand2, operator) {
return eval(operand1 + operator + operand2);
}

export { calc, calcWithEval };
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { calc } from './calc.js';

describe('Calculator', () => {
describe('calc()', () => {
it('should add values', () => {
assert.equal(calc(1, 1, '+'), 2);
assert.equal(calc(10, 5, '+'), 15);
});

it('should subtract values', () => {
assert.equal(calc(1, 1, '-'), 0);
assert.equal(calc(10, 5, '-'), 5);
});

it('should multiply values', () => {
assert.equal(calc(1, 1, '*'), 1);
assert.equal(calc(10, 5, '*'), 50);
});

it('should divide values', () => {
assert.equal(calc(1, 1, '/'), 1);
assert.equal(calc(10, 5, '/'), 2);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* beginWeek: 0..6 - 0(DOM), 1(SEG), 2(TER), 3(QUA), 4(QUI), 5(SEX), 6(SAB)
* endDay: 28..31
*/
function calendar(beginWeek, endDay) {
export function calendar(beginWeek, endDay) {
// TODO
}

export { calendar };
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { calendar } from './calendar.js';

describe('Calendar Tool', () => {
describe('calendar()', () => {
it('making month starting on Sunday and ending on the 31st', () => {
assert.equal(
calendar(0, 31),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05 06 07
08 09 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31`
);
});

it('making month starting on Monday and ending on the 31st', () => {
assert.equal(
calendar(1, 31),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05 06
07 08 09 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31`
);
});

it('making month starting on Tuesday and ending on the 30st', () => {
assert.equal(
calendar(2, 30),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05
06 07 08 09 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30`
);
});

it('making month starting on Wednesday and ending on the 29st', () => {
assert.equal(
calendar(3, 29),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29`
);
});

it('making month starting on Saturday and ending on the 31st', () => {
assert.equal(
calendar(6, 31),
`DOM SEG TER QUA QUI SEX SAB
01
02 03 04 05 06 07 08
09 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31`
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* beginWeek: 0..6 - 0(DOM), 1(SEG), 2(TER), 3(QUA), 4(QUI), 5(SEX), 6(SAB)
* endDay: 28..31
*/
function calendar(beginWeek, endDay) {
export function calendar(beginWeek, endDay) {
let result = 'DOM SEG TER QUA QUI SEX SAB\n';

for (let times = 0; times < beginWeek; times++) {
Expand All @@ -15,5 +15,3 @@ function calendar(beginWeek, endDay) {
result += (day + beginWeek) % 7 == 0 ? '\n' : ' ';
}
}

export { calendar };
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { calendar } from './calendar.js';

describe('Calendar Tool', () => {
describe('calendar()', () => {
it('making month starting on Sunday and ending on the 31st', () => {
assert.equal(
calendar(0, 31),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05 06 07
08 09 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31`
);
});

it('making month starting on Monday and ending on the 31st', () => {
assert.equal(
calendar(1, 31),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05 06
07 08 09 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31`
);
});

it('making month starting on Tuesday and ending on the 30st', () => {
assert.equal(
calendar(2, 30),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04 05
06 07 08 09 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30`
);
});

it('making month starting on Wednesday and ending on the 29st', () => {
assert.equal(
calendar(3, 29),
`DOM SEG TER QUA QUI SEX SAB
01 02 03 04
05 06 07 08 09 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29`
);
});

it('making month starting on Saturday and ending on the 31st', () => {
assert.equal(
calendar(6, 31),
`DOM SEG TER QUA QUI SEX SAB
01
02 03 04 05 06 07 08
09 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31`
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
function factorial(number) {
export function factorial(number) {
// TODO
}

export { factorial };
Loading

0 comments on commit e278fc1

Please sign in to comment.