# Adding books with prices. extra_nonfiction2 = Tome_Rater.create_non_fiction("Clean Code", "Software Engineering", "advanced", 6789, 43.27) extra_novel2 = Tome_Rater.create_novel("Ender's Game", "Orson Scott Card", 11121314, 11.05) extra_book2 = Tome_Rater.create_book("Introduction to High-Frequency Finance", 15161718, 132.00) # Adding books with prices to users. Tome_Rater.add_book_to_user(extra_nonfiction2, "*****@*****.**", 4) Tome_Rater.add_book_to_user(extra_novel2, "*****@*****.**", 3) Tome_Rater.add_book_to_user(extra_nonfiction2, "*****@*****.**", 2) Tome_Rater.add_book_to_user(extra_book2, "*****@*****.**", 3) Tome_Rater.add_book_to_user(extra_novel2, "*****@*****.**", 3) Tome_Rater.add_book_to_user(extra_book2, "*****@*****.**", 3) # Getting the most expensive books. Tome_Rater.print_catalog() print("The two most expensive books:") print(Tome_Rater.get_n_most_expensive_books(2)) # Getting the worth of different users. print("Alan Turing's book worth: " + str(Tome_Rater.get_worth_of_user("*****@*****.**"))) print("Marvin Minsky's book worth: " + str(Tome_Rater.get_worth_of_user("*****@*****.**"))) print("David Marr's book worth: " + str(Tome_Rater.get_worth_of_user("*****@*****.**")))
for book in Tome_Rater.get_n_most_read_books(9): print('{title} has been read {count} times'.format(title=book[0], count=book[1])) print() print( "List of 2 most prolific readers: (truncated if requested list is larger than user base)" ) top_two = Tome_Rater.get_n_most_prolific_readers(2) for user in top_two: print('{user} has read {book_count} books'.format( user=user, book_count=top_two[user])) print() print( "List of 2 most expensive books: (truncated if requested list is larger than catalog" ) pricey_two = Tome_Rater.get_n_most_expensive_books(2) for k, v in pricey_two.items(): print('{title} costs ${price}'.format(title=k, price=v)) print() print('"Worth" of users') print('Total spend for {email} is {total_spend}'.format( email='*****@*****.**', total_spend=Tome_Rater.get_worth_of_user('*****@*****.**'))) print('Total spend for {email} is {total_spend}'.format( email='*****@*****.**', total_spend=Tome_Rater.get_worth_of_user('*****@*****.**'))) print('Total spend for {email} is {total_spend}'.format( email='*****@*****.**', total_spend=Tome_Rater.get_worth_of_user('*****@*****.**'))) print() print('End of first Tome_Rater tests')
print("Should not equal:") if Tome_Rater == Tome_Rater3: print("TomeRaters are equal") else: print("TomeRaters are not equal") print("Test n most read books:") print(Tome_Rater.get_n_most_read_books(3)) print(Tome_Rater.get_n_most_read_books(1000)) print(Tome_Rater.get_n_most_read_books(1.4)) print(Tome_Rater.get_n_most_read_books(-2)) print("Test n most prolific readers:") print(Tome_Rater.get_n_most_prolific_readers(3)) print(Tome_Rater.get_n_most_prolific_readers(1000)) print(Tome_Rater.get_n_most_prolific_readers(1.4)) print(Tome_Rater.get_n_most_prolific_readers(-2)) print("Test n most expensive books:") print(Tome_Rater.get_n_most_expensive_books(3)) print(Tome_Rater.get_n_most_expensive_books(1000)) print(Tome_Rater.get_n_most_expensive_books(1.4)) print(Tome_Rater.get_n_most_expensive_books(-2)) print("Test worth of a user:"******"*****@*****.**")) print(Tome_Rater.get_worth_of_user("*****@*****.**")) print("Test best value book:") print(Tome_Rater.get_book_with_best_rating_for_price())
Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 2) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 4) Tome_Rater.add_book_to_user(novel2, "*****@*****.**", 3) #Uncomment these to test your functions: Tome_Rater.print_catalog() print('') Tome_Rater.print_users() print('') print("Most positive user:"******"Highest rated book:") print(Tome_Rater.highest_rated_book()) print('') print("Most read book:") print(Tome_Rater.get_most_read_book()) print('') print("Get 'n' most read books:") Tome_Rater.get_n_most_read_books(4) print('') print("Get 'n' most prolific readers:") Tome_Rater.get_n_most_prolific_readers(3) print('') print("Get 'n' most expensive books.") Tome_Rater.get_n_most_expensive_books(4) print('') print("The sum of the cost of all books read by given user:"******"*****@*****.**"))
Tome_Rater.add_user("David Marr", "*****@*****.**") # Tests for testing erroneous email addresses Tome_Rater.add_user("E: David Marr", "*****@*****.**") # Duplicate Tome_Rater.add_user("E: User email without @", "withoutmiukumaukucomputation.org") # Without @ Tome_Rater.add_user("E: User email without ending", "without@ending") # Without domain Tome_Rater.add_user("E: User email without ending and @", "justtextasemail") # Just a string # Sophisticated analysis print(Tome_Rater.get_n_most_read_books(3)) print(Tome_Rater.get_n_most_prolific_readers(3)) # Price print(Tome_Rater.get_n_most_expensive_books(3)) print(Tome_Rater.get_worth_of_user("*****@*****.**") ) # Prints the sum of the costs of all the books read by this user # Uncomment these to test your functions: Tome_Rater.print_catalog() Tome_Rater.print_users() print("\nMost positive user:"******"\nHighest rated book:") print(Tome_Rater.highest_rated_book()) print("\nMost read book:") print(Tome_Rater.most_read_book()) print("\n__repr__ test:") print(Tome_Rater)
#Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", [book1, novel1, nonfiction1]) #Add books to a user one by one, with ratings: Tome_Rater.add_book_to_user(book1, "*****@*****.**", 1) Tome_Rater.add_book_to_user(novel1, "*****@*****.**", 3) Tome_Rater.add_book_to_user(nonfiction1, "*****@*****.**", 3) Tome_Rater.add_book_to_user(nonfiction2, "*****@*****.**", 4) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 1) Tome_Rater.add_book_to_user(novel2, "*****@*****.**", 2) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 2) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 4) #Uncomment these to test your functions: Tome_Rater.print_catalog() Tome_Rater.print_users() print("Most positive user:"******"Highest rated book:") print(Tome_Rater.highest_rated_book()) print("Most read book:") print(Tome_Rater.get_most_read_book()) print("Enter the amount of most expensive books to look for") print(Tome_Rater.get_n_most_expensive_books(int(input()))) print("Enter the user's email to search his/her worth") print(Tome_Rater.get_worth_of_user(input()))
print(tomerater3.highest_rated_book()) print("Testing most_positive_user tomerater3: Beatriz Rodriguez") print(tomerater3.most_positive_user()) print("Testing get_n_most_read_books tomerater3: That Book & Python for Dummies") tomerater3.add_book_to_user(tomeraterbook1, "*****@*****.**", 4) tomerater3.add_book_to_user(tomeraterbook1, "*****@*****.**", 2) print(tomerater3.get_n_most_read_books(2)) print("Testing get_n_most_prolific_readers tomerater3: Beatriz Rodriguez & Jenny Parque") tomerater3.add_user("Jenny Parque", "*****@*****.**") tomerater3.add_book_to_user(tomeraterbook1, "*****@*****.**", 3.8) tomerater3.add_book_to_user(tomeraterbook1, "*****@*****.**", 2) tomerater3.add_book_to_user(non_fiction1, "*****@*****.**", 1.5) tomerater3.add_book_to_user(tomeraternovel1, "*****@*****.**", 2.3) print(tomerater3.get_n_most_prolific_readers(2)) print("Testing get_n_most_expensive_books tomerater3: Untruth & Look Over There") print(tomerater3.get_n_most_expensive_books(2)) print("Testing get_worth_of_user for Xiomei Li tomerater3: 67") print(tomerater3.get_worth_of_user("*****@*****.**")) print("Testing string representation tomerater2: This TomeRater has 3 book(s) and 2 user(s). \nWith Watch My Hand being read the most, Untruth having the highest average rating,\nand Beatriz Rodriguez giving the most positive reviews.") print(tomerater2) print("Testing tomerater1 equal to tomerater2: False") print(tomerater1 == tomerater2) print("Testing tomerater1 equal to tomerater4: True") tomerater4.add_user("Beatriz Rodriguez", "*****@*****.**", [book1, book5]) tomerater4.add_book_to_user(tomeraterbook1, "*****@*****.**") print(tomerater1 == tomerater4) print("Testing existing user error handling for user3 tomerater3: User Jenny Parque currently exists with email [email protected]. Please use a different email.") tomerater3.add_user("Jenny Parqua", "*****@*****.**") print("Testing existing isbn error handling for all book types tomerater3") print("Creating TomeRaterBook: The isbn 123908 already exists for another book. Please give a unique isbn.") tomeraterbook2 = tomerater1.create_book("That is a Book", 123908, 3)
print("\r\n***** Testing most positive user") print("Most positive user: "******"\r\n***** Testing TomeRater __repr__ method") print(tomerater) print("\r\n***** Testing TomeRater get_n_most_read_books method") print(tomerater.get_n_most_read_books(1)) print(tomerater.get_n_most_read_books(2)) print(tomerater.get_n_most_read_books(4)) print(tomerater.get_n_most_read_books(10)) print("\r\n***** Testing TomeRater get_n_most_prolific_readers method") print(tomerater.get_n_most_prolific_readers(1)) print(tomerater.get_n_most_prolific_readers(2)) print(tomerater.get_n_most_prolific_readers(3)) print("\r\n***** Testing TomeRater get_n_most_expensive_books method") print(tomerater.get_n_most_expensive_books(1)) print(tomerater.get_n_most_expensive_books(2)) print(tomerater.get_n_most_expensive_books(3)) print("\r\n***** Testing TomeRater get_worth_of_user method") print(tomerater.get_worth_of_user("*****@*****.**")) print(tomerater.get_worth_of_user("*****@*****.**")) print(tomerater.get_worth_of_user("*****@*****.**"))
Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 2) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 4) #Uncomment these to test your functions: Tome_Rater.print_catalog() Tome_Rater.print_users() print("Most positive user:"******"Highest rated book:") print(Tome_Rater.highest_rated_book()) print("Most read book:") print(Tome_Rater.most_read_book()) number_of_books = 3 print("{} of the most expensive books:".format(number_of_books)) print(Tome_Rater.get_n_most_expensive_books(number_of_books)) print("The total worth of a user's books:") print(Tome_Rater.get_worth_of_user("*****@*****.**")) #Tests for value validation class TestCreateBookValues(unittest.TestCase): def test_invalid_price_raises_error(self): self.assertRaises(ValueError, Tome_Rater.create_non_fiction, "Automate the Boring Stuff", "Python", "beginner", 1929452, "") def test_invalid_isbn_raises_error(self): self.assertRaises(ValueError, Tome_Rater.create_non_fiction, "Automate the Boring Stuff", "Python", "beginner", "1929452", 54)