generated from reprograma/onX-sx-temaX
-
Notifications
You must be signed in to change notification settings - Fork 38
exercicio semana 8 #34
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
juliabretas
wants to merge
1
commit into
reprograma:main
Choose a base branch
from
juliabretas: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
Empty file.
Empty file.
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,31 @@ | ||
| from livro import Livro | ||
|
|
||
| class Biblioteca: | ||
| def __init__(self): | ||
| self.livro = [] | ||
|
|
||
| def add_livro(self, livro: Livro): | ||
| if (isinstance(livro,Livro) == False): | ||
| raise TypeError(f"Esperado Livro obtido valor {livro} do tipo{type(livro)}") | ||
| self.livro.append(livro) | ||
|
|
||
| def exibir_livros(self): | ||
| if len(self.livro) == 0: #verifica se a list esta vzia | ||
| raise TypeError("Lista Vazia") | ||
|
Collaborator
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. [Apenas uma sugestão] Que acha de no lugar de TypeError usar o IndexError |
||
| else: return self.livro | ||
|
|
||
| def emprestar_livro(self, livro: Livro): | ||
| if(livro.emprestado == True): | ||
| raise TypeError("Esse livro ja esta emprestado") | ||
| else: | ||
| livro.emprestado = True | ||
| return livro | ||
|
|
||
| def devolver_livro(self, livro: Livro): | ||
| if(livro.emprestado == False): | ||
| raise TypeError("Este livro encotra-se na biblioteca") | ||
| else: | ||
| livro.emprestado = False | ||
| return 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,8 @@ | ||
| class Livro: | ||
| def __init__(self, nome, autor, emprestado): | ||
| #raise NotImplementedError #bota-se enquanto nao configura-se o teste | ||
| self.nome = nome | ||
| self.autor = autor | ||
| self.emprestado = emprestado | ||
|
|
||
|
|
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,22 @@ | ||
| from biblioteca import Biblioteca | ||
| from livro import Livro | ||
| from testBiblioteca import TestBiblioteca | ||
|
|
||
|
|
||
| livro_objeto = Livro(nome="Torto Arado", autor="Itamar Vieira", emprestado=False) | ||
| livro2_objeto = Livro(nome="Entendendo algoritmo", autor="Aditya", emprestado=False) | ||
| biblioteca_objeto = Biblioteca() | ||
| lista = [livro_objeto,livro2_objeto] | ||
| for livro in lista: | ||
| biblioteca_objeto.add_livro(livro) | ||
|
|
||
|
|
||
| for livros in biblioteca_objeto.exibir_livros(): | ||
| print(f"Nome: {livros.nome} Autor: {livros.autor} Emprestado: {livros.emprestado}") | ||
|
|
||
| emprestar = biblioteca_objeto.emprestar_livro(livro_objeto) | ||
| if(emprestar.emprestado == True): | ||
| print(f"O Livro: {emprestar.nome} foi emprestado com sucesso") | ||
|
|
||
|
|
||
|
|
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,55 @@ | ||
| from unittest import TestCase | ||
| from biblioteca import Biblioteca | ||
| from livro import Livro | ||
|
|
||
|
|
||
| class TestBiblioteca(TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.biblioteca = Biblioteca() #com o self. na frente é comunicado que agora biblioteca é uma variável da classe | ||
|
|
||
|
|
||
| def test_init_deve_passar(self): | ||
| # Arrange / Act | ||
| #biblioteca = Biblioteca() | ||
| # Assert | ||
| self.assertIsInstance(self.biblioteca.livro, list) #biblioteca.livros diz que a biclioteca contem os livros | ||
|
|
||
|
|
||
| def test_add_livro_deve_passar(self): | ||
| #Arrange | ||
| #biblioteca = Biblioteca() | ||
| livro = Livro(nome="Torto Arado", autor="Itamar Vieira", emprestado=False) | ||
| #Act | ||
| self.biblioteca.add_livro(livro) | ||
| #Assert | ||
| self.assertEqual(1, len(self.biblioteca.livro)) | ||
|
|
||
| def test_exibir_livro_deve_passar(self): | ||
| #Arrange | ||
| #biblioteca = Biblioteca() | ||
| livro1 = Livro(nome="Torto Arado", autor="Itamar Vieira", emprestado=False) | ||
| livro2 = Livro(nome="Entendendo algoritmo", autor="Aditya", emprestado=False) | ||
|
|
||
| for livro in [livro1,livro2]: | ||
| self.biblioteca.add_livro(livro) | ||
|
|
||
| self.assertEqual(2, len(self.biblioteca.exibir_livros())) | ||
|
|
||
|
|
||
| def test_emprestar_livro_deve_passar(self): | ||
| #Arrange | ||
| #biblioteca = Biblioteca() | ||
| livro_objeto = Livro(nome="Torto Arado", autor="Itamar Vieira", emprestado=False) | ||
| self.assertEqual(True, self.biblioteca.emprestar_livro(livro_objeto).emprestado) | ||
|
|
||
| def test_add_livro_nao_deve_inserir_num(self): | ||
| #Arrange | ||
| #biblioteca = Biblioteca() | ||
| livro = 1989 | ||
| #Assert / Act | ||
| with self.assertRaises(TypeError): | ||
| self.biblioteca.add_livro(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,18 @@ | ||
| from unittest import TestCase | ||
| from livro import Livro | ||
|
|
||
|
|
||
| class TestLivro(TestCase): | ||
| def test_init_deve_passar(self): | ||
| #Arrange | ||
| nome = "Torto Arado" | ||
| autor ="Itamar Vieira" | ||
| #Act | ||
| livro = Livro(nome, autor,False) | ||
| #Assert | ||
| self.assertEqual(nome, livro.nome) | ||
| self.assertEqual(autor, livro.autor) | ||
| self.assertEqual(False, livro.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.
Que arraso essa validação!