|
Programmer's Notebook |
All computer source code presented on this page, unless it includes attribution to another author, is provided by Ed Halley under the Artistic License. Use such code freely and without any expectation of support. I would like to know if you make anything cool with the code, or need questions answered.
python/ bindings.py boards.py buzz.py cache.py cards.py constraints.py english.py getopts.py gizmos.py goals.py improv.py interpolations.py namespaces.py nihongo.py nodes.py octalplus.py patterns.py persist.py physics.py pieces.py quizzes.py recipes.py relays.py romaji.py ropen.py sheets.py strokes.py subscriptions.py svgbuild.py testing.py things.py timing.py ucsv.py useful.py uuid.py vectors.py weighted.py java/ GlobFilenameFilter.java RegexFilenameFilter.java StringBufferOutputStream.java ThreadSet.java TracingThread.java Utf8ConsoleTest.java perl/ CVQM.pm Kana.pm Typo.pm cxx/ CCache.h equalish.cpp |
# testing - useful routines for running tests ''' A few useful routines for running unit tests. SYNOPSIS import testing ; from testing import * def my_routine(number): return { 'one': 1, 'two': 2, 'three': 3}[number] def __test__(): __ok__( my_routine("three"), 3 ) __report__() AUTHOR Ed Halley (ed@halley.cc) 17 October 2007 ''' __all__ = [ '__ok__', '__time__', '__report__' ] #---------------------------------------------------------------------------- __tests = 0 __fails = 0 def __tests__(): return __tests def __fails__(): return __fails def __ok__(test, expect=True, message=''): global __tests global __fails __tests += 1 if message: message = ' (%s)' % message if (test != expect): __fails += 1 print "Test %d%s: [FAIL] expected %s but got %s" % \ (__tests, message, repr(expect), repr(test)) else: print "Test %d%s: [OK] %s" % \ (__tests, message, repr(expect)) def __time__(name=None, setup='pass', stmt='pass'): if name is None: name = stmt import timeit timer = timeit.Timer(stmt, setup) number = 1000000 timings = timer.repeat(repeat=3, number=number) sec = min(timings) desc = "%.2f us/run" % (1e6*sec/number) print "%18s : %s" % (desc, name) def __report__(): global __tests global __fails if __fails > 0: print 'Total of %d failed tests out of %d tests.' % \ (__fails, __tests) else: print 'Total of %d tests. Success.' % __tests #---------------------------------------------------------------------------- if __name__ == '__main__': raise Exception, \ 'This module is not a stand-alone script. Import it in a program.' |
|
Contact Ed Halley by email at
ed@halley.cc. Text, code, layout and artwork are Copyright © 1996-2008 Ed Halley. Copying in whole or in part, with author attribution, is expressly allowed. Any references to trademarks are illustrative and are controlled by their respective owners. |
|