diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..182f34c --- /dev/null +++ b/.gitignore @@ -0,0 +1,122 @@ +Source: https://github.com/github/gitignore/blob/master/Python.gitignore + +# User generated +ENV/ +.vscode +.idea +.DS_Store +.history + + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +.pytest_cache/ + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +.static_storage/ +.media/ +local_settings.py + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# js +node_modules/ +.next/ + +# poetry +poetry.lock \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..506fdf7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "ponicode.testSettings.testLocation.locationType": "Same folder as source file", + "ponicode.testSettings.testLocation.path": "{rootDir}/{filePath}/{fileName}.test.{ext}" +} \ No newline at end of file diff --git a/README.md b/README.md index e69de29..fec2007 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +https://github.com/MsDiala/math-series/pull/1 + +the pull req for the branch \ No newline at end of file diff --git a/math_series/math_series.py b/math_series/math_series.py deleted file mode 100644 index e69de29..0000000 diff --git a/math_series/series.py b/math_series/series.py new file mode 100644 index 0000000..326d969 --- /dev/null +++ b/math_series/series.py @@ -0,0 +1,57 @@ +def fibonacci(n): ##Function that returns value of the given index from Fibonacci sequence + ''' + Given an integer value n, this function returns the nth value of the Fibonacci Numbers. + ''' + if isinstance(n, str): + #The isinstance() function returns True if the specified object + #is of the specified type, otherwise False. + raise TypeError("n must be an integer greater than or equal to 0.") # The raise keyword is used to raise an exception. + elif n < 0: + prompt = "n must be an integer greater than or equal to 0." + return prompt + elif n == 0: + fibonacciOfN = 0 + return fibonacciOfN + elif n == 1 or n == 2: + fibonacciOfN = 1 + return fibonacciOfN + elif n > 2: + fibonacciOfN = fibonacci(n-1) + fibonacci(n-2) + return fibonacciOfN + + +def lucas(n): ###Function that returns value of the given index from Lucas sequence + ''' + Given an integer value n, this function returns the nth value of the Lucas Numbers. + ''' + if n < 0: + prompt = "n must be an integer greater than or equal to 0." + return prompt + elif n == 0: + lucasOfN = 2 + return lucasOfN + elif n == 1: + lucasOfN = 1 + return lucasOfN + elif n >= 2: + lucasOfN = lucas(n-1) + lucas(n-2) + return lucasOfN + + +def sum_series(n, arg1=0, arg2=1): ###Function that returns value of the given index from Custom fibonacci-like sequence + # pass + ''' + Given an integer value n and two optional terms arg1 and arg2, this function returns the nth value of the user-specified Fibonacci or Lucas numbers (defaults to Fibonacci if no optional terms provarged). + ''' + if n < 0: + prompt = "n must be an integer greater than or equal to 0." + return prompt + elif arg1 == 0 and arg2 == 1: + fibonacciOfN = fibonacci(n) + return fibonacciOfN + elif arg1 == 2 and arg2 == 1: + lucasOfN = lucas(n) + return lucasOfN + else: + noSum = "Sorry, that sum is not defined." + return noSum \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 7799713..05333fe 100644 --- a/poetry.lock +++ b/poetry.lock @@ -6,6 +6,19 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "astroid" +version = "2.4.2" +description = "An abstract syntax tree for Python with inference support." +category = "dev" +optional = false +python-versions = ">=3.5" + +[package.dependencies] +lazy-object-proxy = ">=1.4.0,<1.5.0" +six = ">=1.12,<2.0" +wrapt = ">=1.11,<2.0" + [[package]] name = "atomicwrites" version = "1.4.0" @@ -66,6 +79,35 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +[[package]] +name = "isort" +version = "5.6.4" +description = "A Python utility / library to sort Python imports." +category = "dev" +optional = false +python-versions = ">=3.6,<4.0" + +[package.extras] +pipfile_deprecated_finder = ["pipreqs", "requirementslib"] +requirements_deprecated_finder = ["pipreqs", "pip-api"] +colors = ["colorama (>=0.4.3,<0.5.0)"] + +[[package]] +name = "lazy-object-proxy" +version = "1.4.3" +description = "A fast and thorough lazy object proxy." +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" + +[[package]] +name = "mccabe" +version = "0.6.1" +description = "McCabe checker, plugin for flake8" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "more-itertools" version = "8.6.0" @@ -120,6 +162,21 @@ category = "dev" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +[[package]] +name = "pylint" +version = "2.6.0" +description = "python code static checker" +category = "dev" +optional = false +python-versions = ">=3.5.*" + +[package.dependencies] +astroid = ">=2.4.0,<=2.5" +colorama = {version = "*", markers = "sys_platform == \"win32\""} +isort = ">=4.2.5,<6" +mccabe = ">=0.6,<0.7" +toml = ">=0.7.1" + [[package]] name = "pyparsing" version = "2.4.7" @@ -158,6 +215,14 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "six" +version = "1.15.0" +description = "Python 2 and 3 compatibility utilities" +category = "dev" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*" + [[package]] name = "toml" version = "0.10.2" @@ -190,16 +255,28 @@ category = "dev" optional = false python-versions = "*" +[[package]] +name = "wrapt" +version = "1.12.1" +description = "Module for decorators, wrappers and monkey patching." +category = "dev" +optional = false +python-versions = "*" + [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "a3cb18db29ab8af84779030431ca7b5e9750b406e0611d6e52533149660fdcbf" +content-hash = "46249a75e86498b55d7355a92802c353a0e151985ee627a08f4bc2d1d7ea9a57" [metadata.files] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, ] +astroid = [ + {file = "astroid-2.4.2-py3-none-any.whl", hash = "sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386"}, + {file = "astroid-2.4.2.tar.gz", hash = "sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703"}, +] atomicwrites = [ {file = "atomicwrites-1.4.0-py2.py3-none-any.whl", hash = "sha256:6d1784dea7c0c8d4a5172b6c620f40b6e4cbfdf96d783691f2e1302a7b88e197"}, {file = "atomicwrites-1.4.0.tar.gz", hash = "sha256:ae70396ad1a434f9c7046fd2dd196fc04b12f9e91ffb859164193be8b6168a7a"}, @@ -219,6 +296,37 @@ colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, ] +isort = [ + {file = "isort-5.6.4-py3-none-any.whl", hash = "sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7"}, + {file = "isort-5.6.4.tar.gz", hash = "sha256:dcaeec1b5f0eca77faea2a35ab790b4f3680ff75590bfcb7145986905aab2f58"}, +] +lazy-object-proxy = [ + {file = "lazy-object-proxy-1.4.3.tar.gz", hash = "sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-macosx_10_13_x86_64.whl", hash = "sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-win32.whl", hash = "sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27m-win_amd64.whl", hash = "sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a"}, + {file = "lazy_object_proxy-1.4.3-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-manylinux1_x86_64.whl", hash = "sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-win32.whl", hash = "sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e"}, + {file = "lazy_object_proxy-1.4.3-cp34-cp34m-win_amd64.whl", hash = "sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-win32.whl", hash = "sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db"}, + {file = "lazy_object_proxy-1.4.3-cp35-cp35m-win_amd64.whl", hash = "sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-win32.whl", hash = "sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531"}, + {file = "lazy_object_proxy-1.4.3-cp36-cp36m-win_amd64.whl", hash = "sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-win32.whl", hash = "sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142"}, + {file = "lazy_object_proxy-1.4.3-cp37-cp37m-win_amd64.whl", hash = "sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-win32.whl", hash = "sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd"}, + {file = "lazy_object_proxy-1.4.3-cp38-cp38-win_amd64.whl", hash = "sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239"}, +] +mccabe = [ + {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, + {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, +] more-itertools = [ {file = "more-itertools-8.6.0.tar.gz", hash = "sha256:b3a9005928e5bed54076e6e549c792b306fddfe72b2d1d22dd63d42d5d3899cf"}, {file = "more_itertools-8.6.0-py3-none-any.whl", hash = "sha256:8e1a2a43b2f2727425f2b5839587ae37093f19153dc26c0927d1048ff6557330"}, @@ -243,6 +351,10 @@ py = [ {file = "py-1.9.0-py2.py3-none-any.whl", hash = "sha256:366389d1db726cd2fcfc79732e75410e5fe4d31db13692115529d34069a043c2"}, {file = "py-1.9.0.tar.gz", hash = "sha256:9ca6883ce56b4e8da7e79ac18787889fa5206c79dcc67fb065376cd2fe03f342"}, ] +pylint = [ + {file = "pylint-2.6.0-py3-none-any.whl", hash = "sha256:bfe68f020f8a0fece830a22dd4d5dddb4ecc6137db04face4c3420a46a52239f"}, + {file = "pylint-2.6.0.tar.gz", hash = "sha256:bb4a908c9dadbc3aac18860550e870f58e1a02c9f2c204fdf5693d73be061210"}, +] pyparsing = [ {file = "pyparsing-2.4.7-py2.py3-none-any.whl", hash = "sha256:ef9d7589ef3c200abe66653d3f1ab1033c3c419ae9b9bdb1240a85b024efc88b"}, {file = "pyparsing-2.4.7.tar.gz", hash = "sha256:c203ec8783bf771a155b207279b9bccb8dea02d8f0c9e5f8ead507bc3246ecc1"}, @@ -294,6 +406,10 @@ regex = [ {file = "regex-2020.11.13-cp39-cp39-win_amd64.whl", hash = "sha256:a15f64ae3a027b64496a71ab1f722355e570c3fac5ba2801cafce846bf5af01d"}, {file = "regex-2020.11.13.tar.gz", hash = "sha256:83d6b356e116ca119db8e7c6fc2983289d87b27b3fac238cfe5dca529d884562"}, ] +six = [ + {file = "six-1.15.0-py2.py3-none-any.whl", hash = "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced"}, + {file = "six-1.15.0.tar.gz", hash = "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259"}, +] toml = [ {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, @@ -339,3 +455,6 @@ wcwidth = [ {file = "wcwidth-0.2.5-py2.py3-none-any.whl", hash = "sha256:beb4802a9cebb9144e99086eff703a642a13d6a0052920003a230f3294bbe784"}, {file = "wcwidth-0.2.5.tar.gz", hash = "sha256:c4d647b99872929fdb7bdcaa4fbe7f01413ed3d98077df798530e5b04f116c83"}, ] +wrapt = [ + {file = "wrapt-1.12.1.tar.gz", hash = "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"}, +] diff --git a/pyproject.toml b/pyproject.toml index af5ad25..89dc7cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ python = "^3.9" [tool.poetry.dev-dependencies] pytest = "^5.2" black = {version = "^20.8b1", allow-prereleases = true} +pylint = "^2.6.0" [build-system] requires = ["poetry-core>=1.0.0"] diff --git a/tests/test_math_series.py b/tests/test_math_series.py deleted file mode 100644 index a979ccb..0000000 --- a/tests/test_math_series.py +++ /dev/null @@ -1,5 +0,0 @@ -from math_series import __version__ - - -def test_version(): - assert __version__ == '0.1.0' diff --git a/tests/test_series.py b/tests/test_series.py new file mode 100644 index 0000000..bd9ac4e --- /dev/null +++ b/tests/test_series.py @@ -0,0 +1,110 @@ +import pytest +from math_series.series import fibonacci , lucas , sum_series + +# from math_series.math_series import fibonacci + +def test_fib_exists(): + assert fibonacci + + +def test_lucas_exists(): + assert lucas + + +def test_sum_series_exists(): + assert sum_series + + +# ************* Fibonacci series tests ************ + +def test_fib_0(): + expected = 0 + actual = fibonacci(0) + assert actual == expected + + +def test_fib_false_pos(): + expected = 0 + actual = fibonacci(1) + assert actual != expected + + +def test_fib_less_than_0(): + expected = "n must be an integer greater than or equal to 0." + actual = fibonacci(-1) + assert actual == expected + + +def test_fib_str_0(): + with pytest.raises(TypeError): + assert fibonacci("0") is TypeError + + +def test_fib_int1(): + expected = 1 + actual = fibonacci(1) + assert actual == expected + + +def test_fib_int2(): + expected = 1 + actual = fibonacci(2) + assert actual == expected + + +def test_fib_int5(): + expected = 2 + 3 + actual = fibonacci(5) + assert actual == expected + + +# ************* Lucas series tests ************ + +def test_luc_0_pass(): + expected = 2 + actual = lucas(0) + assert actual == expected + + +def test_luc_0_false_pos(): + expected = 2 + actual = lucas(1) + assert actual != expected + + +def test_luc_less_than_0(): + expected = "n must be an integer greater than or equal to 0." + actual = lucas(-1) + assert actual == expected + + +def test_luc_4(): + expected = 3 + 4 + actual = lucas(4) + assert actual == expected + + +# ************* Sum series tests ************ + +def test_sum_series_fib_0(): + expected = 0 + actual = sum_series(0, 0, 1) + assert actual == expected + + +def test_sum_series_lucas_0(): + expected = 2 + actual = sum_series(0, 2, 1) + assert actual == expected + + +def test_sum_series_less_than_zero(): + expected = "n must be an integer greater than or equal to 0." + actual = sum_series(-1,0,1) + assert actual == expected + + +def test_sum_series_not_fib_luc(): + expected = "Sorry, that sum is not defined." + actual = sum_series(4, 1, 2) + assert actual == expected \ No newline at end of file