Question
Please, someone, insert the unit test in the class scheduler in this python program ....... below the program..... import unittest class Student: def __init__(self, stu_name):
Please, someone, insert the unit test in the class scheduler in this python program \.......
below the program.....
import unittest
class Student:
def __init__(self, stu_name):
self.__name = stu_name
self.__days_Time = dict()
def getName(self):
return self.__name
def get_Days_Times(self):
return self.__days_Time
def set_The_Days_Times(self,list_days,list_times):
self.__days_Time[list_days] = list_times
class Class:
#constructor
def __init__(self):
self.__student = []
self.__studentID = []
#adds a student returns as id
def add_student(self,stu_name):
_id = len(self.__studentID)
s = Student(stu_name)
self.__studentID.append(_id+1)
self.__student.append(s)
return _id+1
def add_class(self,_id,days_of_week,start_time,end_time):
if _id in self.__studentID:
student = self.__student[self.__studentID.index(_id)]
dictionary = student.get_Days_Times()
keys = dictionary.keys()
toAdd = True
for i in keys:
k_list = list(i)
days = list(days_of_week)
for day in days:
if day in k_list and ((start_time>= dictionary[i][0] and start_time= dictionary[i][0] and end_time
toAdd = False
break
if not toAdd:
break
if toAdd:
student.set_The_Days_Times(days_of_week,[start_time,end_time])
else:
raise Exception("Class already exists!")
def total_class_time(self,_id):
student = self.__student[self.__studentID.index(_id)]
time = 0
dictionary = student.get_Days_Times()
for k,v in dictionary.items():
ite = 0
t = v[0]
while t
t += 1
ite += 1
#print(t,ite)
if t%100>59:
t = t + 40
time += len(k)*ite
return time/60
example ........................below
# Class_ =Class()
# print(Class_.add_student("Student 1"))
# print(Class_.add_student("Student 2"))
# print(Class_.add_student("Student 3"))
# print(Class_.add_student("Student 4"))
# Class_.add_class(2,"TR",1600,1800)
# Class_.add_class(2,"M",1630,1800)
# print(Class_.total_class_time(2))
# class Test(unittest.TestCase):
# def test_add_students(self):
# dict.clear(students)
# add_student("Jack")
# add_student("Jill")
# add_student("John")
# add_student("Kevin")
# student_id = add_student("Alex")
# self.assertEqual(student_id, 5, "Should be 5")
# def test_add_class_no_overlap(self):
# dict.clear(students)
# add_student("Jack")
# add_class("Math",1,"MTW",1600,1900)
# x = add_class("English",1,"R",1600,1900)
# self.assertEqual(x, None, "Should be None")
# def test_add_class_overlap(self):
# dict.clear(students)
# add_student("Jack")
# add_class("Math",1,"MTW",1600,1900)
# self.assertRaises(Exception, lambda: add_class("English",1,"W",1600,1700),"Should be Exception" )
# def test_total_class_time_no_classes(self):
# dict.clear(students)
# add_student("Jack")
# self.assertEqual(total_class_time(1), 0, "Should be 0")
# def test_total_class_time_multiple_classes(self):
# dict.clear(students)
# add_student("Jack")
# add_class("Math",1,"TWF",1200,1500)
# add_class("English",1,"TWF",1600,1700)
# add_class("CS",1,"MR",1600,1700)
# self.assertEqual(total_class_time(1), 14.0, "Should be 14.0")
unittest.main()
class unittest(unittest.TestCase):
pass
if __name__ == '__main__':
unittest.main()
Use the `unittest` module's assertEqual and assertRaises functions to test the following situations:
- Creating a student when 4 students already exist returns id of 5
- Adding a class on a day student has other classes that don't overlap is successful
- Adding a class that overlaps with another class throws an error
- Checking total class time when student has no classes returns 0
- Checking total class time when student has a bunch of classes scheduled returns correct number
12 main.py 1 import unittest 2 3 class Student: 4 def __init__(self, stu_name): 5 self.__name = stu_name 6 self._days_Time = dict() 7 8 def getName(self): 9 return self._name 10 11 def get_Days_Times(self): return self._days_Time 13 14 def set_The_Days_Times(self, list_days, list_times): 15 self._days_Time[list_days) - list_times 16 17 class Class: 18 #constructor 19 def __init__(self): 20 self.__student = [] 21 self._studentID = [] 22 #adds a student returns as id 23 24 def add_student(self, stu_name): 25 _id = len(self._studentID) 26 s - Student (stu_name) 27 self._student ID.append(_id+1) 28 self._student.append(s) 29 return _id+1 30 31 def add_class(self,_id, days_of_week, start_time, end_time): - 50 51 def total_class_time(self,_id): - 66 67 # Class_=Class() 68 # print (Class_add_student("Student 1")) 69 # print(Class_add_student("Student 2")) 70 # print(Class_add_student ("Student 3")) 71 # print(Class_add_student("Student 4")) 72 # Class_add_class (2,"TR", 1688, 1898) 73 # Class_add_class (2, "M", 1630,1800) 74 # print (Class_.total_class_time(2))Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started