diff options
author | Srikant | 2012-01-24 16:19:59 +0530 |
---|---|---|
committer | Srikant | 2012-01-24 16:19:59 +0530 |
commit | 2965bf37bb8fc6c6d672d6775612531e4a3074ba (patch) | |
tree | 72fd647da1fe30c6ae57ecbd264ac6a0498731a2 /TDD/math_utils | |
parent | b5a5acdddb2ef001e9c97a2959b0dbff9096423c (diff) | |
download | sdes-stscripts-2965bf37bb8fc6c6d672d6775612531e4a3074ba.tar.gz sdes-stscripts-2965bf37bb8fc6c6d672d6775612531e4a3074ba.tar.bz2 sdes-stscripts-2965bf37bb8fc6c6d672d6775612531e4a3074ba.zip |
Added supporting files.
Added script and slides for 'using_python_framework_for_tdd',
math_utils diretory contains files used in the tutorials,
two_column.py is added to convert script.rst into
two column format.Use it as:
$ two_column.py tdd1_script.rst
image dir contains png files for iitb logo's etc.
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() |