mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Updated README
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
"""Tower of Hanoi."""
|
||||
|
||||
# @author willx75
|
||||
# Tower of Hanoi recursion game algorithm is a game, it consists of three rods
|
||||
# and a number of disks of different sizes, which can slide onto any rod
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger()
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def Tower_Of_Hanoi(n, source, dest, by, movement):
|
||||
"""Tower of Hanoi - Move plates to different rods."""
|
||||
if n == 0:
|
||||
return n
|
||||
elif n == 1:
|
||||
movement += 1
|
||||
# no print statement
|
||||
# (you could make it an optional flag for printing logs)
|
||||
logging.debug('Move the plate from', source, 'to', dest)
|
||||
return movement
|
||||
else:
|
||||
|
||||
movement = movement + Tower_Of_Hanoi(n - 1, source, by, dest, 0)
|
||||
logging.debug('Move the plate from', source, 'to', dest)
|
||||
|
||||
movement = movement + 1 + Tower_Of_Hanoi(n - 1, by, dest, source, 0)
|
||||
return movement
|
||||
@@ -1 +0,0 @@
|
||||
from .. import fibonacci
|
||||
@@ -1,34 +0,0 @@
|
||||
"""
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user