-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from tatilimongi/Marlon-+-Victor
Implementação dos Módulos de Lançamento de Notas, Cálculo de Média e Exibição de Status, e Testes Unitários Correspondentes
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const { lancarNotas } = require("../sistema-academico/lancamentoNotas"); | ||
|
||
function calcularMedia(up1, up2) { | ||
const notas = lancarNotas(up1, up2); | ||
const media = (notas.up1 + notas.up2) / 2; | ||
return Math.round(media * 10) / 10; | ||
} | ||
|
||
module.exports = { calcularMedia }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { calcularMedia } = require("../sistema-academico/calcularMedia"); | ||
|
||
function determinarStatus(up1, up2){ | ||
const media = calcularMedia(up1, up2); | ||
if (media < 4.0){ | ||
return "Reprovado por média" | ||
} | ||
else if (media >= 6.0){ | ||
return "Aprovado por média"; | ||
} | ||
else{ | ||
return "Aguardando a final" | ||
} | ||
} | ||
|
||
module.exports = { determinarStatus } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function lancarNotas(up1, up2) { | ||
if (typeof up1 !== 'number' || typeof up2 !== 'number') { | ||
throw new Error("Entradas devem ser numéricas"); | ||
} | ||
|
||
if (up1 < 0 || up1 > 10) { | ||
throw new Error("Nota de 1UP inválida"); | ||
} | ||
if (up2 < 0 || up2 > 10) { | ||
throw new Error("Nota de 2UP inválida"); | ||
} | ||
|
||
if (up1.toFixed(1) !== up1.toString()) { | ||
throw new Error("Nota de 1UP inválida"); | ||
} | ||
if (up2.toFixed(1) !== up2.toString()) { | ||
throw new Error("Nota de 2UP inválida"); | ||
} | ||
|
||
return { up1, up2, mensagem: "Notas salvas com sucesso" }; | ||
} | ||
|
||
module.exports = { lancarNotas }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { calcularMedia } = require("../calcularMedia"); | ||
const { lancarNotas } = require("../lancamentoNotas"); | ||
|
||
jest.mock("../lancamentoNotas", () => ({ | ||
lancarNotas: jest.fn(), | ||
})); | ||
|
||
describe("Suíte de testes para a função calcularMedia", () => { | ||
test("Deve calcular a média corretamente para notas válidas de 1UP e 2UP", () => { | ||
lancarNotas.mockReturnValue({ up1: 7.5, up2: 8.2 }); | ||
const resultado = calcularMedia(7.5, 8.2); | ||
expect(resultado).toBeCloseTo(7.9, 1); | ||
}); | ||
test("Deve calcular a média corretamente para notas iguais de 1UP e 2UP", () => { | ||
lancarNotas.mockReturnValue({ up1: 5.0, up2: 5.0 }); | ||
const resultado = calcularMedia(5.0, 5.0); | ||
expect(resultado).toBe(5.0); | ||
}); | ||
test("Deve calcular a média corretamente para a nota mínima e máxima", () => { | ||
lancarNotas.mockReturnValue({ up1: 0.0, up2: 10.0 }); | ||
const resultado = calcularMedia(0.0, 10.0); | ||
expect(resultado).toBe(5.0); | ||
}); | ||
test("Deve calcular a média corretamente para a nota de 1UP no limite inferior", () => { | ||
lancarNotas.mockReturnValue({ up1: 0.0, up2: 7.0 }); | ||
const resultado = calcularMedia(0.0, 7.0); | ||
expect(resultado).toBe(3.5); | ||
}); | ||
test("Deve calcular a média corretamente para a nota de 2UP no limite superior", () => { | ||
lancarNotas.mockReturnValue({ up1: 8.0, up2: 10.0 }); | ||
const resultado = calcularMedia(8.0, 10.0); | ||
expect(resultado).toBe(9.0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { determinarStatus } = require('../exibirStatus'); | ||
const { calcularMedia } = require('../calcularMedia'); | ||
|
||
// Mock da função calcularMedia | ||
jest.mock('../calcularMedia', () => ({ | ||
calcularMedia: jest.fn(), | ||
})); | ||
|
||
describe('Suíte de testes para a função determinarStatus', () => { | ||
test('Deve retornar "Reprovado por média" para média inferior a 4.0', () => { | ||
calcularMedia.mockReturnValue(3.5); | ||
expect(determinarStatus(3, 4)).toBe("Reprovado por média"); | ||
}); | ||
test('Deve retornar "Aguardando a final" para média igual a 4.0', () => { | ||
calcularMedia.mockReturnValue(4.0); | ||
expect(determinarStatus(4, 4)).toBe("Aguardando a final"); | ||
}); | ||
test('Deve retornar "Aguardando a final" para média entre 4.0 e 6.0', () => { | ||
calcularMedia.mockReturnValue(5.5); | ||
expect(determinarStatus(5, 6)).toBe("Aguardando a final"); | ||
}); | ||
test('Deve retornar "Aprovado por média" para média igual a 6.0', () => { | ||
calcularMedia.mockReturnValue(6.0); | ||
expect(determinarStatus(6, 6)).toBe("Aprovado por média"); | ||
}); | ||
test('Deve retornar "Aprovado por média" para média superior a 6.0', () => { | ||
calcularMedia.mockReturnValue(7.5); | ||
expect(determinarStatus(7, 8)).toBe("Aprovado por média"); | ||
}); | ||
test('Deve retornar "Reprovado por média" para média no limite inferior (0.0)', () => { | ||
calcularMedia.mockReturnValue(0.0); | ||
expect(determinarStatus(0, 0)).toBe("Reprovado por média"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const { lancarNotas } = require("../lancamentoNotas"); | ||
|
||
test('Notas válidas', () => { | ||
const resultado = lancarNotas(7.5, 8.2); | ||
expect(resultado).toEqual({ up1: 7.5, up2: 8.2, mensagem: "Notas salvas com sucesso" }); | ||
}); | ||
|
||
test('Nota de 1UP fora do intervalo', () => { | ||
expect(() => lancarNotas(-1.0, 8.2)).toThrow('Nota de 1UP inválida'); | ||
}); | ||
|
||
test('Nota de 2UP fora do intervalo', () => { | ||
expect(() => lancarNotas(7.5, 12.0)).toThrow('Nota de 2UP inválida'); | ||
}); | ||
|
||
test('Nota de 1UP com mais de uma casa decimal', () => { | ||
expect(() => lancarNotas(7.567, 8.2)).toThrow('Nota de 1UP inválida'); | ||
}); | ||
|
||
test('Nota de 2UP com mais de uma casa decimal', () => { | ||
expect(() => lancarNotas(7.5, 8.256)).toThrow('Nota de 2UP inválida'); | ||
}); | ||
|
||
test('Entradas não numéricas', () => { | ||
expect(() => lancarNotas('sete', 8.2)).toThrow('Entradas devem ser numéricas'); | ||
}); |