Created
April 30, 2010 13:07
-
-
Save henrikh/385161 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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