Skip to content

Артеменко Катерина ІМ-42 #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions екзамен/day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def parse_day(s):
days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
s_lower = s.lower()
for i, day in enumerate(days):
if s_lower.startswith(day):
return i + 1
return -1
22 changes: 22 additions & 0 deletions екзамен/daytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def parse_day(s):
days = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
s_lower = s.lower().strip() # Convert input to lowercase and trim whitespace
for i, day in enumerate(days):
if s_lower.startswith(day):
return i + 1
return -1

import pytest

@pytest.mark.parametrize("input_data, expected", [
(["friday"], 6),
(["Friday"], 6),
(["Fri"], 6),
(["monday"], 2),
(["Mon"], 2),
(["abc"], -1),
([""], -1),
([" fri"], 6),
])
def test_parse_day(input_data, expected):
assert parse_day(*input_data) == expected
13 changes: 13 additions & 0 deletions екзамен/duplicate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def duplicate(value, n):
"""Generate a list with the given value repeated n times.

Args:
value: The value to be duplicated.
n (int): The number of times to duplicate the value.

Returns:
list: A list containing the duplicated values.
"""
if n <= 0:
return []
return [value] * n
12 changes: 12 additions & 0 deletions екзамен/duplicatetest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest
from duplicate import duplicate

@pytest.mark.parametrize("input_data, expected", [
(["abc", 5], ["abc", "abc", "abc", "abc", "abc"]),
(["abc", 1], ["abc"]),
(["abc", -1], []),
(["abc", 0], []),
(["", 0], []),
])
def test_duplicate(input_data, expected):
assert duplicate(*input_data) == expected
10 changes: 10 additions & 0 deletions екзамен/mounth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def get_month_number(s):
months = [
'jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec'
]
s_lower = s.lower()
for i, month in enumerate(months):
if s_lower.startswith(month):
return i + 1
return -1
14 changes: 14 additions & 0 deletions екзамен/mounthtest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
from month import get_month_number

@pytest.mark.parametrize("input_data, expected", [
(["january"], 1),
(["february"], 2),
(["feb"], 2),
(["February"], 2),
(["Feb"], 2),
(["abc"], -1),
([""], -1),
])
def test_get_month_number(input_data, expected):
assert get_month_number(*input_data) == expected