Skip to content
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
3 changes: 3 additions & 0 deletions participants/scipy_016/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.python-version
pyproject.toml
uv.lock
10 changes: 6 additions & 4 deletions participants/scipy_016/pr_tutorial/buggy_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math


def angle_to_sexigesimal(angle_in_degrees, decimals=3):
def angle_to_sexigesimal(angle_in_degrees: float, decimals=3):
"""
Convert the given angle to a sexigesimal string of hours of RA.

Expand All @@ -20,13 +20,15 @@ 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
assert angle_in_degrees >= 0
assert angle_in_degrees <= 360

hours_num = angle_in_degrees*6/180.
hours = math.floor(hours_num)

min_num = (hours_num - hours)*60
minutes = math.floor(min_num)

seconds = (min_num - minutes)*60

format_string = '{}:{}:{:.' + str(decimals) + 'f}'
return format_string.format(hours, minutes, seconds)
return f"{int(hours)}:{int(minutes)}:{int(seconds)}"
10 changes: 5 additions & 5 deletions participants/scipy_016/pr_tutorial/simple_functions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
def fibonacci(max):
def fibonacci(n_terms: int) -> list:
values = [0, 1]
while values[-2] + values[-1] < max:
while len(values) < n_terms:
values.append(values[-2] + values[-1])
return values


def factorial(value):
def factorial(value: int):
if value == 0:
return 1
else:
return value * factorial(value - 1)

return value * factorial(value - 1)
17 changes: 17 additions & 0 deletions participants/scipy_016/pr_tutorial/tests/test_buggy_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest

from pr_tutorial.buggy_function import angle_to_sexigesimal


@pytest.mark.parametrize(
"angle, expected",
[
(0, "0:0:0"),
(90, "3:0:0"),
(30, "1:0:0"),
(45, "1:30:0"),
(60, "2:0:0"),
],
)
def test__angle_to_sexigesimal(angle: float, expected: str):
assert angle_to_sexigesimal(angle) == expected
28 changes: 25 additions & 3 deletions participants/scipy_016/pr_tutorial/tests/test_simple_function.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
from pr_tutorial.simple_functions import factorial
import pytest

from pr_tutorial.simple_functions import factorial,fibonacci

def test_factorial_3():


@pytest.mark.parametrize("value, expected", [
(0, 1),
(3, 6),
(5, 120),
])
def test_factorial_3(value: int, expected: int):
"""Simplest test for one crete case"""

assert factorial(3) == 6
assert factorial(value) == expected


@pytest.mark.parametrize("n_terms, expected", [
(0, [0, 1]),
(1, [0, 1]),
(2, [0, 1]),
(5, [0, 1, 1, 2, 3]),
(10, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]),
])
def test__fibonacci(n_terms: int, expected: list[int]):
"""Simplest test for one crete case"""

assert fibonacci(n_terms) == expected