Skip to content
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

Solution #1206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
34 changes: 31 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
class OnlineCourse:
# write your code here
pass
from __future__ import annotations


class OnlineClass:
def __init__(
self,
name: str,
description: str,
weeks: int
) -> None:
self.name = name
self.description = description
self.weeks = weeks

@classmethod
def from_dict(
cls,
course_dict: dict
) -> OnlineClass:
return OnlineClass(
course_dict.get("name"),
course_dict.get("description"),
cls.days_to_weeks(course_dict.get("days"))
)

@staticmethod
def days_to_weeks(days: int) -> int:
if days % 7 != 0:
return int(days / 7) + 1

return int(days / 7)
10 changes: 5 additions & 5 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from app.main import OnlineCourse
from app.main import OnlineClass


class OnlineClass(OnlineCourse):
class OnlineClass(OnlineClass):
pass


Expand All @@ -16,7 +16,7 @@ class OnlineClass(OnlineCourse):
],
)
def test_constructor(name, description, weeks):
course = OnlineCourse(name=name, description=description, weeks=weeks)
course = OnlineClass(name=name, description=description, weeks=weeks)
assert course.name == name, (
f"Course should have 'name' equal to {name} "
f"when course is created with "
Expand Down Expand Up @@ -52,7 +52,7 @@ def test_constructor(name, description, weeks):
],
)
def test_days_to_weeks(days, weeks):
assert OnlineCourse.days_to_weeks(days) == weeks, (
assert OnlineClass.days_to_weeks(days) == weeks, (
f"Staticmethod 'days_to_weeks' should return {weeks} "
f"when 'days' is equal to {days}"
)
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_days_to_weeks(days, weeks):
],
)
def test_from_dict_method(dictionary, name, description, weeks):
course = OnlineCourse.from_dict(dictionary)
course = OnlineClass.from_dict(dictionary)
assert course.name == name, (
f"Course should have 'name' equal to {name} "
f"when course is created with "
Expand Down
Loading