Page 389 - Computer_Science_F5
P. 389

Computer Science              self.checked_out_books.remove(book)
                              print(f”{book.title} returned successfully.”)
                          else:
                              print(“Book not found in user’s checked out list.”)
          FOR ONLINE READING ONLY

                  Library Class:

               class Library:
                   def __init__(self):
                       self.books = []
                       self.users = []


                   def add_book(self, book):
                       self.books.append(book)


                   def remove_book(self, book):
                       self.books.remove(book)

                   def search_book(self, title):

                       return [book for book in self.books if title.lower() in book.title.lower()]

                   def add_user(self, user):
                       self.users.append(user)



           2. Modular development
             (a) Develop each class separately and test its methods.
             (b) Example of testing the Book class:


                book1 = Book(“Python Programming”, “Sarai Mkuvangwa”, “1234567890”, 3)
                print(book1.checkout())  # Output: True
                print(book1.available_copies)  # Output: 2



           Stage four: Testing and debugging

           1. Testing
             (a) Unit tests:
                 (i)   Test individual methods for expected functionality.


                                                 380
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   380                                                     23/07/2024   12:34
   384   385   386   387   388   389   390   391   392   393   394