Skip to content
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
25 changes: 25 additions & 0 deletions *shapes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Rectangle:
length = 0
width = 0

def __init__(self):
pass

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}')

Binary file added .DS_Store
Binary file not shown.
108 changes: 108 additions & 0 deletions gradebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from enum import Enum
from uuid import uuid4


class AliveStatus(Enum):
DECEASED = 0
ALIVE = 1


class Person:
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, last_name):
self.last_name = last_name
return last_name

def update_dob(self, dob):
self.dob = dob
return dob

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__(first_name, last_name, dob, alive)


class Student(Person):
student_id = uuid4()

def __init__(self, first_name, last_name, dob, alive):
super().__init__(first_name, last_name, dob, alive)


class ZipCodeStudent(Student):

def __init__(self, first_name, last_name, dob, alive):
super().__init__(first_name, last_name, dob, alive)


class College(Student):
def __init__(self, first_name, last_name, dob, alive):
super().__init__(first_name, last_name, dob, alive)


class Classroom:
students = []
instructors = []

def __init__(self):
pass

def add_instructor(self, instructor):
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},\
{instructor.instructor_id}')
return self.instructors

def add_student(self, student):
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},\
{student.student_id}')
return self.students

def print_instructors(self):
print(f'{self.instructors}')

def print_students(self):
print(f'{self.students}')


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())

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())
98 changes: 98 additions & 0 deletions gradebook2.py
Original file line number Diff line number Diff line change
@@ -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())
154 changes: 154 additions & 0 deletions test_gradebook.py
Original file line number Diff line number Diff line change
@@ -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)