Created
May 23, 2011 03:25
-
-
Save poochin/986172 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/python | |
# -#- coding: utf-8 -*- | |
import unittest | |
class TestHorner(unittest.TestCase): | |
def setUp(self): | |
self.factors = (1, 2, 3, 4, 5) | |
def testhorner(self): | |
self.assertEqual(horner(self.factors, 1), 15) | |
self.assertEqual(horner(self.factors, 2), 129) | |
self.assertEqual(horner(self.factors, 3), 547) | |
self.assertEqual(horner(self.factors, 4), 1593) | |
self.assertEqual(horner(self.factors, 5), 3711) | |
def horner(factors, var): | |
if len(factors): | |
return horner(factors[1:], var) * var + factors[0] | |
return 0 | |
def main(): | |
unittest.main() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment