generated from reprograma/onX-sx-temaX
-
Notifications
You must be signed in to change notification settings - Fork 38
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
ProjetoII_Semana8_DaniNegrao #28
Open
danisnegrao
wants to merge
1
commit into
reprograma:main
Choose a base branch
from
danisnegrao:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,25 @@ | ||
from livros_daninegrao import Livros | ||
|
||
class Biblioteca: | ||
def __init__(self): | ||
self.livros = [] | ||
|
||
def adicionar_livros(self, livros: Livros): | ||
if (not isinstance(livros, Livros)): | ||
raise TypeError(f"Esperado livros obtido valor{livros} do tipo {type(livros)}") | ||
self.livros.append(livros) | ||
|
||
def exibir_livro(self, nome_livro): | ||
livros_encontrados = [] | ||
for livro in self.livros: | ||
if livro.nome == nome_livro: | ||
livros_encontrados.append(livro) | ||
return livros_encontrados | ||
|
||
def emprestar_livro(self, nome_livro): | ||
for livro in self.livros: | ||
if livro.nome == nome_livro: | ||
self.livros.remove(livro) | ||
return livro | ||
|
||
|
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,2 @@ | ||
|
||
|
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,5 @@ | ||
class Livros: | ||
def __init__(self, nome, autor): | ||
self.nome =nome | ||
self.autor = autor | ||
self.esta_emprestado = False |
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,17 @@ | ||
from Biblioteca_daninegrao import Biblioteca | ||
from livros_daninegrao import Livros | ||
|
||
nome_livro = "O mito da beleza" | ||
autor_livro = "Naomi Wolf" | ||
livro_objeto = Livros(nome = nome_livro, autor = autor_livro) | ||
|
||
biblioteca_objeto = Biblioteca() | ||
|
||
|
||
print(biblioteca_objeto.livros) | ||
|
||
biblioteca_objeto.adicionar_livros(livro_objeto) | ||
|
||
for livro in biblioteca_objeto.livros: | ||
print(livro.nome) | ||
print(livro.autor) |
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,65 @@ | ||
from unittest import TestCase | ||
from Biblioteca_daninegrao import Biblioteca | ||
from livros_daninegrao import Livros | ||
|
||
|
||
class TestBiblioteca(TestCase): | ||
def setUp(self): | ||
self.biblioteca = Biblioteca() | ||
|
||
|
||
def test_init_deve_passar(self): | ||
#Ararange / Act | ||
#biblioteca = Biblioteca() | ||
#Assert | ||
self.assertIsInstance(self.biblioteca.livros, list) | ||
|
||
def test_adicionar_livros_deve_passar(self): | ||
#Arrange | ||
#biblioteca = Biblioteca() | ||
nome_livro = "O demônio e a srtª Prym" | ||
autor_livro = "Paulo Coelho" | ||
livros = Livros(nome_livro, autor_livro) | ||
|
||
#Act | ||
self.biblioteca.adicionar_livros(livros) | ||
|
||
#Assert | ||
self.assertEqual(1, len(self.biblioteca.livros)) | ||
|
||
def test_adicionar_livro_nao_deve_inserir_numero(self): | ||
#Arrange | ||
#biblioteca = Biblioteca() | ||
livros = 1998 | ||
#Act/Assert | ||
with self.assertRaises(TypeError): | ||
self.biblioteca.adicionar_livros(livros) | ||
|
||
|
||
def test_exibir_livro_deve_passar(self): | ||
# Arrange | ||
nome_livro = "Dom Casmurro" | ||
autor_livro = "Machado de Assis" | ||
livro = Livros(nome_livro, autor_livro) | ||
self.biblioteca.adicionar_livros(livro) | ||
|
||
# Act | ||
resultado = self.biblioteca.exibir_livro(nome_livro) | ||
|
||
# Assert | ||
self.assertEqual(1, len(resultado)) | ||
self.assertEqual(livro, resultado[0]) | ||
|
||
def test_emprestar_livro_deve_passar(self): | ||
# Arrange | ||
nome_livro = "A Moreninha" | ||
autor_livro = "Joaquim Manuel de Macedo" | ||
livro = Livros(nome_livro, autor_livro) | ||
self.biblioteca.adicionar_livros(livro) | ||
|
||
# Act/Assert | ||
self.biblioteca.emprestar_livro(nome_livro) | ||
|
||
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. Aqui parece estar faltando o assert para o método de emprestar_livro |
||
|
||
|
||
|
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,14 @@ | ||
from unittest import TestCase | ||
from livros_daninegrao import Livros | ||
|
||
class TestLivros(TestCase): | ||
def test_init_deve_passar(self): | ||
#Arrange | ||
nome = "Meu pé de laranja lima" | ||
autor = "José Mauro de Vasconcelos" | ||
#Act | ||
livros = Livros(nome, autor) | ||
#Assert | ||
self.assertEqual(nome, livros.nome) | ||
self.assertEqual(autor, livros.autor) | ||
self.assertAlmostEqual(False, livros.esta_emprestado) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Acredito que aqui tenha tido um equivoco, uma troca da implementação do método emprestar_livro com o remover_livro.
O esperado para o método emprestar_livro é:
"O método deve marcar o valor de esta_emprestado como True"