Question: i need to pass these two test cases: Search Infix: Trees, Count: 1 5 and Search Infix: WIII, Count: 2 5 Tested searchBookByInfix ( Trees
i need to pass these two test cases: Search Infix: "Trees", Count: and Search Infix: "WIII", Count:
Tested searchBookByInfixTreesExpected
Tested searchBookByInfixWIIIExpected
import Book
import ArrayList
import ArrayQueue
import RandomQueue
import DLList
import SLLQueue
import ChainedHashTable
import BinarySearchTree
import BinaryHeap
import AdjacencyList
import time
class BookStore:
BookStore: It simulates a book system such as Amazon. It allows searching,
removing and adding in a shopping cart.
def initself:
self.bookCatalog None
self.shoppingCart ArrayQueue.ArrayQueue
def loadCatalogself fileName: str:
loadCatalog: Read the file filenName and creates the array list with all books.
book records are separated by The order is key,
title, group, rank number of copies sold and similar books
self.bookCatalog ArrayList.ArrayList
with openfileName encoding"utf as f:
# The following line is the time that the computation starts
starttime time.time
for line in f:
key title, group, rank, similar line.split
s Book.Bookkey title, group, rank, similar
self.bookCatalog.appends
# The following line is used to calculate the total time
# of execution
elapsedtime time.time starttime
printfLoading selfbookCatalog.size books in elapsedtime seconds"
def setRandomShoppingCartself:
q self.shoppingCart
starttime time.time
self.shoppingCart RandomQueue.RandomQueue
while qsize:
self.shoppingCart.addqremove
elapsedtime time.time starttime
printfSetting radomShoppingCart in elapsedtime seconds"
def setShoppingCartself:
q self.shoppingCart
starttime time.time
self.shoppingCart ArrayQueue.ArrayQueue
while qsize:
self.shoppingCart.addqremove
elapsedtime time.time starttime
printfSetting radomShoppingCart in elapsedtime seconds"
def removeFromCatalogself i: int:
removeFromCatalog: Remove from the bookCatalog the book with the index i
input:
i: positive integer
# The following line is the time that the computation starts
starttime time.time
self.bookCatalog.removei
# The following line is used to calculate the total time
# of execution
elapsedtime time.time starttime
printfRemove book i from books in elapsedtime seconds"
def addBookByIndexself i: int:
addBookByIndex: Inserts into the playlist the song of the list at index i
input:
i: positive integer
# Validating the index. Otherwise it crashes
if i and i self.bookCatalog.size:
starttime time.time
s self.bookCatalog.geti
self.shoppingCart.adds
elapsedtime time.time starttime
printfAdded to shopping cart s
elapsedtime seconds"
def searchBookByInfixself infix: str:
searchBookByInfix: Search all the books that contains infix
input:
infix: A string
starttime time.time
# todo
elapsedtime time.time starttime
printfsearchBookByInfix Completed in elapsedtime seconds"
def removeFromShoppingCartself:
removeFromShoppingCart: remove one book from the shoppung cart
starttime time.time
if self.shoppingCart.size:
u self.shoppingCart.remove
elapsedtime time.time starttime
printfremoveFromShoppingCart u Completed in elapsedtime seconds"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
