return high def most_positive_user(self): high = ["",-1000] for user in self.users.values(): if user.get_average_rating() > high[1]: high = [user, user.get_average_rating()] return high #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[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)
# The ISBN number (class) I added (requires 13 digits) # There where some inconsistencies (with the naming)(between the INSTRUCTIONS and THIS FILE) calling methods #CREATE OBJECT (TomeRater) tr = TomeRater() #CREATE BOOKS book1 = tr.create_book("Society of Mind", 1234512345678) #All (ISBN) (require 13 digits) novel1 = tr.create_novel("Alice In Wonderland", 1020304030201, "Lewis Carroll") #novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.isbn.set_isbn(9781536831139) #novel1.set_isbn(9781536831139) nonfiction1 = tr.create_non_fiction("Automate the Boring Stuff", 1234561929452, "Python", "beginner") #nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = tr.create_non_fiction("Computing Machinery and Intelligence", 1234511111938, "AI", "advanced") #nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938) novel2 = tr.create_novel("The Diamond Age", 1234510101010, "Neal Stephenson") #novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = tr.create_novel("There Will Come Soft Rains", 1234510001000, "Ray Bradbury") #novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) #CREATE USERS tr.add_user("Alan Turing", "*****@*****.**") tr.add_user("David Marr", "*****@*****.**") #Add USER (with BOOKS ARGUMENT)
from EmailUtil import * from TomeRater import * Tome_Rater = TomeRater() #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = Tome_Rater.create_non_fiction( "Computing Machinery and Intelligence", "AI", "advanced", 11111938) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[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)
non_fiction3 = Non_Fiction("Python for Dummies", 111999, "Advanced", "Snakes", 35) print("Creating TomeRaters") tomerater1 = TomeRater() tomerater2 = TomeRater() tomerater3 = TomeRater() tomerater4 = TomeRater() print("Creating TomeRaterBook") tomeraterbook1 = tomerater1.create_book("That Book", 123908, 13) print("Creating TomeRaterNovel") tomeraternovel1 = tomerater1.create_novel("Untruth", "Jim Crowed", 122345, 90) print("Creating TomerRaterNon_Fiction") tomeraternon_fiction1 = tomerater1.create_non_fiction("Python for Dummies", "Beginner", "Programming", 111999, 22.9) print("Begin users testing\n") print("Testing user1 instance: Beatriz Rodriguez, [email protected], {}") print(user1.name, user1.email, user1.books, sep=" , ") print("Testing user1 string representation: User Beatriz Rodriguez with email [email protected] has read 0 book(s) with an average rating of None") print(user1) print("Testing equality of user1 and user2: False") print(user1 == user2) print("Testing equality of user1 and user3: True") print(user1 == user3) print("Testing get_email user1: [email protected]") print(user1.get_email()) print("Testing change_email user2: [email protected]") user2.change_email("*****@*****.**") print(user2.get_email())
# Create some books with some tests: print("\nTest case: Few broken books created") book_error = Tome_Rater.create_book("Society of Mind", None) # ISBN missing - error book_error2 = Tome_Rater.create_book(12345, 12345) # Book name is not a string book1 = Tome_Rater.create_book("Society of Mind", 12345678) print(book1) book2 = Tome_Rater.create_book("Food for coders", 84372672, 2.54) print(book2) book3 = Tome_Rater.create_book("Loops and hoops", 385874323, 64.42) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.set_isbn(9781536831139) novel_error = Tome_Rater.create_novel( "Alice In Wonderland", "Lewis Carroll", 12345) # Same book twice, however ISBN is different and should be accepted nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = Tome_Rater.create_non_fiction( "Computing Machinery and Intelligence", "AI", "advanced", 11111938) nonfiction3 = Tome_Rater.create_non_fiction("Computers", "Graphics", "turbo", 134451313, 34.55) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) novel4 = Tome_Rater.create_novel("The ABC's of programming", "John Doe", 9284374, 12.45) novel5 = Tome_Rater.create_novel("That's it!", "Albert Einstein", 1902938478, 25.95) # Create users with some email tests: Tome_Rater.add_user("Alan Turing", "*****@*****.**")
import sys # ---------------------------------------------------------------------------- # TOME RATER (EQUALITY)(__eq__)(==)(COMPARE EQUALITY ON TWO TomeRater OBJECTS) # trap printout (START) ************************* trap = io.StringIO() sys.stdout = trap # OBJECT#1 tr1 = TomeRater() book1 = tr1.create_book("Society of Mind", 1234512345678) novel1 = tr1.create_novel("Alice In Wonderland", 1020304030201, "Lewis Carroll") nonfiction1 = tr1.create_non_fiction("Automate the Boring Stuff", 1234561929452, "Python", "beginner") tr1.add_user("Marvin Minsky", "*****@*****.**", books=[book1, novel1, nonfiction1]) # OBJECT#2 tr2 = TomeRater() book2 = tr2.create_book("Society of Mind", 1234512345678) novel2 = tr2.create_novel("Alice In Wonderland", 1020304030201, "Lewis Carroll") nonfiction2 = tr2.create_non_fiction("Automate the Boring Stuff", 1234561929452, "Python", "beginner") tr2.add_user("Marvin Minsky",
pap = Fiction('Pride and Prejudice', 'Jane Austen', 679783261) pap2 = Fiction('Pride and Prejudice', 'Jane Austen', 679783261) man0 = Non_Fiction('The Society of Mind', 'Artificial Intelligence', 'Beginner', 671657135) man1 = Non_Fiction('On Cooking', 'Culinary', 'Expert', 131713272) man2 = Non_Fiction('On Cooking', 'Culinary Arts', 'Expert', 131713272) rater = TomeRater() print('==================================================================') print('==================== TESTING TomeRater Class =====================') print('==================================================================') ##################################### BOOKS ################################# r_ww = rater.create_book('World War II at Sea: A Global History', 190243678) r_man = rater.create_non_fiction('The Society of Mind', 'Artificial Intelligence', 'Beginner', 671657135) r_man2 = rater.create_non_fiction('On Cooking', 'Culinary Arts', 'Expert', 131713272) r_pap = rater.create_novel('Pride and Prejudice', 'Jane Austen', 679783261) para = rater.create_novel('The Parasite', 'Arthur Conan Doyle', 809594374) #################################### USERS ################################## rater.add_user('RDSgmail', '*****@*****.**', user_books=[r_ww, r_pap, r_man]) rater.add_user('RDShotmail', '*****@*****.**') rater.add_user('RDSYahoo', '*****@*****.**') ############################### BOOKS TO USERS ############################## rater.add_book_to_user(r_man2, '*****@*****.**', 3) rater.add_book_to_user(r_man2, '*****@*****.**', 4) rater.add_book_to_user(para, '*****@*****.**', 4)
from TomeRater import * Tome_Rater = TomeRater() #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678, 10) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345, 20) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452, 30) nonfiction2 = Tome_Rater.create_non_fiction( "Computing Machinery and Intelligence", "AI", "advanced", 11111938, 40) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010, 50) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000, 60) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[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)
from TomeRater import * Tome_Rater = TomeRater() #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.set_isbn(9781536831139) book1.set_isbn(978153683113) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) #Create users: print("Create Users") Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[book1, novel1, nonfiction1]) #Add books to a user one by one, with ratings: print("Add book to user") 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)
from TomeRater import * Tome_Rater = TomeRater() #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452) nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938) nonfiction3 = Tome_Rater.create_non_fiction("Obey The Testing Goat", "Python", "advanced", 1394098) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") Tome_Rater.add_user("Mitchell Redekopp", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[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)