diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 75aaeae..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file 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()