-
Notifications
You must be signed in to change notification settings - Fork 29
Develop #9
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
JaneM00
wants to merge
1
commit into
yandex-praktikum:main
Choose a base branch
from
JaneM00:patch-2
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
Develop #9
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
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,83 @@ | ||
| import unittest | ||
|
|
||
| class TestBooksCollector(unittest.TestCase): | ||
|
|
||
| def setUp(self): | ||
| self.collector = BooksCollector() | ||
|
|
||
| # Тест на добавление новых книг | ||
| def test_add_new_book(self): | ||
| self.collector.add_new_book("1984") | ||
| self.assertIn("1984", self.collector.books_genre) | ||
| self.assertEqual(self.collector.books_genre["1984"], '') | ||
|
|
||
| # Тест на добавление книги, превышающей максимальную длину | ||
| def test_add_new_book_too_long_name(self): | ||
| self.collector.add_new_book("A" * 41) | ||
| self.assertNotIn("A" * 41, self.collector.books_genre) | ||
|
|
||
| # Тест на установку жанра для книги | ||
| def test_set_book_genre(self): | ||
| self.collector.add_new_book("Fahrenheit 451") | ||
| self.collector.set_book_genre("Fahrenheit 451", "Фантастика") | ||
| self.assertEqual(self.collector.get_book_genre("Fahrenheit 451"), "Фантастика") | ||
|
|
||
| # Тест на получение жанра книги | ||
| def test_get_book_genre(self): | ||
| self.collector.add_new_book("The Shining") | ||
| self.collector.set_book_genre("The Shining", "Ужасы") | ||
| self.assertEqual(self.collector.get_book_genre("The Shining"), "Ужасы") | ||
|
|
||
| # Тест на получение книг с определённым жанром | ||
| def test_get_books_with_specific_genre(self): | ||
| self.collector.add_new_book("It") | ||
| self.collector.set_book_genre("It", "Ужасы") | ||
| self.collector.add_new_book("Harry Potter") | ||
| self.collector.set_book_genre("Harry Potter", "Фантастика") | ||
| books = self.collector.get_books_with_specific_genre("Ужасы") | ||
| self.assertIn("It", books) | ||
| self.assertNotIn("Harry Potter", books) | ||
|
|
||
| # Тест на получение книг для детей | ||
| def test_get_books_for_children(self): | ||
| self.collector.add_new_book("Маша и медведь") | ||
| self.collector.set_book_genre("Маша и медведь", "Мультфильмы") | ||
| self.collector.add_new_book("Ужас вихря") | ||
| self.collector.set_book_genre("Ужас вихря", "Ужасы") | ||
| children_books = self.collector.get_books_for_children() | ||
| self.assertIn("Маша и медведь", children_books) | ||
| self.assertNotIn("Ужас вихря", children_books) | ||
|
|
||
| # Тест на добавление книги в избранное | ||
| def test_add_book_in_favorites(self): | ||
| self.collector.add_new_book("Lord of the Flies") | ||
| self.collector.add_book_in_favorites("Lord of the Flies") | ||
| self.assertIn("Lord of the Flies", self.collector.get_list_of_favorites_books()) | ||
|
|
||
| # Тест на удаление книги из избранного | ||
| def test_delete_book_from_favorites(self): | ||
| self.collector.add_new_book("Pride and Prejudice") | ||
| self.collector.add_book_in_favorites("Pride and Prejudice") | ||
| self.collector.delete_book_from_favorites("Pride and Prejudice") | ||
| self.assertNotIn("Pride and Prejudice", self.collector.get_list_of_favorites_books()) | ||
|
|
||
| # Тест на отсутствие повторного добавления в избранное | ||
| def test_add_book_in_favorites_twice(self): | ||
| self.collector.add_new_book("The Great Gatsby") | ||
| self.collector.add_book_in_favorites("The Great Gatsby") | ||
| self.collector.add_book_in_favorites("The Great Gatsby") # Повторное добавление | ||
| self.assertEqual(len(self.collector.get_list_of_favorites_books()), 1) | ||
|
|
||
| # Параметризованный тест на добавление книг | ||
| from parameterized import parameterized | ||
| @parameterized.expand([ | ||
| ("The Catcher in the Rye",), | ||
| ("To Kill a Mockingbird",), | ||
| ("Brave New World",) | ||
| ]) | ||
| def test_add_books_with_parameterization(self, book_name): | ||
| self.collector.add_new_book(book_name) | ||
| self.assertIn(book_name, self.collector.books_genre) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
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.
Thanks