I have a module, mycalc.py, which is a collection of functions designed to be imported independently.

I've heard about using assert() to check up on whether things are still working correctly, or something like that. So I've begun to write some assert() expressions(?)  and put them at the bottom of the module.

if __name__ == '__main__':      
         assert(numberCommas('7657657.7554') == '7,657,657.7554')
         assert(intCommas(76576577554) == '76,576,577,554')
         assert(nextNPrimes(1000000000000,10) == [1000000000039L, 1000000000061L, 1000000000063L, 1000000000091L, 1000000000121L, 1000000000163L, 1000000000169L, 1000000000177L, 1000000000189L, 1000000000193L])
         maxDiffBetPrimes(101)
         printTime(1215322947.0320001, 1215322934.0398701)
         printTime(1215323947.0320001, 1215323011.4567342)
         printTime(1215322947.0320001, 1215312921.0054233)

OUTPUT:
For primes up through 101, max diff is 8
between the 1 pair(s) of primes [(89, 97)]
Time was 12.99 seconds
Time was 15 minutes, 35 seconds
Time was 2 hours, 47 minutes, 6 seconds

The top three work silently, but I found that I could not figure out how to use assert() with the functions that print rather than return. E.g., maxDiffBetPrimes() and printTime(). Is there a way?

If it'll help, here's printTime():
def printTime(timeEnd, timeStart):
    from mycalc import hmsToText
    timeElapsed = timeEnd - timeStart
    if timeElapsed > 60:
        print "Time was", hmsToText(timeElapsed)
    else:
        print "Time was %.4g seconds" % timeElapsed

Thanks,

Dick Moores
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to