#------------------------------------------------------------------------------ # TestSieve.py # Tests function makeSieve() in program Sieve.py # # Place this program in the same directory as Sieve.py, and run it. The # expected output is contained in the file TestSieveOut. # # To test your program on the Unix timeshare, transfer the files Sieve.py, # TestSieve.py and TestSieveOut to the timeshare and place them in the same # directory. Perform the following commands. # # python3 TestSieve.py > myOutput # diff myOutput TestSieveOut # # The second line should have no output. In other words, if diff gives any # output at all, then the two files are not identical. This would indicate # either that your makeSieve() function is incorrect, or that you did not # follow example GeneralTemplate.py by placing your main program in a # function called main(), and call it from a conditional statement. # # def main(): # # your code for main program # # # # # end main() # # if __name__=='__main__' # # main() # # # end if # # The above test will work on any Linux or Mac computer, not just the Unix # timeshare. If you want to do the same test on Windows PowerShell, use the # following form of the diff command. # # python TestSieve.py > myOutput # diff (cat myOutput) (cat TestSieveOut) # # Again, no output means the files myOutput and TestSieveOut are identical. # #------------------------------------------------------------------------------ import Sieve S = Sieve.makeSieve(500) sum = 0 primeCount = [] for q in S: if q: sum += 1 primeCount.append(sum) # end for print(' n \t number of primes <= n') print('------------------------------') for n in range(2, len(primeCount)): print('', n , '\t', primeCount[n]) # end for # end program -----------------------------------------------------------------