diff options
Diffstat (limited to 'TDD/math_utils')
-rw-r--r-- | TDD/math_utils/fibonacci.py | 7 | ||||
-rw-r--r-- | TDD/math_utils/fibonacci_testcases.dat | 8 | ||||
-rw-r--r-- | TDD/math_utils/test_fibonacci.py | 27 |
3 files changed, 42 insertions, 0 deletions
diff --git a/TDD/math_utils/fibonacci.py b/TDD/math_utils/fibonacci.py new file mode 100644 index 0000000..0f454d6 --- /dev/null +++ b/TDD/math_utils/fibonacci.py @@ -0,0 +1,7 @@ +def fibonacci(n): + if n == 0: + return 0 + elif n == 1: + return 1 + else: + return fibonacci(n-1) + fibonacci(n-2) diff --git a/TDD/math_utils/fibonacci_testcases.dat b/TDD/math_utils/fibonacci_testcases.dat new file mode 100644 index 0000000..c5dae1a --- /dev/null +++ b/TDD/math_utils/fibonacci_testcases.dat @@ -0,0 +1,8 @@ +0, 0 +1, 1 +2, 1 +3, 2 +4, 3 +5, 5 +6, 8 +7, 13 diff --git a/TDD/math_utils/test_fibonacci.py b/TDD/math_utils/test_fibonacci.py new file mode 100644 index 0000000..ee3393f --- /dev/null +++ b/TDD/math_utils/test_fibonacci.py @@ -0,0 +1,27 @@ +import fibonacci +import unittest + +class TestFibonacciFunction(unittest.TestCase): + + def setUp(self): + self.test_file = open('fibonacci_testcases.dat') + self.test_cases = [] + for line in self.test_file: + values = line.split(', ') + n = int(values[0]) + a = int(values[1]) + + self.test_cases.append([n, a]) + + def test_fibonacci(self): + for case in self.test_cases: + n = case[0] + a = case[1] + self.assertEqual(fibonacci.fibonacci(n),a) + + def tearDown(self): + self.test_file.close() + del self.test_cases + +if __name__ == '__main__': + unittest.main() |