diff --git a/participants/scipy_001/doc/README.md b/participants/scipy_001/doc/README.md index a1542d9..d7ebbf8 100644 --- a/participants/scipy_001/doc/README.md +++ b/participants/scipy_001/doc/README.md @@ -1,5 +1,5 @@ -Ok so I guess you are reading this cuz you wanna use my code. There are some -functions that do stuf and thats: +Ok so I guess you are reading this because you would like to use this code. There are some +functions that do things: >>> from simple_functions import factorial >>> factorial(10) diff --git a/participants/scipy_001/pr_tutorial/buggy_function.py b/participants/scipy_001/pr_tutorial/buggy_function.py index 6f38a6b..1c0cce2 100644 --- a/participants/scipy_001/pr_tutorial/buggy_function.py +++ b/participants/scipy_001/pr_tutorial/buggy_function.py @@ -20,13 +20,21 @@ def angle_to_sexigesimal(angle_in_degrees, decimals=3): if math.floor(decimals) != decimals: raise OSError('decimals should be an integer!') - hours_num = angle_in_degrees*24/180 + hours_num = angle_in_degrees * 24 / 180 hours = math.floor(hours_num) - min_num = (hours_num - hours)*60 + min_num = (hours_num - hours) * 60 minutes = math.floor(min_num) - seconds = (min_num - minutes)*60 + seconds = (min_num - minutes) * 60 + frac = math.floor((seconds % 1) * 10 ** decimals) + + seconds = math.floor(seconds) + format_string = '{:02d}:{:02d}:{:02d}.{:0' + str(decimals) + 'd}' + return format_string.format(hours, minutes, seconds, frac) - format_string = '{}:{}:{:.' + str(decimals) + 'f}' - return format_string.format(hours, minutes, seconds) +def angle_test(): + sex = angle_to_sexigesimal(32.231515, decimals=3) + assert sex == '04:17:51.127' + +angle_test() diff --git a/participants/scipy_001/pr_tutorial/tests/test_function.py b/participants/scipy_001/pr_tutorial/tests/test_function.py new file mode 100644 index 0000000..e111fb3 --- /dev/null +++ b/participants/scipy_001/pr_tutorial/tests/test_function.py @@ -0,0 +1,6 @@ +from pr_tutorial.buggy_function import angle_to_sexigesimal + +def test_angle(): + sex = angle_to_sexigesimal(32.231515, decimals=3) + assert sex == '04:17:51.127' +