From e278fc1d20907ed1b18fa254ff7fe21162e08745 Mon Sep 17 00:00:00 2001 From: Luiz Date: Sun, 10 Mar 2024 13:30:34 -0300 Subject: [PATCH] node teste em function --- ...le.test.js => area-of-circle.jest.test.js} | 0 .../_codes/js/code/area-of-circle.js | 4 +- .../js/code/area-of-circle.node.test.js | 15 ++++ .../_codes/js/code/area-of-circle.print.js | 2 +- .../_codes/js/code/package.json | 3 + ...le.test.js => area-of-circle.jest.test.js} | 16 ++-- .../_codes/js/response/area-of-circle.js | 8 +- .../js/response/area-of-circle.node.test.js | 15 ++++ .../js/response/area-of-circle.print.js | 12 ++- .../_codes/js/response/package.json | 3 + .../code/{calc.test.js => calc.jest.test.js} | 0 .../function-calc/_codes/js/code/calc.js | 4 +- .../_codes/js/code/calc.node.test.js | 27 +++++++ .../function-calc/_codes/js/code/package.json | 3 + .../{calc.test.js => calc.jest.test.js} | 0 .../function-calc/_codes/js/response/calc.js | 6 +- .../_codes/js/response/calc.node.test.js | 27 +++++++ .../_codes/js/response/package.json | 3 + ...calendar.test.js => calendar.jest.test.js} | 0 .../_codes/js/code/calendar.js | 4 +- .../_codes/js/code/calendar.node.test.js | 68 +++++++++++++++++ .../_codes/js/code/package.json | 3 + ...calendar.test.js => calendar.jest.test.js} | 0 .../_codes/js/response/calendar.js | 4 +- .../_codes/js/response/calendar.node.test.js | 68 +++++++++++++++++ .../_codes/js/response/package.json | 3 + ...ctorial.test.js => factorial.jest.test.js} | 0 .../_codes/js/code/factorial.js | 4 +- .../_codes/js/code/factorial.node.test.js | 17 +++++ .../_codes/js/code/package.json | 3 + ...ctorial.test.js => factorial.jest.test.js} | 0 .../_codes/js/response/factorial.js | 6 +- .../_codes/js/response/factorial.node.test.js | 17 +++++ .../_codes/js/response/package.json | 3 + ....test.js => fibonacci-number.jest.test.js} | 0 .../_codes/js/code/fibonacci-number.js | 4 +- .../js/code/fibonacci-number.node.test.js | 19 +++++ .../_codes/js/code/package.json | 3 + ....test.js => fibonacci-number.jest.test.js} | 0 .../_codes/js/response/fibonacci-number.js | 6 +- .../js/response/fibonacci-number.node.test.js | 19 +++++ .../_codes/js/response/package.json | 3 + ...est.js => fibonacci-sequence.jest.test.js} | 0 .../_codes/js/code/fibonacci-sequence.js | 4 +- .../js/code/fibonacci-sequence.node.test.js | 19 +++++ .../_codes/js/code/package.json | 3 + ...est.js => fibonacci-sequence.jest.test.js} | 0 .../_codes/js/response/fibonacci-sequence.js | 4 +- .../response/fibonacci-sequence.node.test.js | 19 +++++ .../_codes/js/response/package.json | 3 + ...-text.test.js => figure-text.jest.test.js} | 0 .../_codes/js/code/figure-text.js | 12 ++- .../_codes/js/code/figure-text.node.test.js | 75 +++++++++++++++++++ .../_codes/js/code/package.json | 3 + ...-text.test.js => figure-text.jest.test.js} | 0 .../_codes/js/response/figure-text.js | 11 ++- .../js/response/figure-text.node.test.js | 75 +++++++++++++++++++ .../_codes/js/response/package.json | 3 + .../_codes/js/code/package.json | 3 + ...ime-nth.test.js => prime-nth.jest.test.js} | 0 .../_codes/js/code/prime-nth.js | 4 +- .../_codes/js/code/prime-nth.node.test.js | 13 ++++ .../_codes/js/response/package.json | 3 + ...ime-nth.test.js => prime-nth.jest.test.js} | 0 .../_codes/js/response/prime-nth.js | 6 +- .../_codes/js/response/prime-nth.node.test.js | 13 ++++ .../_codes/js/code/package.json | 3 + .../{prime.test.js => prime.jest.test.js} | 0 .../function-prime/_codes/js/code/prime.js | 4 +- .../_codes/js/code/prime.node.test.js | 21 ++++++ .../_codes/js/response/package.json | 3 + .../{prime.test.js => prime.jest.test.js} | 0 .../_codes/js/response/prime.js | 7 +- .../_codes/js/response/prime.node.test.js | 21 ++++++ .../function-sum/_codes/js/code/package.json | 3 + .../js/code/{sum.test.js => sum.jest.test.js} | 0 .../function-sum/_codes/js/code/sum.js | 4 +- .../_codes/js/code/sum.node.test.js | 13 ++++ .../_codes/js/response/package.json | 3 + .../{sum.test.js => sum.jest.test.js} | 0 .../function-sum/_codes/js/response/sum.js | 4 +- .../_codes/js/response/sum.node.test.js | 13 ++++ .../_codes/js/code/package.json | 3 + ....test.js => triangle-checker.jest.test.js} | 0 .../_codes/js/code/triangle-checker.js | 4 +- .../js/code/triangle-checker.node.test.js | 32 ++++++++ .../_codes/js/response/package.json | 3 + ....test.js => triangle-checker.jest.test.js} | 0 .../_codes/js/response/triangle-checker.js | 4 +- .../js/response/triangle-checker.node.test.js | 32 ++++++++ 90 files changed, 754 insertions(+), 98 deletions(-) rename src/pages/exercises/function-area-of-circle/_codes/js/code/{area-of-circle.test.js => area-of-circle.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.node.test.js create mode 100644 src/pages/exercises/function-area-of-circle/_codes/js/code/package.json rename src/pages/exercises/function-area-of-circle/_codes/js/response/{area-of-circle.test.js => area-of-circle.jest.test.js} (50%) create mode 100644 src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.node.test.js create mode 100644 src/pages/exercises/function-area-of-circle/_codes/js/response/package.json rename src/pages/exercises/function-calc/_codes/js/code/{calc.test.js => calc.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-calc/_codes/js/code/calc.node.test.js create mode 100644 src/pages/exercises/function-calc/_codes/js/code/package.json rename src/pages/exercises/function-calc/_codes/js/response/{calc.test.js => calc.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-calc/_codes/js/response/calc.node.test.js create mode 100644 src/pages/exercises/function-calc/_codes/js/response/package.json rename src/pages/exercises/function-calendar/_codes/js/code/{calendar.test.js => calendar.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-calendar/_codes/js/code/calendar.node.test.js create mode 100644 src/pages/exercises/function-calendar/_codes/js/code/package.json rename src/pages/exercises/function-calendar/_codes/js/response/{calendar.test.js => calendar.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-calendar/_codes/js/response/calendar.node.test.js create mode 100644 src/pages/exercises/function-calendar/_codes/js/response/package.json rename src/pages/exercises/function-factorial/_codes/js/code/{factorial.test.js => factorial.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-factorial/_codes/js/code/factorial.node.test.js create mode 100644 src/pages/exercises/function-factorial/_codes/js/code/package.json rename src/pages/exercises/function-factorial/_codes/js/response/{factorial.test.js => factorial.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-factorial/_codes/js/response/factorial.node.test.js create mode 100644 src/pages/exercises/function-factorial/_codes/js/response/package.json rename src/pages/exercises/function-fibonacci-nth/_codes/js/code/{fibonacci-number.test.js => fibonacci-number.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.node.test.js create mode 100644 src/pages/exercises/function-fibonacci-nth/_codes/js/code/package.json rename src/pages/exercises/function-fibonacci-nth/_codes/js/response/{fibonacci-number.test.js => fibonacci-number.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.node.test.js create mode 100644 src/pages/exercises/function-fibonacci-nth/_codes/js/response/package.json rename src/pages/exercises/function-fibonacci-sequence/_codes/js/code/{fibonacci-sequence.test.js => fibonacci-sequence.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.node.test.js create mode 100644 src/pages/exercises/function-fibonacci-sequence/_codes/js/code/package.json rename src/pages/exercises/function-fibonacci-sequence/_codes/js/response/{fibonacci-sequence.test.js => fibonacci-sequence.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.node.test.js create mode 100644 src/pages/exercises/function-fibonacci-sequence/_codes/js/response/package.json rename src/pages/exercises/function-figure-text/_codes/js/code/{figure-text.test.js => figure-text.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-figure-text/_codes/js/code/figure-text.node.test.js create mode 100644 src/pages/exercises/function-figure-text/_codes/js/code/package.json rename src/pages/exercises/function-figure-text/_codes/js/response/{figure-text.test.js => figure-text.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-figure-text/_codes/js/response/figure-text.node.test.js create mode 100644 src/pages/exercises/function-figure-text/_codes/js/response/package.json create mode 100644 src/pages/exercises/function-prime-nth/_codes/js/code/package.json rename src/pages/exercises/function-prime-nth/_codes/js/code/{prime-nth.test.js => prime-nth.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.node.test.js create mode 100644 src/pages/exercises/function-prime-nth/_codes/js/response/package.json rename src/pages/exercises/function-prime-nth/_codes/js/response/{prime-nth.test.js => prime-nth.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.node.test.js create mode 100644 src/pages/exercises/function-prime/_codes/js/code/package.json rename src/pages/exercises/function-prime/_codes/js/code/{prime.test.js => prime.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-prime/_codes/js/code/prime.node.test.js create mode 100644 src/pages/exercises/function-prime/_codes/js/response/package.json rename src/pages/exercises/function-prime/_codes/js/response/{prime.test.js => prime.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-prime/_codes/js/response/prime.node.test.js create mode 100644 src/pages/exercises/function-sum/_codes/js/code/package.json rename src/pages/exercises/function-sum/_codes/js/code/{sum.test.js => sum.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-sum/_codes/js/code/sum.node.test.js create mode 100644 src/pages/exercises/function-sum/_codes/js/response/package.json rename src/pages/exercises/function-sum/_codes/js/response/{sum.test.js => sum.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-sum/_codes/js/response/sum.node.test.js create mode 100644 src/pages/exercises/function-triangle-checker/_codes/js/code/package.json rename src/pages/exercises/function-triangle-checker/_codes/js/code/{triangle-checker.test.js => triangle-checker.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.node.test.js create mode 100644 src/pages/exercises/function-triangle-checker/_codes/js/response/package.json rename src/pages/exercises/function-triangle-checker/_codes/js/response/{triangle-checker.test.js => triangle-checker.jest.test.js} (100%) create mode 100644 src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.node.test.js diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.test.js b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.jest.test.js similarity index 100% rename from src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.test.js rename to src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.jest.test.js diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.js b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.js index fd64f2a9..739a45d5 100644 --- a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.js +++ b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.js @@ -1,5 +1,3 @@ -function areaOfCircle(radius) { +export function areaOfCircle(radius) { // TODO A = πr² } - -export { areaOfCircle }; diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.node.test.js b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.node.test.js new file mode 100644 index 00000000..f0fb7371 --- /dev/null +++ b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.node.test.js @@ -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); + }); + }); +}); diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.print.js b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.print.js index 6d393e9d..723d0932 100644 --- a/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.print.js +++ b/src/pages/exercises/function-area-of-circle/_codes/js/code/area-of-circle.print.js @@ -1,4 +1,4 @@ -import { areaOfCircle } from "./area-of-circle-fn.js"; +import { areaOfCircle } from './area-of-circle-fn.js'; // Circle Tools diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/code/package.json b/src/pages/exercises/function-area-of-circle/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-area-of-circle/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.test.js b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.jest.test.js similarity index 50% rename from src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.test.js rename to src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.jest.test.js index 2e146095..868bce6d 100644 --- a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.test.js +++ b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.jest.test.js @@ -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) - }) - -}) \ No newline at end of file + expect(areaOfCircle(1)).toBe(3.141592653589793); + }); +}); diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.js b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.js index 3565c4ee..09e8ba63 100644 --- a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.js +++ b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.js @@ -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; diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.node.test.js b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.node.test.js new file mode 100644 index 00000000..f0fb7371 --- /dev/null +++ b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.node.test.js @@ -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); + }); + }); +}); diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.print.js b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.print.js index 55cd171b..cc4eeffd 100644 --- a/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.print.js +++ b/src/pages/exercises/function-area-of-circle/_codes/js/response/area-of-circle.print.js @@ -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) \ No newline at end of file +console.log(areaOfCircle(1)); +console.log(3.141592653589793); diff --git a/src/pages/exercises/function-area-of-circle/_codes/js/response/package.json b/src/pages/exercises/function-area-of-circle/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-area-of-circle/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-calc/_codes/js/code/calc.test.js b/src/pages/exercises/function-calc/_codes/js/code/calc.jest.test.js similarity index 100% rename from src/pages/exercises/function-calc/_codes/js/code/calc.test.js rename to src/pages/exercises/function-calc/_codes/js/code/calc.jest.test.js diff --git a/src/pages/exercises/function-calc/_codes/js/code/calc.js b/src/pages/exercises/function-calc/_codes/js/code/calc.js index d1067ffb..a516777b 100644 --- a/src/pages/exercises/function-calc/_codes/js/code/calc.js +++ b/src/pages/exercises/function-calc/_codes/js/code/calc.js @@ -1,8 +1,6 @@ /** * operator: '+', '-', '*', '/' */ -function calc(operand1, operand2, operator) { +export function calc(operand1, operand2, operator) { // TODO } - -export { calc }; diff --git a/src/pages/exercises/function-calc/_codes/js/code/calc.node.test.js b/src/pages/exercises/function-calc/_codes/js/code/calc.node.test.js new file mode 100644 index 00000000..376e79d9 --- /dev/null +++ b/src/pages/exercises/function-calc/_codes/js/code/calc.node.test.js @@ -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); + }); + }); +}); diff --git a/src/pages/exercises/function-calc/_codes/js/code/package.json b/src/pages/exercises/function-calc/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-calc/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-calc/_codes/js/response/calc.test.js b/src/pages/exercises/function-calc/_codes/js/response/calc.jest.test.js similarity index 100% rename from src/pages/exercises/function-calc/_codes/js/response/calc.test.js rename to src/pages/exercises/function-calc/_codes/js/response/calc.jest.test.js diff --git a/src/pages/exercises/function-calc/_codes/js/response/calc.js b/src/pages/exercises/function-calc/_codes/js/response/calc.js index 90f9310a..1c3a5ae0 100644 --- a/src/pages/exercises/function-calc/_codes/js/response/calc.js +++ b/src/pages/exercises/function-calc/_codes/js/response/calc.js @@ -1,7 +1,7 @@ /** * operator: '+', '-', '*', '/' */ -function calc(operand1, operand2, operator) { +export function calc(operand1, operand2, operator) { switch (operator) { case '+': return parseInt(operand1) + parseInt(operand2); @@ -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 }; diff --git a/src/pages/exercises/function-calc/_codes/js/response/calc.node.test.js b/src/pages/exercises/function-calc/_codes/js/response/calc.node.test.js new file mode 100644 index 00000000..376e79d9 --- /dev/null +++ b/src/pages/exercises/function-calc/_codes/js/response/calc.node.test.js @@ -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); + }); + }); +}); diff --git a/src/pages/exercises/function-calc/_codes/js/response/package.json b/src/pages/exercises/function-calc/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-calc/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-calendar/_codes/js/code/calendar.test.js b/src/pages/exercises/function-calendar/_codes/js/code/calendar.jest.test.js similarity index 100% rename from src/pages/exercises/function-calendar/_codes/js/code/calendar.test.js rename to src/pages/exercises/function-calendar/_codes/js/code/calendar.jest.test.js diff --git a/src/pages/exercises/function-calendar/_codes/js/code/calendar.js b/src/pages/exercises/function-calendar/_codes/js/code/calendar.js index a139b136..ee4ce761 100644 --- a/src/pages/exercises/function-calendar/_codes/js/code/calendar.js +++ b/src/pages/exercises/function-calendar/_codes/js/code/calendar.js @@ -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 }; diff --git a/src/pages/exercises/function-calendar/_codes/js/code/calendar.node.test.js b/src/pages/exercises/function-calendar/_codes/js/code/calendar.node.test.js new file mode 100644 index 00000000..ce287497 --- /dev/null +++ b/src/pages/exercises/function-calendar/_codes/js/code/calendar.node.test.js @@ -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` + ); + }); + }); +}); diff --git a/src/pages/exercises/function-calendar/_codes/js/code/package.json b/src/pages/exercises/function-calendar/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-calendar/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-calendar/_codes/js/response/calendar.test.js b/src/pages/exercises/function-calendar/_codes/js/response/calendar.jest.test.js similarity index 100% rename from src/pages/exercises/function-calendar/_codes/js/response/calendar.test.js rename to src/pages/exercises/function-calendar/_codes/js/response/calendar.jest.test.js diff --git a/src/pages/exercises/function-calendar/_codes/js/response/calendar.js b/src/pages/exercises/function-calendar/_codes/js/response/calendar.js index 10389484..4ddd3ec9 100644 --- a/src/pages/exercises/function-calendar/_codes/js/response/calendar.js +++ b/src/pages/exercises/function-calendar/_codes/js/response/calendar.js @@ -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++) { @@ -15,5 +15,3 @@ function calendar(beginWeek, endDay) { result += (day + beginWeek) % 7 == 0 ? '\n' : ' '; } } - -export { calendar }; diff --git a/src/pages/exercises/function-calendar/_codes/js/response/calendar.node.test.js b/src/pages/exercises/function-calendar/_codes/js/response/calendar.node.test.js new file mode 100644 index 00000000..ce287497 --- /dev/null +++ b/src/pages/exercises/function-calendar/_codes/js/response/calendar.node.test.js @@ -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` + ); + }); + }); +}); diff --git a/src/pages/exercises/function-calendar/_codes/js/response/package.json b/src/pages/exercises/function-calendar/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-calendar/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-factorial/_codes/js/code/factorial.test.js b/src/pages/exercises/function-factorial/_codes/js/code/factorial.jest.test.js similarity index 100% rename from src/pages/exercises/function-factorial/_codes/js/code/factorial.test.js rename to src/pages/exercises/function-factorial/_codes/js/code/factorial.jest.test.js diff --git a/src/pages/exercises/function-factorial/_codes/js/code/factorial.js b/src/pages/exercises/function-factorial/_codes/js/code/factorial.js index 67a4f21a..d7d50849 100644 --- a/src/pages/exercises/function-factorial/_codes/js/code/factorial.js +++ b/src/pages/exercises/function-factorial/_codes/js/code/factorial.js @@ -1,5 +1,3 @@ -function factorial(number) { +export function factorial(number) { // TODO } - -export { factorial }; diff --git a/src/pages/exercises/function-factorial/_codes/js/code/factorial.node.test.js b/src/pages/exercises/function-factorial/_codes/js/code/factorial.node.test.js new file mode 100644 index 00000000..c41d1329 --- /dev/null +++ b/src/pages/exercises/function-factorial/_codes/js/code/factorial.node.test.js @@ -0,0 +1,17 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { factorial } from './factorial.js'; + +describe('Number Tools', () => { + describe('factorial()', () => { + it('should calculate factorial of a number', () => { + assert.equal(factorial(1), 1); + + assert.equal(factorial(2), 2); + + assert.equal(factorial(3), 6); + + assert.equal(factorial(4), 24); + }); + }); +}); diff --git a/src/pages/exercises/function-factorial/_codes/js/code/package.json b/src/pages/exercises/function-factorial/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-factorial/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-factorial/_codes/js/response/factorial.test.js b/src/pages/exercises/function-factorial/_codes/js/response/factorial.jest.test.js similarity index 100% rename from src/pages/exercises/function-factorial/_codes/js/response/factorial.test.js rename to src/pages/exercises/function-factorial/_codes/js/response/factorial.jest.test.js diff --git a/src/pages/exercises/function-factorial/_codes/js/response/factorial.js b/src/pages/exercises/function-factorial/_codes/js/response/factorial.js index b9b68647..87f61408 100644 --- a/src/pages/exercises/function-factorial/_codes/js/response/factorial.js +++ b/src/pages/exercises/function-factorial/_codes/js/response/factorial.js @@ -1,12 +1,10 @@ -function factorial(number) { +export function factorial(number) { if (number) return number * factorial(number - 1); else return 1; } /* alternative. to understand how ternary operators works: * https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Operators/Operador_Condicional */ -function factorialWithTernary(number) { +export function factorialWithTernary(number) { return number ? number * factorial(number - 1) : 1; } - -export { factorial, factorialWithTernary }; diff --git a/src/pages/exercises/function-factorial/_codes/js/response/factorial.node.test.js b/src/pages/exercises/function-factorial/_codes/js/response/factorial.node.test.js new file mode 100644 index 00000000..c41d1329 --- /dev/null +++ b/src/pages/exercises/function-factorial/_codes/js/response/factorial.node.test.js @@ -0,0 +1,17 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { factorial } from './factorial.js'; + +describe('Number Tools', () => { + describe('factorial()', () => { + it('should calculate factorial of a number', () => { + assert.equal(factorial(1), 1); + + assert.equal(factorial(2), 2); + + assert.equal(factorial(3), 6); + + assert.equal(factorial(4), 24); + }); + }); +}); diff --git a/src/pages/exercises/function-factorial/_codes/js/response/package.json b/src/pages/exercises/function-factorial/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-factorial/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.test.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.jest.test.js similarity index 100% rename from src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.test.js rename to src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.jest.test.js diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.js index 6c539fa6..e6a80906 100644 --- a/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.js +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.js @@ -1,5 +1,3 @@ -function fibonacci(number) { +export function fibonacci(number) { // TODO } - -export { fibonacci }; diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.node.test.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.node.test.js new file mode 100644 index 00000000..8812971a --- /dev/null +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/fibonacci-number.node.test.js @@ -0,0 +1,19 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { fibonacci } from './fibonacci-number.js'; + +describe('Fibonacci series', () => { + describe('fibonacci()', () => { + it('should calculate the nth fibonacci number', () => { + assert.equal(fibonacci(0), NaN); + + assert.equal(fibonacci(1), 0); + + assert.equal(fibonacci(2), 1); + + assert.equal(fibonacci(4), 2); + + assert.equal(fibonacci(6), 5); + }); + }); +}); diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/code/package.json b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.test.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.jest.test.js similarity index 100% rename from src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.test.js rename to src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.jest.test.js diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.js index 93492145..1f9a8b41 100644 --- a/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.js +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.js @@ -1,4 +1,4 @@ -function fibonacci(number) { +export function fibonacci(number) { let a = 0; let b = 1; let temp = 1; @@ -12,9 +12,7 @@ function fibonacci(number) { number--; } else if (number == 1) return 0; - else return undefined; + else return NaN; return temp; } - -export { fibonacci }; diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.node.test.js b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.node.test.js new file mode 100644 index 00000000..8812971a --- /dev/null +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/fibonacci-number.node.test.js @@ -0,0 +1,19 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { fibonacci } from './fibonacci-number.js'; + +describe('Fibonacci series', () => { + describe('fibonacci()', () => { + it('should calculate the nth fibonacci number', () => { + assert.equal(fibonacci(0), NaN); + + assert.equal(fibonacci(1), 0); + + assert.equal(fibonacci(2), 1); + + assert.equal(fibonacci(4), 2); + + assert.equal(fibonacci(6), 5); + }); + }); +}); diff --git a/src/pages/exercises/function-fibonacci-nth/_codes/js/response/package.json b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-nth/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.test.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.jest.test.js similarity index 100% rename from src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.test.js rename to src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.jest.test.js diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.js index 6c539fa6..e6a80906 100644 --- a/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.js +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.js @@ -1,5 +1,3 @@ -function fibonacci(number) { +export function fibonacci(number) { // TODO } - -export { fibonacci }; diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.node.test.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.node.test.js new file mode 100644 index 00000000..af11ced8 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/fibonacci-sequence.node.test.js @@ -0,0 +1,19 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { fibonacci } from './fibonacci-sequence.js'; + +describe('Fibonacci series', () => { + describe('fibonacci()', () => { + it('should return the first n fibonacci numbers', () => { + assert.equal(fibonacci(0), ''); + + assert.equal(fibonacci(1), '0'); + + assert.equal(fibonacci(2), '0, 1'); + + assert.equal(fibonacci(4), '0, 1, 1, 2'); + + assert.equal(fibonacci(6), '0, 1, 1, 2, 3, 5'); + }); + }); +}); diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/package.json b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.test.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.jest.test.js similarity index 100% rename from src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.test.js rename to src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.jest.test.js diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.js index f837e1fe..dd93ffe8 100644 --- a/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.js +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.js @@ -1,4 +1,4 @@ -function fibonacci(number) { +export function fibonacci(number) { let a = 0; let b = 1; let result = `${a}, ${b}`; @@ -18,5 +18,3 @@ function fibonacci(number) { return result; } - -export { fibonacci }; diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.node.test.js b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.node.test.js new file mode 100644 index 00000000..af11ced8 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/fibonacci-sequence.node.test.js @@ -0,0 +1,19 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { fibonacci } from './fibonacci-sequence.js'; + +describe('Fibonacci series', () => { + describe('fibonacci()', () => { + it('should return the first n fibonacci numbers', () => { + assert.equal(fibonacci(0), ''); + + assert.equal(fibonacci(1), '0'); + + assert.equal(fibonacci(2), '0, 1'); + + assert.equal(fibonacci(4), '0, 1, 1, 2'); + + assert.equal(fibonacci(6), '0, 1, 1, 2, 3, 5'); + }); + }); +}); diff --git a/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/package.json b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-fibonacci-sequence/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.test.js b/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.jest.test.js similarity index 100% rename from src/pages/exercises/function-figure-text/_codes/js/code/figure-text.test.js rename to src/pages/exercises/function-figure-text/_codes/js/code/figure-text.jest.test.js diff --git a/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.js b/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.js index e51eab4a..6517cdd4 100644 --- a/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.js +++ b/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.js @@ -1,21 +1,19 @@ -function halfSquare(size) { +export function halfSquare(size) { // TODO } -function triangleText(size) { +export function triangleText(size) { // TODO } -function halfDiamondText(size) { +export function halfDiamondText(size) { // TODO } -function diamondText(size) { +export function diamondText(size) { // TODO } -function boardText(size) { +export function boardText(size) { // TODO } - -export { triangleText, halfDiamondText, diamondText, boardText }; diff --git a/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.node.test.js b/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.node.test.js new file mode 100644 index 00000000..ac5461ba --- /dev/null +++ b/src/pages/exercises/function-figure-text/_codes/js/code/figure-text.node.test.js @@ -0,0 +1,75 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { + triangleText, + halfDiamondText, + diamondText, + boardText, +} from './figure-text.js'; + +describe('Figure Text Tool', () => { + describe('triangleText()', () => { + it('making triangle text with size 1', () => { + assert.equal(triangleText(1), '#'); + }); + + it('making triangle text with size 2', () => { + assert.equal(triangleText(2), '# \n' + '##'); + }); + + it('making triangle text with size 3', () => { + assert.equal(triangleText(3), '# \n' + '## \n' + '###'); + }); + }); + + describe('halfDiamondText()', () => { + it('making half diamond text with size 1', () => { + assert.equal(halfDiamondText(1), '#'); + }); + + it('making half diamond text with size 2', () => { + assert.equal(halfDiamondText(2), '# \n' + '##\n' + '# '); + }); + + it('making half diamond text with size 3', () => { + assert.equal( + halfDiamondText(3), + '# \n' + '## \n' + '###\n' + '## \n' + '# ' + ); + }); + }); + describe('diamondText()', () => { + it('making diamond text with size 1', () => { + assert.equal(diamondText(1), '#'); + }); + + it('making diamond text with size 2', () => { + assert.equal(diamondText(2), ' # \n' + '###\n' + ' # '); + }); + + it('making diamond text with size 3', () => { + assert.equal( + diamondText(3), + ' # \n' + ' ### \n' + '#####\n' + ' ### \n' + ' # ' + ); + }); + }); + + describe('boardText()', () => { + it('making board text with size 1', () => { + assert.equal(boardText(1), '#'); + }); + + it('making board text with size 2', () => { + assert.equal(boardText(2), '# \n' + ' #'); + }); + + it('making board text with size 3', () => { + assert.equal(boardText(3), '# #\n' + ' # \n' + '# #'); + }); + + it('making board text with size 4', () => { + assert.equal(boardText(4), '# # \n' + ' # #\n' + '# # \n' + ' # #'); + }); + }); +}); diff --git a/src/pages/exercises/function-figure-text/_codes/js/code/package.json b/src/pages/exercises/function-figure-text/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-figure-text/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.test.js b/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.jest.test.js similarity index 100% rename from src/pages/exercises/function-figure-text/_codes/js/response/figure-text.test.js rename to src/pages/exercises/function-figure-text/_codes/js/response/figure-text.jest.test.js diff --git a/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.js b/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.js index 5e308754..7a6fa2f6 100644 --- a/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.js +++ b/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.js @@ -1,4 +1,4 @@ -function halfSquare(size) { +export function halfSquare(size) { let result = ''; let block = '#'; for (let row = 1; row <= size; row++) { @@ -13,7 +13,7 @@ function halfSquare(size) { return result; } -function triangleText(size) { +export function triangleText(size) { let result = ''; let block = '#'; for (let row = 1; row <= size; row++) { @@ -25,7 +25,7 @@ function triangleText(size) { return result; } -function halfDiamondText(size) { +export function halfDiamondText(size) { let result = ''; let block = '#'; for (let row = 1; row <= 2 * size - 1; row++) { @@ -37,7 +37,7 @@ function halfDiamondText(size) { return result; } -function diamondText(size) { +export function diamondText(size) { let result = ''; let block = '#'; for (let row = 1; row <= 2 * size - 1; row++) { @@ -54,7 +54,7 @@ function diamondText(size) { return result; } -function boardText(size) { +export function boardText(size) { let result = ''; let block = '#'; for (let row = 1; row <= size; row++) { @@ -66,4 +66,3 @@ function boardText(size) { return result; } -export { triangleText, halfDiamondText, diamondText, boardText }; diff --git a/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.node.test.js b/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.node.test.js new file mode 100644 index 00000000..ac5461ba --- /dev/null +++ b/src/pages/exercises/function-figure-text/_codes/js/response/figure-text.node.test.js @@ -0,0 +1,75 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { + triangleText, + halfDiamondText, + diamondText, + boardText, +} from './figure-text.js'; + +describe('Figure Text Tool', () => { + describe('triangleText()', () => { + it('making triangle text with size 1', () => { + assert.equal(triangleText(1), '#'); + }); + + it('making triangle text with size 2', () => { + assert.equal(triangleText(2), '# \n' + '##'); + }); + + it('making triangle text with size 3', () => { + assert.equal(triangleText(3), '# \n' + '## \n' + '###'); + }); + }); + + describe('halfDiamondText()', () => { + it('making half diamond text with size 1', () => { + assert.equal(halfDiamondText(1), '#'); + }); + + it('making half diamond text with size 2', () => { + assert.equal(halfDiamondText(2), '# \n' + '##\n' + '# '); + }); + + it('making half diamond text with size 3', () => { + assert.equal( + halfDiamondText(3), + '# \n' + '## \n' + '###\n' + '## \n' + '# ' + ); + }); + }); + describe('diamondText()', () => { + it('making diamond text with size 1', () => { + assert.equal(diamondText(1), '#'); + }); + + it('making diamond text with size 2', () => { + assert.equal(diamondText(2), ' # \n' + '###\n' + ' # '); + }); + + it('making diamond text with size 3', () => { + assert.equal( + diamondText(3), + ' # \n' + ' ### \n' + '#####\n' + ' ### \n' + ' # ' + ); + }); + }); + + describe('boardText()', () => { + it('making board text with size 1', () => { + assert.equal(boardText(1), '#'); + }); + + it('making board text with size 2', () => { + assert.equal(boardText(2), '# \n' + ' #'); + }); + + it('making board text with size 3', () => { + assert.equal(boardText(3), '# #\n' + ' # \n' + '# #'); + }); + + it('making board text with size 4', () => { + assert.equal(boardText(4), '# # \n' + ' # #\n' + '# # \n' + ' # #'); + }); + }); +}); diff --git a/src/pages/exercises/function-figure-text/_codes/js/response/package.json b/src/pages/exercises/function-figure-text/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-figure-text/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-prime-nth/_codes/js/code/package.json b/src/pages/exercises/function-prime-nth/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-prime-nth/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.test.js b/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.jest.test.js similarity index 100% rename from src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.test.js rename to src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.jest.test.js diff --git a/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.js b/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.js index 1014fb81..fa748828 100644 --- a/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.js +++ b/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.js @@ -4,8 +4,6 @@ import { isPrime } from '../../prime/code/prime.js'; * begin: 1..n * end: 1..n, end > begin */ -function nthPrime(nth) { +export function nthPrime(nth) { // TODO } - -export { nthPrime }; diff --git a/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.node.test.js b/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.node.test.js new file mode 100644 index 00000000..1aef8554 --- /dev/null +++ b/src/pages/exercises/function-prime-nth/_codes/js/code/prime-nth.node.test.js @@ -0,0 +1,13 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { nthPrime } from './prime-nth.js'; + +describe('Number Tools', () => { + describe('nthPrime()', () => { + it('should return the nth prime number', () => { + assert.equal(nthPrime(4), 7); + + assert.equal(nthPrime(6), 13); + }); + }); +}); diff --git a/src/pages/exercises/function-prime-nth/_codes/js/response/package.json b/src/pages/exercises/function-prime-nth/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-prime-nth/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.test.js b/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.jest.test.js similarity index 100% rename from src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.test.js rename to src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.jest.test.js diff --git a/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.js b/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.js index ff2a5218..d8890f74 100644 --- a/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.js +++ b/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.js @@ -1,10 +1,10 @@ -import { isPrime } from '../../prime/response/prime.js'; +import { isPrime } from '../../../../function-prime/_codes/js/response/prime.js'; /** * begin: 1..n * end: 1..n, end > begin */ -function nthPrime(nth) { +export function nthPrime(nth) { let result = 2; for (let number = 3, count = 1; count < nth; number++) { @@ -16,5 +16,3 @@ function nthPrime(nth) { return result; } - -export { nthPrime }; diff --git a/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.node.test.js b/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.node.test.js new file mode 100644 index 00000000..1aef8554 --- /dev/null +++ b/src/pages/exercises/function-prime-nth/_codes/js/response/prime-nth.node.test.js @@ -0,0 +1,13 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { nthPrime } from './prime-nth.js'; + +describe('Number Tools', () => { + describe('nthPrime()', () => { + it('should return the nth prime number', () => { + assert.equal(nthPrime(4), 7); + + assert.equal(nthPrime(6), 13); + }); + }); +}); diff --git a/src/pages/exercises/function-prime/_codes/js/code/package.json b/src/pages/exercises/function-prime/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-prime/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-prime/_codes/js/code/prime.test.js b/src/pages/exercises/function-prime/_codes/js/code/prime.jest.test.js similarity index 100% rename from src/pages/exercises/function-prime/_codes/js/code/prime.test.js rename to src/pages/exercises/function-prime/_codes/js/code/prime.jest.test.js diff --git a/src/pages/exercises/function-prime/_codes/js/code/prime.js b/src/pages/exercises/function-prime/_codes/js/code/prime.js index 6aeb1aef..7564d1f3 100644 --- a/src/pages/exercises/function-prime/_codes/js/code/prime.js +++ b/src/pages/exercises/function-prime/_codes/js/code/prime.js @@ -1,5 +1,3 @@ -function isPrime(number) { +export function isPrime(number) { // TODO } - -export { isPrime }; diff --git a/src/pages/exercises/function-prime/_codes/js/code/prime.node.test.js b/src/pages/exercises/function-prime/_codes/js/code/prime.node.test.js new file mode 100644 index 00000000..ef5025ce --- /dev/null +++ b/src/pages/exercises/function-prime/_codes/js/code/prime.node.test.js @@ -0,0 +1,21 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { isPrime } from './prime.js'; + +describe('Number Tools', () => { + describe('isPrime()', () => { + it('should check if a number is prime', () => { + assert.equal(isPrime(2), true); + + assert.equal(isPrime(3), true); + + assert.equal(isPrime(4), false); + + assert.equal(isPrime(5), true); + + assert.equal(isPrime(6), false); + + assert.equal(isPrime(7), true); + }); + }); +}); diff --git a/src/pages/exercises/function-prime/_codes/js/response/package.json b/src/pages/exercises/function-prime/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-prime/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-prime/_codes/js/response/prime.test.js b/src/pages/exercises/function-prime/_codes/js/response/prime.jest.test.js similarity index 100% rename from src/pages/exercises/function-prime/_codes/js/response/prime.test.js rename to src/pages/exercises/function-prime/_codes/js/response/prime.jest.test.js diff --git a/src/pages/exercises/function-prime/_codes/js/response/prime.js b/src/pages/exercises/function-prime/_codes/js/response/prime.js index 0f430a58..ec7b65df 100644 --- a/src/pages/exercises/function-prime/_codes/js/response/prime.js +++ b/src/pages/exercises/function-prime/_codes/js/response/prime.js @@ -1,7 +1,6 @@ -function isPrime(number) { +export function isPrime(number) { // for(let i = 2; i < number; i++) - for (let i = 2, s = Math.sqrt(number); i <= s; i++) if (number % i === 0) return false; + for (let i = 2, s = Math.sqrt(number); i <= s; i++) + if (number % i === 0) return false; return number !== 1; } - -export { isPrime }; diff --git a/src/pages/exercises/function-prime/_codes/js/response/prime.node.test.js b/src/pages/exercises/function-prime/_codes/js/response/prime.node.test.js new file mode 100644 index 00000000..ef5025ce --- /dev/null +++ b/src/pages/exercises/function-prime/_codes/js/response/prime.node.test.js @@ -0,0 +1,21 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { isPrime } from './prime.js'; + +describe('Number Tools', () => { + describe('isPrime()', () => { + it('should check if a number is prime', () => { + assert.equal(isPrime(2), true); + + assert.equal(isPrime(3), true); + + assert.equal(isPrime(4), false); + + assert.equal(isPrime(5), true); + + assert.equal(isPrime(6), false); + + assert.equal(isPrime(7), true); + }); + }); +}); diff --git a/src/pages/exercises/function-sum/_codes/js/code/package.json b/src/pages/exercises/function-sum/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-sum/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-sum/_codes/js/code/sum.test.js b/src/pages/exercises/function-sum/_codes/js/code/sum.jest.test.js similarity index 100% rename from src/pages/exercises/function-sum/_codes/js/code/sum.test.js rename to src/pages/exercises/function-sum/_codes/js/code/sum.jest.test.js diff --git a/src/pages/exercises/function-sum/_codes/js/code/sum.js b/src/pages/exercises/function-sum/_codes/js/code/sum.js index 424c64dc..077cf99a 100644 --- a/src/pages/exercises/function-sum/_codes/js/code/sum.js +++ b/src/pages/exercises/function-sum/_codes/js/code/sum.js @@ -1,5 +1,3 @@ -function sum(a, b) { +export function sum(a, b) { // TODO } - -export { sum }; diff --git a/src/pages/exercises/function-sum/_codes/js/code/sum.node.test.js b/src/pages/exercises/function-sum/_codes/js/code/sum.node.test.js new file mode 100644 index 00000000..d79e401d --- /dev/null +++ b/src/pages/exercises/function-sum/_codes/js/code/sum.node.test.js @@ -0,0 +1,13 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { sum } from './sum.js'; + +describe('Number Tools', () => { + describe('sum()', () => { + it('should add values', () => { + assert.equal(sum(1, 2), 3); + + assert.equal(sum(3, 2), 5); + }); + }); +}); diff --git a/src/pages/exercises/function-sum/_codes/js/response/package.json b/src/pages/exercises/function-sum/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-sum/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-sum/_codes/js/response/sum.test.js b/src/pages/exercises/function-sum/_codes/js/response/sum.jest.test.js similarity index 100% rename from src/pages/exercises/function-sum/_codes/js/response/sum.test.js rename to src/pages/exercises/function-sum/_codes/js/response/sum.jest.test.js diff --git a/src/pages/exercises/function-sum/_codes/js/response/sum.js b/src/pages/exercises/function-sum/_codes/js/response/sum.js index e51581ac..506a4134 100644 --- a/src/pages/exercises/function-sum/_codes/js/response/sum.js +++ b/src/pages/exercises/function-sum/_codes/js/response/sum.js @@ -1,5 +1,3 @@ -function sum(a, b) { +export function sum(a, b) { return a + b; } - -export { sum }; diff --git a/src/pages/exercises/function-sum/_codes/js/response/sum.node.test.js b/src/pages/exercises/function-sum/_codes/js/response/sum.node.test.js new file mode 100644 index 00000000..d79e401d --- /dev/null +++ b/src/pages/exercises/function-sum/_codes/js/response/sum.node.test.js @@ -0,0 +1,13 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { sum } from './sum.js'; + +describe('Number Tools', () => { + describe('sum()', () => { + it('should add values', () => { + assert.equal(sum(1, 2), 3); + + assert.equal(sum(3, 2), 5); + }); + }); +}); diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/code/package.json b/src/pages/exercises/function-triangle-checker/_codes/js/code/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-triangle-checker/_codes/js/code/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.test.js b/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.jest.test.js similarity index 100% rename from src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.test.js rename to src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.jest.test.js diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.js b/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.js index 1aff5f9a..3e95dd56 100644 --- a/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.js +++ b/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.js @@ -1,5 +1,3 @@ -function triangleChecker(a, b, c) { +export function triangleChecker(a, b, c) { // TODO } - -export { triangleChecker }; diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.node.test.js b/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.node.test.js new file mode 100644 index 00000000..1dd88ace --- /dev/null +++ b/src/pages/exercises/function-triangle-checker/_codes/js/code/triangle-checker.node.test.js @@ -0,0 +1,32 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { triangleChecker } from './triangle-checker.js'; + +describe('Triangle Tools', () => { + describe('triangleChecker()', () => { + it('should return equilateral', () => { + assert.equal(triangleChecker(2, 2, 2), 'equilateral'); + assert.equal(triangleChecker(10, 10, 10), 'equilateral'); + }); + + it('should return isosceles', () => { + assert.equal(triangleChecker(3, 4, 4), 'isosceles'); + assert.equal(triangleChecker(4, 3, 4), 'isosceles'); + assert.equal(triangleChecker(4, 4, 3), 'isosceles'); + assert.equal(triangleChecker(10, 10, 2), 'isosceles'); + }); + + it('should return scalene', () => { + assert.equal(triangleChecker(3, 4, 5), 'scalene'); + assert.equal(triangleChecker(10, 11, 12), 'scalene'); + assert.equal(triangleChecker(5, 4, 2), 'scalene'); + }); + + it('should check if it is invalid', () => { + assert.equal(triangleChecker(0, 0, 0), 'none'); + assert.equal(triangleChecker(3, 4, -5), 'none'); + assert.equal(triangleChecker(1, 1, 3), 'none'); + assert.equal(triangleChecker(2, 4, 2), 'none'); + }); + }); +}); diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/response/package.json b/src/pages/exercises/function-triangle-checker/_codes/js/response/package.json new file mode 100644 index 00000000..3dbc1ca5 --- /dev/null +++ b/src/pages/exercises/function-triangle-checker/_codes/js/response/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.test.js b/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.jest.test.js similarity index 100% rename from src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.test.js rename to src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.jest.test.js diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.js b/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.js index 5e4dc394..498d8db2 100644 --- a/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.js +++ b/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.js @@ -1,4 +1,4 @@ -function triangleChecker(a, b, c) { +export function triangleChecker(a, b, c) { if (a >= b + c || b >= a + c || c >= a + b) return 'none'; else switch (true) { @@ -10,5 +10,3 @@ function triangleChecker(a, b, c) { return 'isosceles'; } } - -export { triangleChecker }; diff --git a/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.node.test.js b/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.node.test.js new file mode 100644 index 00000000..1dd88ace --- /dev/null +++ b/src/pages/exercises/function-triangle-checker/_codes/js/response/triangle-checker.node.test.js @@ -0,0 +1,32 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert'; +import { triangleChecker } from './triangle-checker.js'; + +describe('Triangle Tools', () => { + describe('triangleChecker()', () => { + it('should return equilateral', () => { + assert.equal(triangleChecker(2, 2, 2), 'equilateral'); + assert.equal(triangleChecker(10, 10, 10), 'equilateral'); + }); + + it('should return isosceles', () => { + assert.equal(triangleChecker(3, 4, 4), 'isosceles'); + assert.equal(triangleChecker(4, 3, 4), 'isosceles'); + assert.equal(triangleChecker(4, 4, 3), 'isosceles'); + assert.equal(triangleChecker(10, 10, 2), 'isosceles'); + }); + + it('should return scalene', () => { + assert.equal(triangleChecker(3, 4, 5), 'scalene'); + assert.equal(triangleChecker(10, 11, 12), 'scalene'); + assert.equal(triangleChecker(5, 4, 2), 'scalene'); + }); + + it('should check if it is invalid', () => { + assert.equal(triangleChecker(0, 0, 0), 'none'); + assert.equal(triangleChecker(3, 4, -5), 'none'); + assert.equal(triangleChecker(1, 1, 3), 'none'); + assert.equal(triangleChecker(2, 4, 2), 'none'); + }); + }); +});