diff --git a/py-revision b/py-revision new file mode 160000 index 0000000..92e766d --- /dev/null +++ b/py-revision @@ -0,0 +1 @@ +Subproject commit 92e766decd782f0a53b9fb10f004324a9da7187d diff --git a/src/revision/mathematics.py b/src/revision/mathematics.py index 78954c7..4b0c5b5 100644 --- a/src/revision/mathematics.py +++ b/src/revision/mathematics.py @@ -43,4 +43,9 @@ def hcfOfTwoNumbers(num1,num2): return hcfOfTwoNumbers(num2, num1%num2) def lcmOfTwoNumbers(num1,num2): - return (num1 * num2) // hcfOfTwoNumbers(num1,num2) \ No newline at end of file + return (num1 * num2) // hcfOfTwoNumbers(num1,num2) + +def fibonacci(n): + if n <= 1: + return n + return (fibonacci(n - 1) + fibonacci(n - 2)) \ No newline at end of file diff --git a/tests/unit/test_mathematics.py b/tests/unit/test_mathematics.py index 499799f..3d6301b 100644 --- a/tests/unit/test_mathematics.py +++ b/tests/unit/test_mathematics.py @@ -1,6 +1,6 @@ import unittest -from src.revision.mathematics import sum, factorial, convert_temperature, lcm, hcf +from src.revision.mathematics import sum, factorial, convert_temperature, lcm, hcf, fibonacci class Test(unittest.TestCase): @@ -108,7 +108,21 @@ def test_hcf_of_given_multiple_numbers_is_8(self): self.assertEqual(result, 8) - + def test_fifth_term_of_fibonacci_is_5(self): + """ + Test that sum of 3rd and 4th term is 5th that is 5 + """ + result = fibonacci(5) + + self.assertEqual(result, 5) + + def test_fourteenth_term_of_fibonacci_is_377(self): + """ + Test that sum of 12th and 13th term is 14th that is 377 + """ + result = fibonacci(14) + + self.assertEqual(result, 377) if __name__ == '__main__': unittest.main() \ No newline at end of file