3
# [SNIPPET_NAME: Unit Tests]
4
# [SNIPPET_CATEGORIES: unittest]
5
# [SNIPPET_DESCRIPTION: Example of basic Python unit testing]
6
# [SNIPPET_DOCS: http://docs.python.org/library/unittest.html]
7
# [SNIPPET_AUTHOR: David Futcher <bobbo@ubuntu.com>]
8
# [SNIPPET_LICENSE: MIT]
15
# Adapted from "Writing generators" snippet by Josh Holland <jrh@joshh.co.uk>
16
def fibonacci(start=(0, 1), stop=FIB_STOP):
23
class FibonacciGeneratorTest(unittest.TestCase):
24
""" Basic unit test class to check the above Fibonacci generator """
28
self.correct = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
33
def testStopping(self):
34
# Check the generator stopped when it should have
35
self.assertEqual(FIB_STOP, len(self.fibs))
37
def testNumbers(self):
38
# Check the generated list against our known correct list
39
for i in range(len(self.correct)):
40
self.assertEqual(self.fibs[i], self.correct[i])
42
if __name__ == '__main__':