def test_clCountSort_c(term,method,times): # get the runtime parameters searchString = term searchType = method loopCount = times # run the test as many times as specified in the command line argument for i in range(loopCount): # read the previous timer total from the file fr = open('timer.txt', 'r') contents = fr.readline() if contents == "" : # if the file is empty, start with zero oldTotal = float(0) else : oldTotal = float(contents) fr.close() # run the count and sort method with search string and search type from run time parameters c = clCountSort() fileName1, fileCount1, fileName2, fileCount2, fileName3, fileCount3, runTime = c.methCountSort(searchString,searchType) #write the new timer total back to the file fw = open('timer.txt', 'w') newTotal = oldTotal + float(runTime) fw.write(str(newTotal)) fw.close()
def test_clCountSort_c(): searchString = "and" searchType = "3" c = clCountSort() fileName1, fileCount1, fileName2, fileCount2, fileName3, fileCount3, totalTime = c.methCountSort( searchString, searchType) assert fileName1 == "french_armed_forces.txt" assert fileCount1 == 30 assert fileName2 == "hitchhikers.txt" assert fileCount2 == 11 assert fileName3 == "warp_drive.txt" assert fileCount3 == 3 print("\nTotal Time test test_clCountSort_c:", totalTime)
def test_clCountSort_a(): searchString = "the" searchType = "1" a = clCountSort() fileName1, fileCount1, fileName2, fileCount2, fileName3, fileCount3, totalTime = a.methCountSort( searchString, searchType) assert fileName1 == "french_armed_forces.txt" assert fileCount1 == 59 assert fileName2 == "hitchhikers.txt" assert fileCount2 == 24 assert fileName3 == "warp_drive.txt" assert fileCount3 == 9 print("\nTotal Time test test_clCountSort_a:", totalTime)
def test_clCountSort_b(): searchString = "an" searchType = "2" b = clCountSort() fileName1, fileCount1, fileName2, fileCount2, fileName3, fileCount3, totalTime = b.methCountSort( searchString, searchType) assert fileName1 == "french_armed_forces.txt" assert fileCount1 == 88 assert fileName2 == "hitchhikers.txt" assert fileCount2 == 23 assert fileName3 == "warp_drive.txt" assert fileCount3 == 14 print("\nTotal Time test test_clCountSort_b:", totalTime)
# * 6) respond to prompts * # * 7) evaluate results * # ****************************************************************************** # This program will run the DocumentSearch.py program by calling the three methods. import pytest from DocumentSearch import clSearchString, clSearchType, clCountSort # RUN the methSearchString and methSearchType methods, # then pass the results to the methCountSort method s = clSearchString() #instantiate the Search String class searchString = s.methSearchString() #get the search string t = clSearchType() #instantiate the Search Type class searchType = t.methSearchType() #get the search type u = clCountSort() #instantiate the Count Sort class #count occurrences and and sort the results fileName1, fileCount1, fileName2, fileCount2, fileName3, fileCount3, timerResult = u.methCountSort( searchString, searchType) # PRINT the results print("\nSearch Results") print(" ", fileName1, " - ", fileCount1, "matches") print(" ", fileName2, " - ", fileCount2, "matches") print(" ", fileName3, " - ", fileCount3, "matches") print("\nElapsed Time: ", timerResult, "ms\n")