# 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", "*****@*****.**") Tome_Rater.add_user("Marvin Minsky", "*****@*****.**") # 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) print("Most positive user:") print(Tome_Rater.most_positive_user())
#Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678, 11) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345, 30) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452, 20) nonfiction2 = Tome_Rater.create_non_fiction( "Computing Machinery and Intelligence", "AI", "advanced", 11111938, 50) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010, 13) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000, 22) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") Tome_Rater.add_user("David", "*****@*****.**") Tome_Rater.add_user("Marr", "*****@*****.**") Tome_Rater.add_user("Troll Marr", "*****@*****.**") Tome_Rater.add_user("David Troll", "davidacomputation.org") #Add a user with three books already read: #Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[book1, novel1, nonfiction1]) Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", 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)
"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", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") print("\nTest case: 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 # Add a user with three books already read: Tome_Rater.add_user( "Marvin Minsky", "*****@*****.**", user_books=[book1, book3, novel1, novel2, nonfiction1, nonfiction3])
#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) 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)
novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345, 15.0) novel1.set_isbn(9781536831139) nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452, 20) nonfiction2 = Tome_Rater.create_non_fiction( "Computing Machinery and Intelligence", "AI", "advanced", 11111938, 30.0) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010, 18.0) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000, 17.0) book2 = Tome_Rater.create_book("Starship Society", 10001000, 19.0) #Create users: print('creating users') Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") Tome_Rater.add_user("David May", "*****@*****.**") Tome_Rater.add_user("David May", "*****@*****.**") Tome_Rater.add_user("Dave Man", "*****@*****.**") #Add a user with three books already read: print('adding users with 3 books read') Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[book1, novel1, nonfiction1]) Tome_Rater.add_user("Peter Lays", "*****@*****.**", user_books=[book2, novel3, nonfiction2]) #Add books to a user one by one, with ratings:
print("Create novel with invalid price:") novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010, -13) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000, 50) #Set price to some books afterwards novel2.set_price(60) novel1.set_price(99.90) print("Set invalid prices:") nonfiction1.set_price("asdf") nonfiction1.set_price(-4000) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") print("Add existing email") Tome_Rater.add_user("David2 Marr", "*****@*****.**") print("Add invalid emails") Tome_Rater.add_user("Vellu", "*****@*****.**") Tome_Rater.add_user("Vellu", "email.org") #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)
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) 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)
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) Tome_Rater.add_book_to_user(novel2, "*****@*****.**", 2) Tome_Rater.add_book_to_user(novel3, "*****@*****.**", 2)
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) rater.add_book_to_user(para, '*****@*****.**', 3) ############################################################################# print('\n--------------------- Error Handling Checks ----------------------') rater.add_book_to_user(r_man2, '*****@*****.**', 5) rater.add_book_to_user(r_man, '*****@*****.**') rater.add_book_to_user(para, '*****@*****.**', -1)
#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", "*****@*****.**") Tome_Rater.add_user("user1", "*****@*****.**") Tome_Rater.add_user("user2", "*****@*****.**") Tome_Rater.add_user("some dude", "*****@*****.**") Tome_Rater.add_user("my friend", "*****@*****.**") Tome_Rater.add_user("Jim Kabobi", "*****@*****.**") #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)
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) #Test already existing ISBN book2 = Tome_Rater.create_book("Das fliegende Klassenzimmer", 12345678) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") #Test if email-address already exists #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]) #Test if email-address is valid Tome_Rater.add_user("Hans Meier", "*****@*****.**", user_books=[novel2, novel3, nonfiction1]) #Test already existing ISBN Tome_Rater.add_user("Lothar Luder", "*****@*****.**", user_books=[book2, book1, nonfiction1])
# ------------------------------------------ # TOME RATER (OBJECT#2)(default from populate.py) #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.isbn.set_isbn(9781536831139) nonfiction1 = tr.create_non_fiction("Automate the Boring Stuff", 1234561929452, "Python", "beginner") nonfiction2 = tr.create_non_fiction("Computing Machinery and Intelligence", 1234511111938, "AI", "advanced") novel2 = tr.create_novel("The Diamond Age", 1234510101010, "Neal Stephenson") novel3 = tr.create_novel("There Will Come Soft Rains", 1234510001000, "Ray Bradbury") #CREATE USERS tr.add_user("Alan Turing", "*****@*****.**") tr.add_user("David Marr", "*****@*****.**") #Add USER (with BOOKS ARGUMENT) tr.add_user("Marvin Minsky", "*****@*****.**", books=[book1, novel1, nonfiction1]) #Add BOOK (to users) tr.add_book_to_user('*****@*****.**', book1, 1) tr.add_book_to_user('*****@*****.**', novel1, 3) tr.add_book_to_user('*****@*****.**', nonfiction1, 3) tr.add_book_to_user('*****@*****.**', nonfiction2, 4) tr.add_book_to_user('*****@*****.**', novel3, 1) tr.add_book_to_user('*****@*****.**', novel2, 2) tr.add_book_to_user('*****@*****.**', novel3, 2) tr.add_book_to_user('*****@*****.**', novel3, 4) # ------------------------------------------
"Test book", 12345678) # this is to test the duplicate ISBN number #Creates some more books 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", "*****@*****.**") Tome_Rater.add_user("Alan Turing", "*****@*****.**") #this tests for a duplicate email Tome_Rater.add_user("test1", "test1.com") # this tests if the email is valid Tome_Rater.add_user("test2", "[email protected]") # this tests if the email is valid Tome_Rater.add_user("test3", "[email protected]") # this tests if the email is valid #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)
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) novel3_copy = 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", "*****@*****.**", [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)
#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) 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()
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 book with duplicate ISBN book2 = Tome_Rater.create_book("1984", 12345678) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Create user with duplicate email Tome_Rater.add_user("Alan Jackson", "*****@*****.**") #Create users with invalid email addresses Tome_Rater.add_user("Bill Gates", "gatesmicrosoft.com") Tome_Rater.add_user("Steve Wozniak", "*****@*****.**") #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:
# 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", "*****@*****.**", books=[book2, novel2, nonfiction2])
from TomeRater import * Tome_Rater = TomeRater() #Create some books: book1 = Tome_Rater.create_book("Society of Mind", 12345678, 12) novel1 = Tome_Rater.create_novel("Alice In Wonderland", "Lewis Carroll", 12345, 19) novel1.set_isbn(9781536831139) print('') nonfiction1 = Tome_Rater.create_non_fiction("Automate the Boring Stuff", "Python", "beginner", 1929452, 24) nonfiction2 = Tome_Rater.create_non_fiction("Computing Machinery and Intelligence", "AI", "advanced", 11111938, 13) novel2 = Tome_Rater.create_novel("The Diamond Age", "Neal Stephenson", 10101010, 31) novel3 = Tome_Rater.create_novel("There Will Come Soft Rains", "Ray Bradbury", 10001000, 22) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") #Tome_Rater.add_user("Pavel Ivanov", "*****@*****.**") #Add a user with three books already read: Tome_Rater.add_user("Marvin Minsky", "*****@*****.**", user_books=[book1, novel1, nonfiction1]) Tome_Rater.add_user("Pavel Ivanov", "*****@*****.**", user_books=[novel3, nonfiction2, nonfiction1, book1]) #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)
print("Testing equality of non_fiction1 and non_fiction2: False") print(non_fiction1 == non_fiction2) print("Testing equality of non_fiction1 and non_fiction3: True") print(non_fiction1 == non_fiction3) print("Begin tomerater testing\n") print("Testing tomerater1 instance: {}, {}") print(tomerater1.users, tomerater1.books, sep=" , ") print("Testing tomeraterbook1 equal to book2: True") print(tomeraterbook1 == book2) print("Testing tomeraternovel1 equal to fiction1: True") print(tomeraternovel1 == fiction1) print("Testing tomeraternon_fiction1 equal to non_fiction1: True") print(tomeraternon_fiction1 == non_fiction1) print("Testing add_user tomerater1: Beatriz Rodriguez, [email protected], The Book, Henry Book") tomerater1.add_user("Beatriz Rodriguez", "*****@*****.**", [book1, book5]) print(tomerater1.users, tomerater1.books, sep=" , ") print("Testing add_book_to_user tomerater1 user1: That Book") tomerater1.add_book_to_user(tomeraterbook1, "*****@*****.**") print(tomerater1.users, tomerater1.books, sep=" , ") print("Testing print_catalog tomerater1: The Book, That Book, That Book") tomerater1.print_catalog() print("Testing print_users tomerater1: Beatriz Rodriguez, [email protected]") tomerater1.print_users() print("Testing most_read_book tomerater2: Watch My Hand by Nancy P. Magcian") tomerater2.add_user("Beatriz Rodriguez", "*****@*****.**") tomerater2.add_user("Xiomei Li", "*****@*****.**") tomerater2.add_book_to_user(fiction4, "*****@*****.**", 2.5) tomerater2.add_book_to_user(fiction4, "*****@*****.**", 3) tomerater2.add_book_to_user(tomeraternovel1, "*****@*****.**", 4) print(tomerater2.most_read_book())
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) #this is a bad book - it duplicates the previous ISBN. bad_novel = Tome_Rater.create_novel("This should bomb", "Ray Bradbury", 10001000) #Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") Tome_Rater.add_user("Alan Turing", "*****@*****.**") # Try to create a user with a bad email address - should generate an error. Tome_Rater.add_user("Jane Austen", "*****@*****.**") Tome_Rater.add_user("Ruth Bader Ginsburg", "rbg_at_justice.org") #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)
# 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) novel4 = Tome_Rater.create_novel("The Hobbit", "J.R.R. Tolkien", 10002001) novel5 = Tome_Rater.create_novel("The Fellowship of the Ring", "J.R.R. Tolkien", 10002002) novel6 = Tome_Rater.create_novel("The Two Towers", "J.R.R. Tolkien", 10002003) novel7 = Tome_Rater.create_novel("The Return of the King", "J.R.R. Tolkien", 10002004) # Create users: Tome_Rater.add_user("Alan Turing", "*****@*****.**") Tome_Rater.add_user("David Marr", "*****@*****.**") Tome_Rater.add_user("Alice Test", "*****@*****.**") Tome_Rater.add_user("Bob Test", "*****@*****.**") Tome_Rater.add_user("Carly Test", "*****@*****.**") # 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) Tome_Rater.add_book_to_user(novel5, "*****@*****.**", 2)
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) 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)
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) Tome_Rater.add_book_to_user(novel2, "*****@*****.**", 2)