mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-01 00:41:09 +00:00
9b945cb2b4
* iterative and formula fibonacci methods Added two ways to calculate the fibonacci sequence: (1) iterative (2) formula. I've also added a timer decorator so someone can see the difference in computation time between these two methods. Added two unittests using the slash framework. * Update test_fibonacci.py * remove inline comments per Contributing Guidelines * Update sol5.py * Create placeholder.py * Update and rename maths/test_fibonacci.py to maths/tests/test_fibonacci.py * Delete placeholder.py * Create __init__.py * Update test_fibonacci.py * Rename Maths/lucasSeries.py to maths/lucasSeries.py * Update and rename Project Euler/Problem 01/sol5.py to project_euler/problem_01/sol6.py
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""
|
|
To run with slash:
|
|
1. run pip install slash (may need to install C++ builds from Visual Studio website)
|
|
2. In the command prompt navigate to your project folder
|
|
3. then type--> slash run -vv -k tags:fibonacci ..
|
|
-vv indicates the level of verbosity (how much stuff you want the test to spit out after running)
|
|
-k is a way to select the tests you want to run. This becomes much more important in large scale projects.
|
|
"""
|
|
|
|
import slash
|
|
from .. import fibonacci
|
|
|
|
default_fib = [0, 1, 1, 2, 3, 5, 8]
|
|
|
|
|
|
@slash.tag('fibonacci')
|
|
@slash.parametrize(('n', 'seq'), [(2, [0, 1]), (3, [0, 1, 1]), (9, [0, 1, 1, 2, 3, 5, 8, 13, 21])])
|
|
def test_different_sequence_lengths(n, seq):
|
|
"""Test output of varying fibonacci sequence lengths"""
|
|
iterative = fibonacci.fib_iterative(n)
|
|
formula = fibonacci.fib_formula(n)
|
|
assert iterative == seq
|
|
assert formula == seq
|
|
|
|
|
|
@slash.tag('fibonacci')
|
|
@slash.parametrize('n', [7.3, 7.8, 7.0])
|
|
def test_float_input_iterative(n):
|
|
"""Test when user enters a float value"""
|
|
iterative = fibonacci.fib_iterative(n)
|
|
formula = fibonacci.fib_formula(n)
|
|
assert iterative == default_fib
|
|
assert formula == default_fib
|
|
|