Skip to content

Commit

Permalink
node teste em object
Browse files Browse the repository at this point in the history
  • Loading branch information
luizchaves committed Mar 10, 2024
1 parent 7b282f0 commit 7b8cd01
Show file tree
Hide file tree
Showing 34 changed files with 1,047 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
function firstTeam() {
export function firstTeam() {
// TODO
}

function showStading() {
export function showStading() {
// TODO
}

export { firstTeam, showStading };
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
import { describe, it } from 'node:test';
import assert from 'node:assert';
import { firstTeam, showStanding } from './brazilian-championship.js';

const standings = [
{
team: 'Palmeiras',
mp: 38,
w: 24,
d: 8,
l: 6,
gf: 62,
ga: 32,
gd: 30,
pts: 80,
},
{
team: 'Santos',
mp: 38,
w: 22,
d: 5,
l: 11,
gf: 59,
ga: 35,
gd: 24,
pts: 71,
},
{
team: 'Flamengo',
mp: 38,
w: 20,
d: 11,
l: 7,
gf: 52,
ga: 35,
gd: 17,
pts: 71,
},
{
team: 'Atlético Mineiro',
mp: 38,
w: 17,
d: 11,
l: 10,
gf: 61,
ga: 53,
gd: 8,
pts: 62,
},
{
team: 'Botafogo',
mp: 38,
w: 17,
d: 8,
l: 13,
gf: 43,
ga: 39,
gd: 4,
pts: 59,
},
{
team: 'Atlético-PR',
mp: 38,
w: 17,
d: 6,
l: 15,
gf: 38,
ga: 32,
gd: 6,
pts: 57,
},
{
team: 'Corinthians',
mp: 38,
w: 15,
d: 10,
l: 13,
gf: 48,
ga: 42,
gd: 6,
pts: 55,
},
{
team: 'Ponte Preta',
mp: 38,
w: 15,
d: 8,
l: 15,
gf: 48,
ga: 52,
gd: -4,
pts: 53,
},
{
team: 'Grêmio',
mp: 38,
w: 14,
d: 11,
l: 13,
gf: 41,
ga: 44,
gd: -3,
pts: 53,
},
{
team: 'São Paulo',
mp: 38,
w: 14,
d: 10,
l: 14,
gf: 44,
ga: 36,
gd: 8,
pts: 52,
},
{
team: 'Chapecoense',
mp: 38,
w: 13,
d: 13,
l: 12,
gf: 49,
ga: 56,
gd: -7,
pts: 52,
},
{
team: 'Cruzeiro',
mp: 38,
w: 14,
d: 9,
l: 15,
gf: 48,
ga: 49,
gd: -1,
pts: 51,
},
{
team: 'Fluminense',
mp: 38,
w: 13,
d: 11,
l: 14,
gf: 45,
ga: 45,
gd: 0,
pts: 50,
},
{
team: 'Sport Recife',
mp: 38,
w: 13,
d: 8,
l: 17,
gf: 49,
ga: 55,
gd: -6,
pts: 47,
},
{
team: 'Coritiba',
mp: 38,
w: 11,
d: 13,
l: 14,
gf: 41,
ga: 42,
gd: -1,
pts: 46,
},
{
team: 'Vitória',
mp: 38,
w: 12,
d: 9,
l: 17,
gf: 51,
ga: 53,
gd: -2,
pts: 45,
},
{
team: 'Internacional',
mp: 38,
w: 11,
d: 10,
l: 17,
gf: 35,
ga: 41,
gd: -6,
pts: 43,
},
{
team: 'Figueirense',
mp: 38,
w: 8,
d: 13,
l: 17,
gf: 30,
ga: 50,
gd: -20,
pts: 37,
},
{
team: 'Santa Cruz',
mp: 38,
w: 8,
d: 7,
l: 23,
gf: 45,
ga: 69,
gd: -24,
pts: 31,
},
{
team: 'América-MG',
mp: 38,
w: 7,
d: 7,
l: 24,
gf: 23,
ga: 58,
gd: -35,
pts: 28,
},
];

describe('Brazilian Championship', () => {
describe('firstTeam()', () => {
it('should get the first team', () => {
assert.equal(firstTeam(standings), 'Palmeiras');
});
});

describe('showStanding()', () => {
it('should display standings', () => {
assert.equal(
showStanding(standings),
`Palmeiras | 38 | 24 | 8 | 6 | 62 | 32 | 30 | 80
Santos | 38 | 22 | 5 | 11 | 59 | 35 | 24 | 71
Flamengo | 38 | 20 | 11 | 7 | 52 | 35 | 17 | 71
Atlético Mineiro | 38 | 17 | 11 | 10 | 61 | 53 | 8 | 62
Botafogo | 38 | 17 | 8 | 13 | 43 | 39 | 4 | 59
Atlético-PR | 38 | 17 | 6 | 15 | 38 | 32 | 6 | 57
Corinthians | 38 | 15 | 10 | 13 | 48 | 42 | 6 | 55
Ponte Preta | 38 | 15 | 8 | 15 | 48 | 52 | -4 | 53
Grêmio | 38 | 14 | 11 | 13 | 41 | 44 | -3 | 53
São Paulo | 38 | 14 | 10 | 14 | 44 | 36 | 8 | 52
Chapecoense | 38 | 13 | 13 | 12 | 49 | 56 | -7 | 52
Cruzeiro | 38 | 14 | 9 | 15 | 48 | 49 | -1 | 51
Fluminense | 38 | 13 | 11 | 14 | 45 | 45 | 0 | 50
Sport Recife | 38 | 13 | 8 | 17 | 49 | 55 | -6 | 47
Coritiba | 38 | 11 | 13 | 14 | 41 | 42 | -1 | 46
Vitória | 38 | 12 | 9 | 17 | 51 | 53 | -2 | 45
Internacional | 38 | 11 | 10 | 17 | 35 | 41 | -6 | 43
Figueirense | 38 | 8 | 13 | 17 | 30 | 50 | -20 | 37
Santa Cruz | 38 | 8 | 7 | 23 | 45 | 69 | -24 | 31
América-MG | 38 | 7 | 7 | 24 | 23 | 58 | -35 | 28`
);
});
});
});
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,12 +1,12 @@
function firstTeam(standings) {
export function firstTeam(standings) {
return standings.sort(sortTeam)[0].team;
}

function showStading(standings) {
export function showStanding(standings) {
return printTeams(standings.sort(sortTeam));
}

function sortTeam(a, b) {
export function sortTeam(a, b) {
if (a.pts > b.pts) return -1;
if (a.pts < b.pts) return 1;
if (a.w > b.w) return -1;
Expand All @@ -18,7 +18,7 @@ function sortTeam(a, b) {
return 0;
}

function printTeams(standings) {
export function printTeams(standings) {
const maxLength = standings.reduce(
(max, character) => {
const teamLength = character.team.length;
Expand All @@ -41,40 +41,22 @@ function printTeams(standings) {
max.pts = ptsLength > max.pts ? ptsLength : max.pts;
return max;
},
{ team: 0, mp: 0, w: 0, d: 0, l: 0, gf: 0, ga: 0, gd: 0, pts: 0 },
{ team: 0, mp: 0, w: 0, d: 0, l: 0, gf: 0, ga: 0, gd: 0, pts: 0 }
);

return standings
.map(row => {
.map((row) => {
return [
row.team.padEnd(maxLength.team),
Number(row.mp)
.toString()
.padStart(maxLength.mp),
Number(row.w)
.toString()
.padStart(maxLength.w),
Number(row.d)
.toString()
.padStart(maxLength.d),
Number(row.l)
.toString()
.padStart(maxLength.l),
Number(row.gf)
.toString()
.padStart(maxLength.gf),
Number(row.ga)
.toString()
.padStart(maxLength.ga),
Number(row.gd)
.toString()
.padStart(maxLength.gd),
Number(row.pts)
.toString()
.padStart(maxLength.pts),
Number(row.mp).toString().padStart(maxLength.mp),
Number(row.w).toString().padStart(maxLength.w),
Number(row.d).toString().padStart(maxLength.d),
Number(row.l).toString().padStart(maxLength.l),
Number(row.gf).toString().padStart(maxLength.gf),
Number(row.ga).toString().padStart(maxLength.ga),
Number(row.gd).toString().padStart(maxLength.gd),
Number(row.pts).toString().padStart(maxLength.pts),
].join(' | ');
})
.join('\n');
}

export { firstTeam, showStading };
Loading

0 comments on commit 7b8cd01

Please sign in to comment.