Skip to content

Commit

Permalink
Added composition
Browse files Browse the repository at this point in the history
  • Loading branch information
qtkhajadevops committed Apr 28, 2024
1 parent ed34e48 commit a682645
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
Empty file.
39 changes: 39 additions & 0 deletions Projects/oop_demo/learning/institute/structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""This module defines the basic structures necessary
"""


class Course:
"""This represents Course"""

def __init__(self, course_id: str, name: str) -> None:
self.__course_id = course_id
self.__name = name

@property
def name(self):
"""This property returns name"""
return self.__name

@property
def course_id(self):
"""Course Id propert"""
return self.__course_id


class Student:
"""
This class Represents the student
"""

def __init__(
self,
student_id: str,
name: str,
) -> None:
self.student_id = student_id
self.name = name
self.courses = []

def enroll_course(self, course: Course):
"""We are enrolling student to a course"""
self.courses.append(course)
Empty file.
33 changes: 33 additions & 0 deletions Projects/oop_demo/tests/institute/test_structures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
This test cases test the institute structures
"""
from learning.institute.structure import Course, Student

def test_student_course():
"""Testing the basic functionality
"""
python_course = Course(
"x123",
"Python"
)
devops_course = Course(
"x121",
"DevOps"
)
cloud_course = Course(
"x121",
"DevOps"
)
student = Student(
student_id = "s1001",
name = "Abhay"
)

assert len(student.courses) == 0
# now lets enroll student to python
student.enroll_course(python_course)
assert len(student.courses) == 1
student.enroll_course(devops_course)
assert len(student.courses) == 2
student.enroll_course(cloud_course)
assert len(student.courses) == 3

0 comments on commit a682645

Please sign in to comment.