generated from reprograma/onX-sx-temaX
-
Notifications
You must be signed in to change notification settings - Fork 38
Projeto Guiado II - Nargylla Cloviel #22
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
NallaCloviel
wants to merge
3
commits into
reprograma:main
Choose a base branch
from
NallaCloviel: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
Show all changes
3 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,41 @@ | ||
| from livro import Livro | ||
|
|
||
| class Biblioteca : | ||
| def __init__(self): | ||
| self.livros = [] | ||
|
|
||
| #Adicionando o livro | ||
| def adicionar_livro(self, livro: Livro): | ||
| if (not isinstance(livro, Livro)): | ||
| raise TypeError(f"Esoerado Livro obtido valor {livro} do tipo {type(livro)}") | ||
|
|
||
| self.livros.append(livro) | ||
|
|
||
| #exibir livro | ||
| def exibir_livros(self): | ||
| lista_livros = [] | ||
| for livro in self.livros: | ||
| lista_livros.append(f'{livro.nome} por {livro.autor}') | ||
| return lista_livros | ||
|
|
||
| #Removendo o livro | ||
| def remover_livro(self, nome_livro): | ||
| livro_removido = False | ||
| for livro in self.livros: | ||
| if livro.nome == nome_livro: | ||
| self.livros.remove(livro) | ||
| livro_removido = True | ||
|
|
||
| if not livro_removido: | ||
| raise ValueError (f"O livro {nome_livro} não existe na biblioteca!") | ||
|
|
||
| #Pesquisar livro | ||
| def pesquisar_livro(self, nome_livro): | ||
| for livro in self.livros: | ||
| if livro.nome == nome_livro: | ||
| 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,5 @@ | ||
| class Livro: | ||
| def __init__(self, nome, autor): | ||
| self.nome = nome | ||
| self.autor = autor | ||
| self.esta_emprestado = False |
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,82 @@ | ||
| from unittest import TestCase | ||
| from Biblioteca import Biblioteca | ||
| from livro import Livro | ||
|
|
||
| class TestBiblioteca(TestCase): | ||
| def test_init_deve_passar(self): | ||
| # Arrange / Act | ||
| biblioteca = Biblioteca() | ||
|
|
||
| # Assert | ||
| self.assertIsInstance(biblioteca.livros, list) | ||
|
|
||
| class TestBiblioteca(TestCase): | ||
| def test_init_deve_passar(self): | ||
| # Arrange / Act | ||
| biblioteca = Biblioteca() | ||
|
|
||
| # Assert | ||
| self.assertIsInstance(biblioteca.livros, list) | ||
|
|
||
| def test_adicionar_livro_deve_passar(self): | ||
| # Arrange | ||
| biblioteca = Biblioteca() | ||
| nome_livro = "Dom Casmurro" | ||
| autor_livro = "Machado de Assis" | ||
| livro = Livro(nome_livro, autor_livro) | ||
|
|
||
| # Act | ||
| biblioteca.adicionar_livro(livro) | ||
|
|
||
| # Assert | ||
| self.assertEqual(1, len(biblioteca.livros)) | ||
|
|
||
| def test_adicionar_livro_nao_deve_inserir_numero(self): | ||
| #Arrange | ||
| biblioteca = Biblioteca | ||
| livro = 1988 | ||
| #act/assert | ||
| with self.assertRaises(TypeError): | ||
| biblioteca.adicionar_livro(livro) | ||
|
|
||
| def test_exibir_livros_listados_deve_passar(self): | ||
|
|
||
| #Arrange | ||
| biblioteca = Biblioteca() | ||
| #Act | ||
| livro1 = Livro("Dom Casmurro", "Machado de Assis") | ||
| biblioteca.adicionar_livro(livro1) | ||
| lista_de_livros = biblioteca.exibir_livros() | ||
|
|
||
| #Assert | ||
| self.assertIn("Dom Casmurro por Machado de Assis", lista_de_livros) | ||
|
|
||
| def test_remover_livro_deve_passar(self): | ||
| #Arrange | ||
| biblioteca = Biblioteca() | ||
| nome_livro = "Dom Casmurro" | ||
| autor_livro = "Machado de Assis" | ||
| livro = Livro(nome_livro, autor_livro) | ||
| biblioteca.adicionar_livro(livro) | ||
|
|
||
| # Act | ||
| biblioteca.remover_livro(nome_livro) | ||
|
|
||
| # Assert | ||
| self.assertEqual(0, len(biblioteca.livros)) | ||
|
|
||
|
|
||
| def test_pesquisar_livro_deve_passar(self): | ||
| #Arrange | ||
| biblioteca = Biblioteca() | ||
| nome_livro = "Dom Casmurro" | ||
| autor_livro = "Machado de Assis" | ||
| livro = Livro(nome_livro, autor_livro) | ||
| biblioteca.adicionar_livro(livro) | ||
|
|
||
| #Act | ||
| livro_pesquisa = "Dom Casmurro" | ||
| livro_encontrado = biblioteca.pesquisar_livro(livro_pesquisa) | ||
|
|
||
| # Act/#Assert | ||
| self.assertEqual("Dom Casmurro", livro_encontrado.nome) |
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,16 @@ | ||
| from unittest import TestCase | ||
| from livro import Livro | ||
|
|
||
| class TestLivro(TestCase): | ||
| def test_init_deve_passar(self): | ||
| #Arrange | ||
| nome = "O Alquimista" | ||
| autor = "Paulo Coelho" | ||
|
|
||
| #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.
eu havia esquecido de fazer o exibir livro, agora consegui