Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new function defination for fibonacci serias #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions py-revision
Submodule py-revision added at 92e766
7 changes: 6 additions & 1 deletion src/revision/mathematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ def hcfOfTwoNumbers(num1,num2):
return hcfOfTwoNumbers(num2, num1%num2)

def lcmOfTwoNumbers(num1,num2):
return (num1 * num2) // hcfOfTwoNumbers(num1,num2)
return (num1 * num2) // hcfOfTwoNumbers(num1,num2)

def fibonacci(n):
if n <= 1:
return n
return (fibonacci(n - 1) + fibonacci(n - 2))
18 changes: 16 additions & 2 deletions tests/unit/test_mathematics.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()