generated from reprograma/onX-sx-temaX
-
Notifications
You must be signed in to change notification settings - Fork 38
semana 8 #32
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
Open
DamarisSantos
wants to merge
2
commits into
reprograma:main
Choose a base branch
from
DamarisSantos: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
semana 8 #32
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,27 @@ | ||
| from Livro import Livro | ||
|
|
||
| class Biblioteca: | ||
| def __init__(self): | ||
| self.livros = [] | ||
| #raise NotImplementedError | ||
|
|
||
| def adicionar_livro(self, livro: Livro): | ||
| if (not isinstance(livro, Livro)): | ||
| raise TypeError(f'Esperado Livro obtido valor {livro} do tipo {type(livro)}') | ||
| self.livros.append(livro) | ||
|
|
||
| #resolução projeto | ||
| def exibir_livro(self): | ||
| return self.livros | ||
|
|
||
|
|
||
| def emprestar_livro(self, nome_livro): | ||
| #return (self.nome, self.autor) | ||
| for livro in self.livros: | ||
| if livro.nome == nome_livro: | ||
| livro.esta_emprestado = True | ||
| else: | ||
| return ("Livro indisponível") | ||
|
|
||
|
|
||
|
|
This file contains hidden or 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,7 @@ | ||
| class Livro: | ||
| def __init__(self, nome, autor): | ||
|
|
||
| self.nome = nome | ||
| self.autor = autor | ||
| self.esta_emprestado = False | ||
| #NotImplementedError |
Empty file.
This file contains hidden or 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 import Biblioteca | ||
| from Livro import Livro | ||
|
|
||
| nome_livro = "O vendedor de sonhos" | ||
| autor_livro = "Augusto Cury" | ||
| livro_objeto = Livro(nome = nome_livro, autor = autor_livro) | ||
|
|
||
| biblioteca_objeto = Biblioteca() | ||
|
|
||
| print(biblioteca_objeto.livros) | ||
|
|
||
| biblioteca_objeto.adicionar_livro(livro_objeto) | ||
|
|
||
| for livro in biblioteca_objeto.livros: | ||
| print(livro.nome) | ||
| print(livro.autor) | ||
|
|
This file contains hidden or 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,59 @@ | ||
| from unittest import TestCase | ||
| from Biblioteca import Biblioteca | ||
| from Livro import Livro | ||
|
|
||
| class testBiblioteca(TestCase): | ||
| def setUp(self): | ||
| self.biblioteca = Biblioteca() | ||
|
|
||
| def test_init_deve_passar(self): | ||
| # Arrange / Act | ||
| #biblioteca = Biblioteca() | ||
|
|
||
| # Assert | ||
| self.assertIsInstance(self.biblioteca.livros, list) | ||
|
|
||
| def test_adicionar_livro_deve_passar(self): | ||
| #Arrange | ||
| # biblioteca = Biblioteca() | ||
| nome_livro = "O vendedor de sonhos" | ||
| autor_livro = "Augusto Cury" | ||
| livro = Livro(nome_livro, autor_livro) | ||
|
|
||
| #Act | ||
| self.biblioteca.adicionar_livro(livro) | ||
| #Assert | ||
| self.assertEqual(1, len(self.biblioteca.livros)) | ||
|
|
||
| def test_adicionar_livro_nao_deve_inserir_numeros(self): | ||
| #Arrange | ||
| #biblioteca = Biblioteca() | ||
| livro = 1988 | ||
|
|
||
| # Assert / Act | ||
| with self.assertRaises(TypeError): | ||
| self.biblioteca.adicionar_livro(livro) | ||
|
|
||
| def test_exibir_livro_deve_mostrar(self): | ||
| #Arrange | ||
| nome_livro = "O vendedor de sonhos" | ||
| autor_livro = "Augusto Cury" | ||
| livro = Livro(nome_livro, autor_livro) | ||
| self.biblioteca.adicionar_livro(livro) | ||
| #Act | ||
| lista_livros = self.biblioteca.exibir_livro() | ||
| #Assert | ||
| self.assertEqual(1, len(lista_livros)) | ||
|
|
||
| def test_emprestar_livro_deve_emprestar(self): | ||
| #Arrange | ||
| nome_livro = "O vendedor de sonhos" | ||
| autor_livro = "Augusto Cury" | ||
| livro = Livro(nome_livro, autor_livro) | ||
| self.biblioteca.emprestar_livro(livro) | ||
| #Act | ||
| self.biblioteca.emprestar_livro(nome_livro = 'O vendedor de sonhos') | ||
| #Assert | ||
| self.assertTrue(self.biblioteca.emprestar_livro) | ||
|
|
||
|
|
||
This file contains hidden or 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 unittest import TestCase | ||
| from Livro import Livro | ||
|
|
||
| class TestLivro(TestCase): | ||
| def test_init_deve_passar(self): | ||
| # Arrange | ||
| nome = "Mindset" | ||
| autor = "Carol Dweck" | ||
| # Act | ||
| livro = Livro(nome, autor) | ||
| # Assert | ||
| self.assertEqual(nome, livro.nome) | ||
| self.assertEqual(autor, livro.autor) | ||
| self.assertEqual(False, livro.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.
Os testes mostram bastante coesão com a entrega!
Só tem um ponto de atenção nessa linha: no seu método emprestar_livro caso o livro esteja na lista biblioteca.livros vc não retorna nada (ou retorna None).
Somado a esse fato esse assertTrue está te retornando um falso positivo
Isso foi uma surpresa até para mim mas a documentação explica:
"Observe que isso é equivalente a bool(expr) is True e não a expr is True (use assertIs(expr, True) para o último)."Portanto caso queira que seu método retorne True quando o livro é encontrado e emprestado (teria que modificar o metodo também) um assert sugerido para esse teste seria:
self.assertIs(self.biblioteca.emprestar_livro, True)ou fazer um assert com o tipo None ( self.assertIsNone() )