Skip to content

Instantly share code, notes, and snippets.

@henrikh
Created April 30, 2010 13:07
Show Gist options
  • Select an option

  • Save henrikh/385161 to your computer and use it in GitHub Desktop.

Select an option

Save henrikh/385161 to your computer and use it in GitHub Desktop.
from test import Test
square = lambda x: x**2
squareTest = Test(square)
squareTest.addTests(([2], 2*2),
([3], 3*3),
([1000], 1000*1000))
squareTest.run()
class Test:
def __init__(self, func):
self.tests = []
self.func = func
def addTest(self, arguments, expectedResult):
self.tests.append((arguments, expectedResult))
def addTests(self, *tests):
self.tests.extend(tests)
def run(self):
print "Running Tests"
print "-------------"
numberFailed = 0
for i, test in enumerate(self.tests):
print "Runing test %d :" % (i + 1),
if self.func(*test[0]) == test[-1]:
print "Done."
else:
print "FAILED!!!"
numberFailed = numberFailed + 1
print "-------------"
print "Ran: %d, Failed: %d" % (len(self.tests), numberFailed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment