From d97a9c21e7cff5f60260dd49eb45ff4f3cbebe68 Mon Sep 17 00:00:00 2001 From: IvankaKuzin Date: Thu, 5 Dec 2024 19:01:20 +0200 Subject: [PATCH 1/3] Solution --- app/main.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..ff1cc9a7 100644 --- a/app/main.py +++ b/app/main.py @@ -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) From bb816d4240fa9f182cc146626053a9a420471480 Mon Sep 17 00:00:00 2001 From: IvankaKuzin Date: Thu, 5 Dec 2024 19:03:31 +0200 Subject: [PATCH 2/3] rename class --- app/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/main.py b/app/main.py index ff1cc9a7..540f62ad 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ from __future__ import annotations -class OnlineClass: +class OnlineCourse: def __init__( self, name: str, @@ -16,8 +16,8 @@ def __init__( def from_dict( cls, course_dict: dict - ) -> OnlineClass: - return OnlineClass( + ) -> OnlineCourse: + return OnlineCourse( course_dict.get("name"), course_dict.get("description"), cls.days_to_weeks(course_dict.get("days")) From b69c59f260ab0469c4e084c3d734c3d141e31bd7 Mon Sep 17 00:00:00 2001 From: IvankaKuzin Date: Thu, 5 Dec 2024 19:24:27 +0200 Subject: [PATCH 3/3] changed the name of the class for passing tests --- app/main.py | 6 +++--- tests/test_main.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/main.py b/app/main.py index 540f62ad..ff1cc9a7 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ from __future__ import annotations -class OnlineCourse: +class OnlineClass: def __init__( self, name: str, @@ -16,8 +16,8 @@ def __init__( def from_dict( cls, course_dict: dict - ) -> OnlineCourse: - return OnlineCourse( + ) -> OnlineClass: + return OnlineClass( course_dict.get("name"), course_dict.get("description"), cls.days_to_weeks(course_dict.get("days")) diff --git a/tests/test_main.py b/tests/test_main.py index 7535bf92..a030acf9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,9 +1,9 @@ import pytest -from app.main import OnlineCourse +from app.main import OnlineClass -class OnlineClass(OnlineCourse): +class OnlineClass(OnlineClass): pass @@ -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 " @@ -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}" ) @@ -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 "