#------------------------------------------------------------------------------ # 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 TestSieveOutput # # 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 # place your main program in a conditional of the form # # if __name__=='__main__' # # # your code for main program # # # end if # # Note: The above test will likely work on any Linux or Mac computer, not # just the Unix timeshare. If you want to try diff on Windows PowerShell, # you will have to study the diff command in that environment. # #------------------------------------------------------------------------------ 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 -----------------------------------------------------------------