From ab017fbeefff48c3c072afb8966606e2801ae20c Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 21 Mar 2022 11:15:49 -0400 Subject: [PATCH 1/9] Set up Classes. --- *shapes.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 *shapes.py diff --git a/*shapes.py b/*shapes.py new file mode 100644 index 0000000..fa288e3 --- /dev/null +++ b/*shapes.py @@ -0,0 +1,23 @@ +class Rectangle: + length = 0 + width = 0 + + def __init__(self): + pass + +def area(): + + + + + +def perimeter(): + + + + + + +class Square(Rectangle): + def __init__(self): + pass From 0e94eda6985f3094260ac042e0e43b531e1149a8 Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 21 Mar 2022 11:55:20 -0400 Subject: [PATCH 2/9] Finished exercise1, created base and subclass. --- *shapes.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/*shapes.py b/*shapes.py index fa288e3..e4258a7 100644 --- a/*shapes.py +++ b/*shapes.py @@ -5,19 +5,21 @@ class Rectangle: def __init__(self): pass -def area(): - - - - - -def perimeter(): - - - + def area_of(self, length, width): + area = length * width + return area + def perimeter_of(self, length, width): + perimeter = 2 * (length + width) + return perimeter class Square(Rectangle): def __init__(self): pass + + +square1 = Square() +square_area = square1.area_of(2, 3) +print(f'The area of square1 is: {square_area}') + From fa1f70f05470a863f8be58b3e9305c3875c85845 Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 21 Mar 2022 12:36:14 -0400 Subject: [PATCH 3/9] Added Person Class. --- gradebook.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 gradebook.py diff --git a/gradebook.py b/gradebook.py new file mode 100644 index 0000000..e3f4caa --- /dev/null +++ b/gradebook.py @@ -0,0 +1,34 @@ +from enum import Enum + + +class AliveStatus(Enum): + DECEASED = 0 + ALIVE = 1 + + +class Person: + first_name = '' + last_name = '' + dob = '' + alive = AliveStatus + + def __init__(self): + pass + + def update_first_name(self, new_first_name): + self.first_name = new_first_name + return new_first_name + + def update_last_name(self, new_last_name): + self.last_name = new_last_name + return new_last_name + + def update_dob(self, new_dob): + self.dob = new_dob + return new_dob + + def update_status(self, new_status): + self.alive = new_status + return new_status + + From 7a074574d8c5f1e3c56ce85bbc94044f968c6dac Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 21 Mar 2022 13:02:03 -0400 Subject: [PATCH 4/9] Added additional classes. --- gradebook.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/gradebook.py b/gradebook.py index e3f4caa..d9300b9 100644 --- a/gradebook.py +++ b/gradebook.py @@ -1,4 +1,5 @@ from enum import Enum +import uuid class AliveStatus(Enum): @@ -6,7 +7,7 @@ class AliveStatus(Enum): ALIVE = 1 -class Person: +class Person(): first_name = '' last_name = '' dob = '' @@ -32,3 +33,39 @@ def update_status(self, new_status): return new_status +class Instructor(Person): + instructor_id = uuid.uuid4() + + def __init__(self): + pass + + +class Student(Person): + student_id = uuid.uuid4() + + def __init__(self): + pass + + +class ZipCodeStudent(Student): + + def __init__(self): + pass + + +class College(Student): + + def __init__(self): + pass + + +class Classroom: + students = [] + instructors = [] + + def __init__(self): + pass + + +student1 = Student() +print(student1.student_id) From f227882d5685dfacd119511017e39e4d8c453924 Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 21 Mar 2022 20:10:04 -0400 Subject: [PATCH 5/9] Made some changes to Instructor class and methods. --- gradebook.py | 59 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/gradebook.py b/gradebook.py index d9300b9..5f196a7 100644 --- a/gradebook.py +++ b/gradebook.py @@ -1,5 +1,5 @@ from enum import Enum -import uuid +from uuid import uuid4 class AliveStatus(Enum): @@ -7,7 +7,7 @@ class AliveStatus(Enum): ALIVE = 1 -class Person(): +class Person: first_name = '' last_name = '' dob = '' @@ -16,9 +16,9 @@ class Person(): def __init__(self): pass - def update_first_name(self, new_first_name): - self.first_name = new_first_name - return new_first_name + def update_first_name(self, first_name): + self.first_name = first_name + return first_name def update_last_name(self, new_last_name): self.last_name = new_last_name @@ -34,29 +34,28 @@ def update_status(self, new_status): class Instructor(Person): - instructor_id = uuid.uuid4() + instructor_id = uuid4() - def __init__(self): - pass + def __init__(self, first_name, last_name, dob, alive): + super().__init__() class Student(Person): - student_id = uuid.uuid4() + student_id = uuid4 - def __init__(self): - pass + def __init__(self, first_name, last_name, dob, alive): + super().__init__() class ZipCodeStudent(Student): - def __init__(self): - pass + def __init__(self, first_name, last_name, dob, alive): + super().__init__() class College(Student): - - def __init__(self): - pass + def __init__(self, first_name, last_name, dob, alive): + super().__init__() class Classroom: @@ -66,6 +65,30 @@ class Classroom: def __init__(self): pass + def add_instructor(self, instructor): + self.instructors.append(instructor.instructor_id) + return self.instructors + + def remove_instructor(self): + return self.instructors + + def add_student(self): + return self.students + + def remove_student(self): + return self.students + + def print_instructors(self): + print(f'Instructor: {self.instructors}') + + def print_students(self): + print(self.students) + + +instructor1 = Instructor('Allen', 'Chung', '9/27/91', 1) + +print(instructor1.update_first_name('Allen')) -student1 = Student() -print(student1.student_id) +classroom1 = Classroom() +classroom1.add_instructor(instructor1) +print(classroom1.print_instructors()) From b80dc767e20d14a238bd89078d23d3f8961e4aff Mon Sep 17 00:00:00 2001 From: Allen C Date: Tue, 22 Mar 2022 12:24:59 -0400 Subject: [PATCH 6/9] Added add and remove instructor methods. --- gradebook.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/gradebook.py b/gradebook.py index 5f196a7..2577d4c 100644 --- a/gradebook.py +++ b/gradebook.py @@ -66,29 +66,39 @@ def __init__(self): pass def add_instructor(self, instructor): - self.instructors.append(instructor.instructor_id) + self.instructors.append(f'Instructor_{instructor.first_name},{instructor.last_name}, {instructor.dob},\ + {instructor.instructor_id}') return self.instructors - def remove_instructor(self): + def remove_instructor(self, instructor): + self.instructors.remove(f'Instructor_{instructor.first_name},{instructor.last_name}, {instructor.dob},\ + {instructor.instructor_id}') return self.instructors - def add_student(self): + def add_student(self, student): + self.students.append(student.student_id) return self.students def remove_student(self): return self.students def print_instructors(self): - print(f'Instructor: {self.instructors}') + print(f'{self.instructors}') def print_students(self): print(self.students) -instructor1 = Instructor('Allen', 'Chung', '9/27/91', 1) +instructor1 = Instructor(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) -print(instructor1.update_first_name('Allen')) +instructor1.update_first_name('Allen') +instructor1.update_last_name('Chung') +instructor1.update_dob('9/27/01') +instructor1.update_status(1) classroom1 = Classroom() classroom1.add_instructor(instructor1) print(classroom1.print_instructors()) +classroom1.remove_instructor(instructor1) +print(classroom1.print_instructors()) + From e349f5482b87856c5405c8592f0252068fcf8abf Mon Sep 17 00:00:00 2001 From: Allen C Date: Tue, 22 Mar 2022 12:45:41 -0400 Subject: [PATCH 7/9] Added student methods. --- gradebook.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/gradebook.py b/gradebook.py index 2577d4c..9e5d642 100644 --- a/gradebook.py +++ b/gradebook.py @@ -41,7 +41,7 @@ def __init__(self, first_name, last_name, dob, alive): class Student(Person): - student_id = uuid4 + student_id = uuid4() def __init__(self, first_name, last_name, dob, alive): super().__init__() @@ -76,17 +76,20 @@ def remove_instructor(self, instructor): return self.instructors def add_student(self, student): - self.students.append(student.student_id) + self.students.append(f'Student_{student.first_name},{student.last_name}, {student.dob},\ + {student.student_id}') return self.students - def remove_student(self): + def remove_student(self, student): + self.students.remove(f'Student_{student.first_name},{student.last_name}, {student.dob},\ +{student.student_id}') return self.students def print_instructors(self): print(f'{self.instructors}') def print_students(self): - print(self.students) + print(f'{self.students}') instructor1 = Instructor(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) @@ -102,3 +105,16 @@ def print_students(self): classroom1.remove_instructor(instructor1) print(classroom1.print_instructors()) +student1 = Student(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) + +student1.update_first_name('Allen') +student1.update_last_name('Chung') +student1.update_dob('9/27/01') +student1.update_status(1) + +classroom2 = Classroom() +classroom2.add_student(student1) +print(classroom2.print_students()) +#classroom2.remove_student(student1) +#print(classroom2.print_students()) + From 16fb5df9a2ec5e70f2f164b21a642678d1b4f6f7 Mon Sep 17 00:00:00 2001 From: Allen C Date: Tue, 22 Mar 2022 14:50:28 -0400 Subject: [PATCH 8/9] Fixed the super class and sub class parameters. --- gradebook.py | 50 +++++++++++++++++++------------------------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/gradebook.py b/gradebook.py index 9e5d642..ac09fdb 100644 --- a/gradebook.py +++ b/gradebook.py @@ -8,54 +8,52 @@ class AliveStatus(Enum): class Person: - first_name = '' - last_name = '' - dob = '' - alive = AliveStatus - - def __init__(self): - pass + def __init__(self, first_name, last_name, dob, AliveStatus): + self.first_name = first_name + self.last_name = last_name + self.dob = dob + self.alive = AliveStatus def update_first_name(self, first_name): self.first_name = first_name return first_name - def update_last_name(self, new_last_name): - self.last_name = new_last_name - return new_last_name + def update_last_name(self, last_name): + self.last_name = last_name + return last_name - def update_dob(self, new_dob): - self.dob = new_dob - return new_dob + def update_dob(self, dob): + self.dob = dob + return dob - def update_status(self, new_status): - self.alive = new_status - return new_status + def update_status(self, status): + self.alive = status + return status class Instructor(Person): instructor_id = uuid4() def __init__(self, first_name, last_name, dob, alive): - super().__init__() + super().__init__(first_name, last_name, dob, alive) class Student(Person): student_id = uuid4() def __init__(self, first_name, last_name, dob, alive): - super().__init__() + super().__init__(first_name, last_name, dob, alive) class ZipCodeStudent(Student): def __init__(self, first_name, last_name, dob, alive): - super().__init__() + super().__init__(first_name, last_name, dob, alive) class College(Student): def __init__(self, first_name, last_name, dob, alive): - super().__init__() + super().__init__(first_name, last_name, dob, alive) class Classroom: @@ -94,27 +92,17 @@ def print_students(self): instructor1 = Instructor(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) -instructor1.update_first_name('Allen') -instructor1.update_last_name('Chung') -instructor1.update_dob('9/27/01') -instructor1.update_status(1) - classroom1 = Classroom() classroom1.add_instructor(instructor1) print(classroom1.print_instructors()) classroom1.remove_instructor(instructor1) print(classroom1.print_instructors()) -student1 = Student(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) +student1 = Student(first_name='Kira', last_name='Sy', dob='1/1/2000', alive=1) -student1.update_first_name('Allen') -student1.update_last_name('Chung') -student1.update_dob('9/27/01') -student1.update_status(1) classroom2 = Classroom() classroom2.add_student(student1) print(classroom2.print_students()) #classroom2.remove_student(student1) #print(classroom2.print_students()) - From 54170b65cee9030fac259a49f78fa5ef017a184c Mon Sep 17 00:00:00 2001 From: Allen C Date: Mon, 4 Apr 2022 18:02:39 -0400 Subject: [PATCH 9/9] Added Final updates. Added tests. --- .DS_Store | Bin 0 -> 6148 bytes gradebook.py | 14 ++--- gradebook2.py | 98 +++++++++++++++++++++++++++++ test_gradebook.py | 154 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 259 insertions(+), 7 deletions(-) create mode 100644 .DS_Store create mode 100644 gradebook2.py create mode 100644 test_gradebook.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b39e028ae319e64522423956718bdc87baed674c GIT binary patch literal 6148 zcmeHKy-LJD5T5ZO1Z=Lna!WxF?hWD*pWt3VW8^%zkSny`!d9^HF?bgE$fAshm`7bZ7A#JdJvOWP@~rQ+Bb)qI zlRSGthqR(KUFOe!cRloVeO))3zJaZ5ZrYdq=ZB-*-+t@gUJSUIM5NL#>aMA!b2`l{ z&z^Gcu=f4I{$L(PwAC8E^(Z7?ATJ zUEMQIoU3v-035JznRD=h@nhMlZwibgm9rj>xm0?uWbYg2h*ebs_ zFPy4l|B%9oD@C830cRj*V4};Z-2cb;WJa6(JjGYefHUyN7~rB_)(gCp-K}3q$=tyw@ literal 0 HcmV?d00001 diff --git a/gradebook.py b/gradebook.py index ac09fdb..259aca5 100644 --- a/gradebook.py +++ b/gradebook.py @@ -64,22 +64,22 @@ def __init__(self): pass def add_instructor(self, instructor): - self.instructors.append(f'Instructor_{instructor.first_name},{instructor.last_name}, {instructor.dob},\ + self.instructors.append(f'Instructor_{instructor.first_name} {instructor.last_name}, {instructor.dob},\ {instructor.instructor_id}') return self.instructors def remove_instructor(self, instructor): - self.instructors.remove(f'Instructor_{instructor.first_name},{instructor.last_name}, {instructor.dob},\ + self.instructors.remove(f'Instructor_{instructor.first_name} {instructor.last_name}, {instructor.dob},\ {instructor.instructor_id}') return self.instructors def add_student(self, student): - self.students.append(f'Student_{student.first_name},{student.last_name}, {student.dob},\ + self.students.append(f'Student_{student.first_name} {student.last_name}, {student.dob},\ {student.student_id}') return self.students def remove_student(self, student): - self.students.remove(f'Student_{student.first_name},{student.last_name}, {student.dob},\ + self.students.remove(f'Student_{student.first_name} {student.last_name}, {student.dob},\ {student.student_id}') return self.students @@ -90,7 +90,7 @@ def print_students(self): print(f'{self.students}') -instructor1 = Instructor(first_name='Allen', last_name='Chung', dob='9/27/91', alive=1) +instructor1 = Instructor('Allen', 'Chung', '9/27/91', 1) classroom1 = Classroom() classroom1.add_instructor(instructor1) @@ -98,11 +98,11 @@ def print_students(self): classroom1.remove_instructor(instructor1) print(classroom1.print_instructors()) -student1 = Student(first_name='Kira', last_name='Sy', dob='1/1/2000', alive=1) +student1 = Student('Kira', 'Sy', '1/1/2000', 1) classroom2 = Classroom() classroom2.add_student(student1) print(classroom2.print_students()) #classroom2.remove_student(student1) -#print(classroom2.print_students()) +#print(classroom2.print_students()) \ No newline at end of file diff --git a/gradebook2.py b/gradebook2.py new file mode 100644 index 0000000..6aeb776 --- /dev/null +++ b/gradebook2.py @@ -0,0 +1,98 @@ +from typing import List, Dict +from enum import Enum +import uuid + + +class AliveStatus(Enum): + Deceased = 0 + Alive = 1 + + +class Person: + def __init__(self, first_name: str, last_name: str, dob: str): + self.first_name = first_name + self.last_name = last_name + self.dob = dob + self.alive = AliveStatus.Alive + + def __str__(self): + return f"{self.first_name} {self.last_name}" + + def update_first_name(self, first_name: str): + self.first_name = first_name + + def update_last_name(self, last_name: str): + self.last_name = last_name + + def update_dob(self, dob: str): + self.dob = dob + + def update_status(self, alive: AliveStatus): + self.alive = alive + + +class Instructor(Person): + def __init__(self, first_name: str, last_name: str, dob: str): + Person.__init__(self, first_name, last_name, dob) + self.instructor_id = f"Instructor_{uuid.uuid4()}" + + +class Student(Person): + def __init__(self, first_name: str, last_name: str, dob: str): + Person.__init__(self, first_name, last_name, dob) + self.student_id = f"Student_{uuid.uuid4()}" + + +class PreKStudent(Student): + def __init__(self, first_name: str, last_name: str, dob: str): + Student.__init__(self, first_name, last_name, dob) + + +class ZipCodeStudent(Student): + def __init__(self, first_name: str, last_name: str, dob: str): + Student.__init__(self, first_name, last_name, dob) + + +class GradeBook: + pass + + +class Classroom: + + def __init__(self): + self.students: Dict[str, Student] = {} + self.instructors: Dict[str, Instructor] = {} + + def add_instructor(self, instructor: Instructor): + self.instructors[instructor.instructor_id] = instructor + + def remove_instructor(self, instructor: Instructor): + if instructor.instructor_id in self.instructors: + del self.instructors[instructor.instructor_id] + + def add_student(self, student: Student): + self.students[student.student_id] = student + + def remove_student(self, student): + if student.student_id in self.students: + del self.students[student.student_id] + + def print_instructors(self): + for key, value in self.instructors.items(): + print(f"{key}: {value}") + + def print_students(self): + for key, value in self.students.items(): + print(f"{key}: {value}") + + +if __name__ == "__main__": + pass + +instructor1 = Instructor('Allen''Chung', '9/27/91', 1) + +classroom1 = Classroom() +classroom1.add_instructor(instructor1) +print(classroom1.print_instructors()) +classroom1.remove_instructor(instructor1) +print(classroom1.print_instructors()) \ No newline at end of file diff --git a/test_gradebook.py b/test_gradebook.py new file mode 100644 index 0000000..79de4b6 --- /dev/null +++ b/test_gradebook.py @@ -0,0 +1,154 @@ +import unittest +import unittest.mock +from io import StringIO + +import gradebook + + +class PersonTest(unittest.TestCase): + + def setUp(self) -> None: + bob = gradebook.Person("Bob", "Smith", "01201970", 0) + jane = gradebook.Person("Jane", "Doe", "02201984", 1) + + self._people = [ + bob, + jane + ] + + def test_update_first_name(self): + bob = self._people[0] + bob.update_first_name("John") + self.assertEqual("John", bob.first_name) + + def test_update_last_name(self): + bob = self._people[0] + bob.update_last_name("Doe") + self.assertEqual("Doe", bob.last_name) + + def test_update_dob(self): + bob = self._people[0] + bob.update_dob("01011970") + self.assertEqual("01011970", bob.dob) + + def test_update_status(self): + bob = self._people[0] + bob.update_status(gradebook.AliveStatus.Deceased) + self.assertEqual(gradebook.AliveStatus.Deceased, bob.alive) + + +class StudentTest(unittest.TestCase): + + def setUp(self) -> None: + bob = gradebook.Student("Bob", "Smith", "01201970") + jane = gradebook.Student("Jane", "Doe", "02201984") + + self._students = [ + bob, + jane + ] + + def test_instantiation(self): + bob = self._students[0] + self.assertTrue(bob.student_id is not None) + self.assertTrue(isinstance(bob.student_id, str)) + self.assertEqual(bob.student_id[:8], "Student_") + + +class InstructorTest(unittest.TestCase): + + def setUp(self) -> None: + self._bob_marley = gradebook.Instructor("Bob", "Marley", "06021945") + + def test_instantiation(self): + marley = self._bob_marley + self.assertTrue(marley.instructor_id is not None) + self.assertTrue(isinstance(marley.instructor_id, str)) + self.assertEqual(marley.instructor_id[:11], "Instructor_") + + +class PreKStudentTest(unittest.TestCase): + + def test_instantiation(self): + bob = gradebook.PreKStudent("Bob", "Smith", "01201970") + self.assertTrue(isinstance(bob, gradebook.Student)) + + def test_is_subclass(self): + self.assertTrue(issubclass(gradebook.PreKStudent, gradebook.Student)) + + +class ZipCodeStudentTest(unittest.TestCase): + + def test_instantiation(self): + bob = gradebook.ZipCodeStudent("Bob", "Smith", "01201970") + self.assertTrue(isinstance(bob, gradebook.Student)) + + def test_is_subclass(self): + self.assertTrue(issubclass(gradebook.ZipCodeStudent, gradebook.Student)) + + +class ClassroomTest(unittest.TestCase): + + def setUp(self) -> None: + self._zc_cohort = gradebook.Classroom() + rich = gradebook.ZipCodeStudent("Richmond", "Avenal", "1973") + jen = gradebook.Instructor("Jen", "Barber", "1977") + + self._zc_cohort.students[rich.student_id] = rich + self._zc_cohort.instructors[jen.instructor_id] = jen + + def get_rich(self) -> gradebook.Student: + rich_key = next(iter(self._zc_cohort.students.keys())) + rich = self._zc_cohort.students.get(rich_key) + return rich + + def get_jen(self) -> gradebook.Instructor: + jen_key = next(iter(self._zc_cohort.instructors.keys())) + jen = self._zc_cohort.instructors.get(jen_key) + return jen + + def test_add_instructor(self): + yamamoto = gradebook.Instructor("Unknown", "Yamamoto", "1953") + self._zc_cohort.add_instructor(yamamoto) + + result = yamamoto.instructor_id in self._zc_cohort.instructors + self.assertTrue(result) + + def test_remove_instructor(self): + jen = self.get_jen() + + self._zc_cohort.remove_instructor(jen) + self.assertEqual(len(self._zc_cohort.instructors), 0) + + @unittest.mock.patch('sys.stdout', new_callable=StringIO) + def test_print_instructors(self, mock_stdout): + self._zc_cohort.print_instructors() + jen = self.get_jen() + + expected = f"{jen.instructor_id}: Jen Barber\n" + actual = mock_stdout.getvalue() + + self.assertEqual(expected, actual) + + def test_add_student(self): + moss = gradebook.ZipCodeStudent("Maurice", "Moss", "01011972") + self._zc_cohort.add_student(moss) + + result = moss.student_id in self._zc_cohort.students + self.assertTrue(result) + + def test_remove_student(self): + rich = self.get_rich() + + self._zc_cohort.remove_student(rich) + self.assertEqual(len(self._zc_cohort.students), 0) + + @unittest.mock.patch('sys.stdout', new_callable=StringIO) + def test_print_students(self, mock_stdout): + self._zc_cohort.print_students() + rich = self.get_rich() + + expected = f"{rich.student_id}: Richmond Avenal\n" + actual = mock_stdout.getvalue() + + self.assertEqual(expected, actual)