From d1e336450d9dedfdb74968d6ac1cd293f9654ffc Mon Sep 17 00:00:00 2001 From: Vlada Khrustaleva Date: Wed, 21 Aug 2024 22:23:27 +0700 Subject: [PATCH 1/3] new --- .gitignore | 0 .idea/misc.xml | 3 +++ 2 files changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/misc.xml b/.idea/misc.xml index 75aaeae..f2e0f8d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file From 374ffca95838b14c0060ee108e335f6c13b4b863 Mon Sep 17 00:00:00 2001 From: VladislavaHub Date: Wed, 21 Aug 2024 22:30:56 +0700 Subject: [PATCH 2/3] =?UTF-8?q?test.=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 0 "test.\321\200\321\203" | 85 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) delete mode 100644 .gitignore create mode 100644 "test.\321\200\321\203" diff --git a/.gitignore b/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git "a/test.\321\200\321\203" "b/test.\321\200\321\203" new file mode 100644 index 0000000..3f3bc96 --- /dev/null +++ "b/test.\321\200\321\203" @@ -0,0 +1,85 @@ +from main import BooksCollector + +# класс TestBooksCollector объединяет набор тестов, которыми мы покрываем наше приложение BooksCollector +# обязательно указывать префикс Test +class TestBooksCollector: + + # пример теста: + # обязательно указывать префикс test_ + # дальше идет название метода, который тестируем add_new_book_ + # затем, что тестируем add_two_books - добавление двух книг + def test_add_new_book_add_two_books(self): + # создаем экземпляр (объект) класса BooksCollector + collector = BooksCollector() + + # добавляем две книги + collector.add_new_book('Гордость и предубеждение и зомби') + collector.add_new_book('Что делать, если ваш кот хочет вас убить') + + # проверяем, что добавилось именно две + # словарь books_rating, который нам возвращает метод get_books_rating, имеет длину 2 + assert len(collector.get_books_rating()) == 2 + + def setUp(self): + self.collector = BooksCollector() + + def test_add_new_book(self): + self.collector.add_new_book("The Great Gatsby") + self.assertIn("The Great Gatsby", self.collector.books_genre) + self.assertEqual(self.collector.books_genre["The Great Gatsby"], "") + + def test_add_new_book_invalid_length(self): + self.collector.add_new_book("") # Empty name + self.collector.add_new_book("A" * 41) # Exceeds 40 characters + self.assertEqual(len(self.collector.books_genre), 0) + + def test_set_book_genre(self): + self.collector.add_new_book("Brave New World") + self.collector.set_book_genre("Brave New World", "Фантастика") + self.assertEqual(self.collector.books_genre["Brave New World"], "Фантастика") + + def test_set_book_genre_invalid_book(self): + self.collector.set_book_genre("Nonexistent Book", "Фантастика") + self.assertEqual(len(self.collector.books_genre), 0) # No books should be set + + def test_set_book_genre_invalid_genre(self): + self.collector.add_new_book("The Catcher in the Rye") + self.collector.set_book_genre("The Catcher in the Rye", "Nonexistent Genre") + self.assertEqual(self.collector.books_genre["The Catcher in the Rye"], "") + + def test_get_book_genre(self): + self.collector.add_new_book("Moby Dick") + self.collector.set_book_genre("Moby Dick", "Фантастика") + self.assertEqual(self.collector.get_book_genre("Moby Dick"), "Фантастика") + + def test_get_books_genre(self): + self.collector.add_new_book("Fahrenheit 451") + self.collector.set_book_genre("Fahrenheit 451", "Фантастика") + self.assertEqual(self.collector.get_books_genre(), {"Fahrenheit 451": "Фантастика"}) + + def test_get_books_for_children(self): + self.collector.add_new_book("Finding Nemo") + self.collector.set_book_genre("Finding Nemo", "Мультфильмы") + self.collector.add_new_book("It") + self.collector.set_book_genre("It", "Ужасы") + self.assertEqual(self.collector.get_books_for_children(), ["Finding Nemo"]) + + def test_add_book_in_favorites(self): + self.collector.add_new_book("To Kill a Mockingbird") + self.collector.set_book_genre("To Kill a Mockingbird", "Детективы") + self.collector.add_book_in_favorites("To Kill a Mockingbird") + self.assertIn("To Kill a Mockingbird", self.collector.favorites) + + def test_add_book_in_favorites_not_exist(self): + self.collector.add_book_in_favorites("Not Exist Book") + self.assertNotIn("Not Exist Book", self.collector.favorites) + + def test_delete_book_from_favorites(self): + self.collector.add_new_book("The Lord of the Rings") + self.collector.set_book_genre("The Lord of the Rings", "Фантастика") + self.collector.add_book_in_favorites("The Lord of the Rings") + self.collector.delete_book_from_favorites("The Lord of the Rings") + self.assertNotIn("The Lord of the Rings", self.collector.favorites) + + if __name__ == "__main__": + unittest.main() From b9f1492a6bc8489cfbe9000d856465d56a2730bb Mon Sep 17 00:00:00 2001 From: VladislavaHub Date: Wed, 21 Aug 2024 22:31:52 +0700 Subject: [PATCH 3/3] Delete .idea/misc.xml --- .idea/misc.xml | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .idea/misc.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index f2e0f8d..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file