diff --git a/Biblioteca.py b/Biblioteca.py new file mode 100644 index 0000000..8a61560 --- /dev/null +++ b/Biblioteca.py @@ -0,0 +1,29 @@ +from Livro import Livro +class Biblioteca : + + def __init__ (self): + self.livros = [] + + 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) + def listar_livro(self): + for i in self.livros: + return i + def emprestar_livro (self,nome: Livro): + for i in self.livros: + if i.nome == nome: + i.esta_emprestado == True + return True + return False + def remover_livro(self,nome:Livro): + for i in self.livros: + if i == nome: + self.livros.remove(i) + + + + + + \ No newline at end of file diff --git a/Livro.py b/Livro.py new file mode 100644 index 0000000..cbe739e --- /dev/null +++ b/Livro.py @@ -0,0 +1,9 @@ +class Livro: + + def __init__(self, nome, autor): + self.nome = nome + self.autor = autor + self.esta_emprestado = False + + + \ No newline at end of file diff --git a/testBiblioteca.py b/testBiblioteca.py new file mode 100644 index 0000000..adb05ad --- /dev/null +++ b/testBiblioteca.py @@ -0,0 +1,71 @@ +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 = "Harry Potter" + autor_livro = "J.K. Rowlling" + 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_numero(self): + #Arrange + biblioteca = Biblioteca() + livro = 1988 + #Act/Assert + + with self.assertRaises(TypeError): + self.biblioteca.adicionar_livro(livro) + def test_listar_livro(self): + #Arrange + nome_livro = "Harry Potter" + autor_livro = "J.K. Rowlling" + livro = Livro(nome_livro,autor_livro) + #Act + self.biblioteca.adicionar_livro(livro) + self.biblioteca.listar_livro() + #Assert + self.assertEqual (1, len(self.biblioteca.livros)) + + + def test_emprestar_livro(self): + #Arrange + nome_livro = "Harry Potter" + autor_livro = "J.K Rowlling" + livro = Livro (nome_livro, autor_livro) + #Act + self.biblioteca.adicionar_livro(livro) + esta_emprestado = self.biblioteca.emprestar_livro(nome_livro) + #Assert + self.assertTrue(esta_emprestado) + def test_remover_livro(self): + #Arrange + + nome_livro = "Harry Potter" + autor_livro = "J.K Rowlling" + + livro = Livro(nome_livro,autor_livro) + #Act + self.biblioteca.adicionar_livro(livro) + self.biblioteca.remover_livro(livro) + + #Assert + self.assertEqual (0, len(self.biblioteca.livros)) + + + + \ No newline at end of file diff --git a/testLivro.py b/testLivro.py new file mode 100644 index 0000000..a8dafcb --- /dev/null +++ b/testLivro.py @@ -0,0 +1,14 @@ +from unittest import TestCase +from Livro import Livro + +class TestLivro (TestCase): + def test_init_deve_passar (self): + # Arrange + nome = "Extraordinário" + autor = "R.J Palacio" + # Act + livro = Livro(nome, autor) + # Assert + self.assertEqual(nome, livro.nome) + self.assertEqual (autor, livro.autor) + self.assertEqual(False, livro.esta_emprestado) \ No newline at end of file