def testAddBook(self): ''' Function that checks whether a book is added correctly to a list or not input:- preconditions:- output:- postconditions: If the addition of a book is incorrectly implemented, an error will appear ''' bookList = [] firstBook = Book(1, "Poezii", "Volum ce cuprinde capodoperele poeziei eminesciene", "Mihai Eminescu") secondBook = Book(2, "Poezii", "Volum ce cuprinde capodoperele poeziei bacoviene", "George Bacovia") thirdBook = Book(3, "Amintiri din copilarie", "Povestiri inspirate din copilaria autorului", "Ion Creanga") bookList.append(firstBook) bookList.append(secondBook) bookList.append(thirdBook) newBook = Book(4, "Cartof", "Agricultura", "Who knows") newBook._Book__addBook(bookList) anotherBookList = [] anotherBookList.append(firstBook) anotherBookList.append(secondBook) anotherBookList.append(thirdBook) anotherBookList.append(newBook) self.assertEqual(bookList, anotherBookList)
def __loadBooksFromFile(self): file = open(self.__fileName, "r") oneLine = file.readline().strip() while oneLine != "": attributes = oneLine.split(" ; ") book = Book(attributes[0], attributes[1], attributes[2], attributes[3]) book._Book__addBook(self.__list) oneLine = file.readline().strip() file.close()
def testUpdateBook(self): ''' Function that checks whether a book is updated correctly or not, without risking to create duplicates input:- preconditions:- output:- postconditions: If the update of a book is incorrectly implemented, an error will appear ''' mylist = [] book1 = Book(3, "Love", "Amazing", "Doctor Love") book2 = Book(2, "Curtains", "A complete guide to curtains", "Senor Draperie") book1._Book__addBook(mylist) book2._Book__addBook(mylist) book1._Book__updateBook(3, 1, "A", "B", "C", mylist) self.assertEqual(book1._Book__getId(), 1) self.assertEqual(book1._Book__getTitle(), "A") self.assertEqual(book1._Book__getDescription(), "B") self.assertEqual(book1._Book__getAuthor(), "C")