-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adicionado o Teste unitário e a Resolução de operações básicas. #23
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class ContaBancaria { | ||
constructor(titular, saldoAtual, limiteExtraParaSaque) { | ||
this.titular = titular; | ||
this.saldoAtual = saldoAtual; | ||
this.limiteExtraParaSaque = limiteExtraParaSaque; | ||
} | ||
|
||
validarLimiteExtraParaSaque(limiteExtraParaSaque) { | ||
if (limiteExtraParaSaque < 0) { | ||
throw new Error('Valor Limite Não Pode Ser Negativo'); | ||
} | ||
} | ||
|
||
consultarSaldoAtual() { | ||
return this.saldoAtual; | ||
} | ||
|
||
depositarValor(valorDaOperacao) { | ||
return this.saldoAtual += valorDaOperacao; | ||
} | ||
|
||
retirarValor(valorDaOperacao) { | ||
|
||
if ((this.saldoAtual + this.limiteExtraParaSaque) < valorDaOperacao) { | ||
throw new Error('Saldo insuficiente'); | ||
} else { | ||
this.saldoAtual -= valorDaOperacao; | ||
} | ||
|
||
return this.consultarSaldoAtual() | ||
} | ||
|
||
} | ||
|
||
module.exports = ContaBancaria |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Os nomes dos testes são curtos e descritivos, o que é bom. Como sugestão, eu diria para deixa-los ainda mais descritivos, indicando exatamente o que está sendo testado.
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,31 @@ | ||||||
const contaBancaria = require("./resolucao") | ||||||
|
||||||
describe("Conta Bancária", () => { | ||||||
let conta | ||||||
beforeEach(() => { | ||||||
conta = new contaBancaria("Luiz", 10000, 2) | ||||||
}) | ||||||
|
||||||
// Consulta | ||||||
test("Validar consulta do saldo", () => { expect(conta.consultarSaldoAtual()).toEqual(10000) }) | ||||||
|
||||||
// Saque | ||||||
test("Validar erro de saldo insuficiente", () => { | ||||||
expect(() => { conta.retirarValor(11000) }).toThrow() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Ao testar se uma exceção é lançada, é útil adicionar uma mensagem de erro descritiva para explicar o que está sendo testado. Isso facilita a depuração, caso um teste falhe. |
||||||
}) | ||||||
test("Validar saque quando saldo for suficiente.", () => { | ||||||
expect(conta.retirarValor(1000)).toEqual(9000) | ||||||
}) | ||||||
|
||||||
// Depósito | ||||||
test("Validar atualização correta do saldo, após receber um depósito", () => { | ||||||
expect(conta.depositarValor(1000)).toEqual(11000) | ||||||
}) | ||||||
|
||||||
// Limite | ||||||
test("Validar se o valor limite é um número positivo", () => { | ||||||
expect(() => { conta.validarLimiteExtraParaSaque(-2)}).toThrow() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.