Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions exercicios/para-casa/Projeto Guiado II/Book.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kWQndQRb5jbw"
},
"outputs": [],
"source": [
"class Book:\n",
" def __init__(self, name, author):\n",
" self.name = name\n",
" self.author = author\n",
" self.book.borrowed = False"
]
}
]
}
66 changes: 66 additions & 0 deletions exercicios/para-casa/Projeto Guiado II/Library.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "2EETCSQKJjhu"
},
"outputs": [],
"source": [
"from Book import Book\n",
"\n",
"class Library:\n",
" def __init__(self):\n",
" self.books = []\n",
"\n",
" def add_book(self, book: Book):\n",
" if (not isinstance(book, Book)):\n",
" raise TypeError(f\"Expected Book, received value {book} of type {type(book)}\")\n",
" self.books.append(book)\n",
"\n",
" def show_books(self):\n",
" return self.books\n",
"\n",
" def borrow_book(self, title):\n",
" for book in self.books:\n",
" if book.name == title and not book.borrowed:\n",
" book.borrowed = True\n",
"\n",
" def remove_book(self, title):\n",
" for book in self.books:\n",
" if book.name == title:\n",
" self.books.remove(book)\n",
"\n",
" def find_book(self, title):\n",
" message = \"Book not found.\"\n",
" for book in self.books:\n",
" if book.name == title:\n",
" message = book\n",
" return message\n",
"\n",
" def return_livro(self, title):\n",
" message = \"Book not found.\"\n",
" for book in self.books:\n",
" if book.name == title:\n",
" book.borrowed = False\n",
" message = f\"Book returned: {book}\"\n",
" return message"
]
}
]
}
105 changes: 105 additions & 0 deletions exercicios/para-casa/Projeto Guiado II/LibraryTest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "P7SHX3hl2znl"
},
"outputs": [],
"source": [
"from unittest import TestCase\n",
"from Library import Library\n",
"from Book import Book\n",
"\n",
"class TestLibrary(TestCase):\n",
" def setUp(self):\n",
" self.library = Library()\n",
" self.book1 = Book(\"Siddhartha\", \"Hermann Hesse\")\n",
" self.book2 = Book(\"The Desert of the Tartars\", \"Dino Buzzati\")\n",
"\n",
" def test_init_should_pass(self):\n",
" self.assertIsInstance(self.library.books, list)\n",
"\n",
" def test_add_book_should_pass(self):\n",
" book_name = \"Cosmos\"\n",
" book_author = \"Carl Sagan\"\n",
" book = Book(book_name, book_author)\n",
"\n",
" self.library.add_book(book)\n",
"\n",
" self.assertEqual(1, len(self.library.books))\n",
"\n",
" def test_add_book_should_not_insert_number(self):\n",
" book = 1980\n",
"\n",
" with self.assertRaises(TypeError):\n",
" self.library.add_book(book)\n",
"\n",
" def test_show_books(self):\n",
" self.library.add_book(self.book1)\n",
" self.library.add_book(self.book2)\n",
" library_list = [self.book1, self.book2]\n",
"\n",
" self.assertEqual(self.library.show_books(), library_list)\n",
"\n",
" def test_borrow_books(self):\n",
" self.library.add_book(self.book1)\n",
" self.library.add_book(self.book2)\n",
"\n",
" self.library.book_borrowed(\"Siddhartha\")\n",
" self.library.book_borrowed(\"The Desert of the Tartars\")\n",
"\n",
" self.assertTrue(self.book1.book_borrowed)\n",
" self.assertTrue(self.book2.book_borrowed)\n",
"\n",
" def test_remove_book(self):\n",
" self.library.add_book(self.book1)\n",
" self.library.add_book(self.book2)\n",
"\n",
" self.library.remove_book(\"Siddhartha\")\n",
"\n",
" self.assertIsNot(self.library.books, self.book1)\n",
"\n",
" def test_search_existing_book(self):\n",
" self.library.add_book(self.book1)\n",
" self.library.add_book(self.book2)\n",
"\n",
" search_book = self.library.search_book(\"Siddhartha\")\n",
"\n",
" self.assertEqual(search_book, self.book1)\n",
"\n",
" def test_search_nonexistent_book(self):\n",
" self.library.add_book(self.book1)\n",
"\n",
" search_book = self.library.search_book(\"The Desert of the Tartars\")\n",
"\n",
" self.assertEqual(search_book, \"Book not found.\")\n",
"\n",
" def test_return_book(self):\n",
" self.library.add_book(self.book1)\n",
" self.library.add_book(self.book2)\n",
" self.library.book_borrowed(\"Siddhartha\")\n",
" self.library.book_borrowed(\"The Desert of the Tartars\")\n",
"\n",
" self.library.return_book(\"The Desert of the Tartars\")\n",
"\n",
" self.assertFalse(self.book2.book_borrowed)\n"
]
}
]
}
54 changes: 54 additions & 0 deletions exercicios/para-casa/Projeto Guiado II/TestBook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"source": [],
"metadata": {
"id": "HZ0ol3P2Hkxp"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "sU0taxfw9Ory"
},
"outputs": [],
"source": [
"from unittest import TestCase\n",
"from Library import Library\n",
"\n",
"\n",
"class testBook(TestCase):\n",
" def test_init_pass(self):\n",
"\n",
" name = 'Siddhartha'\n",
" author = 'Hermann Hesse'\n",
"\n",
"\n",
" book = Book(name, author)\n",
"\n",
"\n",
" self.assertEqual(name, book.name)\n",
" self.assertEqual(author, book.author)\n",
" self.assertEqual(False, book.borrowed)"
]
}
]
}
33 changes: 0 additions & 33 deletions exercicios/para-casa/README.md

This file was deleted.

31 changes: 0 additions & 31 deletions exercicios/para-casa/instrucoes-pull-request.md

This file was deleted.