def test_get_num_courses_in_program(self): """ 060A - Valid Get Number of Courses in Program """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A01000056") test_course_2 = Course("COMP1409", "123444", "CSD") test_course_2.add_student("A01000056") test_course_3 = Course("COMP1510", "123555", "CSD") test_course_3.add_student("A01000045") test_course_4 = Course("COMP2530", "123667", "CSD") test_course_4.add_student("A01000034") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) test_school.add_course(test_course_3) test_school.add_course(test_course_4) self.assertEqual(test_school.get_num_courses_in_program("CIT"), 1, "Must be only 1 CIT course") self.assertEqual(test_school.get_num_courses_in_program("CSD"), 3, "Must be 3 CSD courses") self.assertEqual(test_school.get_num_courses_in_program("SSD"), 0, "Must be no SSD courses")
def test_profit_02_sumOfPay(self): Nackadmein = School("Nackademin") staff1 = Staff("Mark", "Tomteboda 1", "Nackademin", 50) staff2 = Staff("Pike", "Tomteboda 3", "Nackademin", 50) Nackadmein.addStaff(staff1) Nackadmein.addStaff(staff2) self.assertEqual(Nackadmein.sumOfPay(), 100)
def test_profit_04_notProfit(self): Nackadmein = School("Nackademin") iot = Program("IoT") java = Program("Java") Nackadmein.addProgram(iot) Nackadmein.addProgram(java) studentx = Student("john", "gatan 12", "iot", 17, 50) studenty = Student("peter", "gatan 2", "iot", 17, 50) studentz = Student("peter", "gatan 2", "iot", 17, 40) iot.addStudent(studentx) iot.addStudent(studenty) java.addStudent(studentz) staff1 = Staff("Mark", "Tomteboda 1", "Nackademin", 50) staff2 = Staff("Pike", "Tomteboda 3", "Nackademin", 50) staff3 = Staff("Moa", "Tomteboda 1", "Nackademin", 50) Nackadmein.addStaff(staff1) Nackadmein.addStaff(staff2) Nackadmein.addStaff(staff3) self.assertEqual( Nackadmein.getProfit(Nackadmein.sumOfPay(), Nackadmein.totalFee()), False)
def test_add_course_undefined(self): """ 020B - Invalid Add Course Parameters """ test_school = School("Computing and Academic Studies") invalid_course = None self.assertRaisesRegex(ValueError, "Course must be defined.", test_school.add_course, invalid_course)
def test_get_num_students_in_program(self): """ 060A - Valid Get Number of Student in Program """ test_student_1 = Student("Bill", "Smith", "A0100000000", "CIT") test_student_1.add_course("ACIT2515") test_student_2 = Student("Ken", "Rodgers", "A0100000001", "CSD") test_student_2.add_course("COMP1510") test_student_3 = Student("Sally", "Jones", "A0100000002", "CSD") test_student_3.add_course("COMP1510") test_student_4 = Student("Julie", "Wong", "A0100000003", "CSD") test_student_4.add_course("COMP1510") test_school = School("Computing and Academic Studies") test_school.add_student(test_student_1) test_school.add_student(test_student_2) test_school.add_student(test_student_3) test_school.add_student(test_student_4) self.assertEqual(test_school.get_num_students_in_program("CIT"), 1, "Must be only 1 CIT student") self.assertEqual(test_school.get_num_students_in_program("CSD"), 3, "Must be 3 CSD students") self.assertEqual(test_school.get_num_students_in_program("SSD"), 0, "Must be no SSD students")
def order_question(self): #반복↓ while True: #show menu # self.menu() print("1.학교에서\ 2.회사에서\ 3.공공장소에서\ 4.일상생활에서 ") User_S = input("알고싶은 문장의 번호를 선택하세요") if User_S == "": #사용자가 엔터를 치면 끝난다. break elif User_S == '1': #1을 누르면 school.py를 불러와서 실행 s = School() s.run(User_S) elif User_S == '2': #2을 누르면 school.py를 불러와서 실행 o = Office() o.run(User_S) elif User_S == '3': #3을 누르면 school.py를 불러와서 실행 p = Public() p.run(User_S) elif User_S == '4': #4을 누르면 school.py를 불러와서 실행 l = Life() l.run(User_S)
def test_add_student_undefined(self): """ 020B - Invalid Add Student Parameters """ test_school = School("Computing and Academic Studies") invalid_student = None self.assertRaisesRegex(ValueError, "Student must be defined.", test_school.add_student, invalid_student)
def make_school(lb_student, ub_student, lb_classes, ub_classes): school = School(make_random_school_name()) for _ in range(random.randint(lb_classes, ub_classes)): class_list = Class_List(make_random_name(), []) for __ in range(random.randint(lb_student, ub_student)): class_list.add_student(make_random_student()) school.school_classes.append(class_list) return school
def test_profit_01_sumOfFee(self): Nackadmein = School("Nackademin") studentx = Student("john", "gatan 12", "iot", 17, 5000) studenty = Student("peter", "gatan 2", "iot", 17, 5000) Iot = Program("IoT") Iot.addStudent(studentx) Iot.addStudent(studenty) self.assertEqual(Iot.sumOfFee(), 10000)
def dashboard_add_school(): if 'school_name' in request.form: school_name = request.form['school_name'] if not school_name == "": page = School(dsn=app.config['dsn']) return page.insert_school(school_name) else: return "bos" else: return render_template('dashboard_add_school.html')
def signup(): name = request.form['name'] username = request.form['username'].strip() password = request.form['password'].strip() school = School(None, name, username, password) if insert_school(school): session['logged_in'] = True session['username'] = username session['name'] = name return redirect('/home')
def test_course_exists_invalid_course_id(self): """ 030B - Invalid Course ID Exists Parameters """ test_school = School("Computing and Academic Studies") course_id_undef = None self.assertRaisesRegex(ValueError, "Course ID cannot be undefined.", test_school.course_exists, course_id_undef) course_id_empty = "" self.assertRaisesRegex(ValueError, "Course ID cannot be empty.", test_school.course_exists, course_id_empty)
def test_remove_course_invalid_course_id(self): """ 040B - Invalid Remove Course Parameters """ test_school = School("Computing and Academic Studies") course_id_undef = None self.assertRaisesRegex(ValueError, "Course ID cannot be undefined.", test_school.remove_course, course_id_undef) course_id_empty = "" self.assertRaisesRegex(ValueError, "Course ID cannot be empty.", test_school.remove_course, course_id_empty)
def test_get_num_courses_in_program_invalid_program_name(self): """ 060B - Invalid Get Num Course in Program Parameters """ test_school = School("Computing and Academic Studies") program_name_undef = None self.assertRaisesRegex(ValueError, "Program Name cannot be undefined.", test_school.get_num_courses_in_program, program_name_undef) program_name_empty = "" self.assertRaisesRegex(ValueError, "Program Name cannot be empty.", test_school.get_num_courses_in_program, program_name_empty)
def test_get_programs(self): """adds students and checks what programs are returned""" test_school = School("Computing and Academic Studies") test_student_1 = Student("Bill", "Smith", "A0100000000", "CIT") test_student_2 = Student("Ken", "Rodgers", "A0100000001", "CSD") test_student_3 = Student("Sally", "Jones", "A0100000002", "CSD") test_school.add_student(test_student_1) test_school.add_student(test_student_2) test_school.add_student(test_student_3) self.assertEqual(test_school.get_programs(), ["CIT", "CSD"])
def add_school(self): school_name = input("输入学校名:") school_addr = input("输入学校地址:") new_school = School(school_name, school_addr) school_list = get_school_list() for school in school_list: if school.name == new_school.name: print("新增学校失败,学校已存在") return school_list.append(new_school) save()
def test_get_all_students(self): """creates 3 students and adds them to the school and sees how many are returned""" test_school = School("Computing and Academic Studies") test_student_1 = Student("Bill", "Smith", "A0100000000", "CIT") test_student_2 = Student("Ken", "Rodgers", "A0100000001", "CSD") test_student_3 = Student("Sally", "Jones", "A0100000002", "CSD") test_school.add_student(test_student_1) test_school.add_student(test_student_2) test_school.add_student(test_student_3) self.assertEqual(len(test_school.get_all_students()), 3)
def __read_instance__(self, path_kinderen, path_schools): with open(path_schools, "r") as file: schools_content = json.load(file) with open(path_kinderen, 'r') as file: kinderen_content = json.load(file) self.school_ids_uniek = list(schools_content.keys()) self.student_ids = list(kinderen_content.keys()) # initialize schools for school_id, school_info in schools_content.items(): preferences = school_info.get("applicaties") preferences = [(kind_id, preferences.get(kind_id).get('toeval')) for kind_id in preferences.keys()] preferences.sort(key=lambda x: x[1]) preferences = [i[0] for i in preferences ] # drop toeval, enkel rangorde in lijst telt nu school = School(unique_id=school_info.get("school_id_uniek"), school_id=school_info.get("school_id"), ind_capacity=school_info.get('INDCapaciteit'), n_ind_capacity=school_info.get('nINDCapaciteit'), preferences=preferences) self.schools.update({school_id: school}) # initialize alle kinderen for kind_id, kind_info in kinderen_content.items(): preferences = kind_info.get('applicaties') preferences = [(school_id, preferences.get(school_id).get('voorkeur')) for school_id in preferences.keys()] preferences.sort(key=lambda x: x[1]) preferences = [i[0] for i in preferences] applicaties = [ Application(periode=item.get("periode"), student_id=kind_id, school_id=key, voorkeur_student=item.get("voorkeur"), toeval=item.get('toeval')) for key, item in kind_info.get('applicaties').items() ] kind = Student(id=kind_id, school_preferences=preferences, indicator_status=kind_info.get("indicator_status"), applicaties=applicaties) self.kinderen.update({kind_id: kind})
def test_student_exists_invalid_student_id(self): """ 030B - Invalid Student Exists Parameters """ test_school = School("Computing and Academic Studies") student_id_undef = None self.assertRaisesRegex(ValueError, "Student Number cannot be undefined.", test_school.student_exists, student_id_undef) student_id_empty = "" self.assertRaisesRegex(ValueError, "Student Number cannot be empty.", test_school.student_exists, student_id_empty)
def select_school(username): conn = sqlite3.connect('school.db') c = conn.cursor() c.execute("SELECT * FROM school WHERE user_name = '%s'" % username) row = c.fetchone() school = School(id=row[0], name=row[1], username=row[2], password=row[3], filepath=row[4], predict=row[5]) conn.close() return school
def init_example(self): # example from http://www.eecs.harvard.edu/cs286r/courses/fall09/papers/stable-improvement-cycles.pdf x = School('X') y = School('Y') z = School('Z') s1 = Student('1') s2 = Student('2') s3 = Student('3') self.schools = [x, y, z] self.students = [s1, s2, s3] x.init_preference(self.students, {0: [s1], 1: [s2, s3]}) y.init_preference(self.students, {0: [s2], 1: [s1, s3]}) z.init_preference(self.students, {0: [s3], 1: [s1, s2]}) s1.init_preference(self.schools, [y, x, z]) s2.init_preference(self.schools, [z, y, x]) s3.init_preference(self.schools, [y, z, x]) self.calculate_permutations() return {s1: x, s2: z, s3: y}
def init_example(self, schools_list): # example from http://www.eecs.harvard.edu/cs286r/courses/fall09/papers/stable-improvement-cycles.pdf x = School('X') y = School('Y') z = School('Z') s1 = Student('1') s2 = Student('2') s3 = Student('3') self.schools = [x, y, z] self.students = [s1, s2, s3] x.init_preference(self.students, { 0: [s1], 1: [s2, s3] }) y.init_preference(self.students, { 0: [s2], 1: [s1, s3] }) z.init_preference(self.students, { 0: [s3], 1: [s1, s2] }) for i in range(len(self.students)): std = self.students[i] schools = [self.schools[pos] for pos in schools_list[i]] # print(std, schools) std.init_preference(self.schools, schools) # s1.init_preference(self.schools, [y, x, z]) # s2.init_preference(self.schools, [z, y, x]) # s3.init_preference(self.schools, [y, z, x]) self.calculate_permutations()
def get_schools(): """ Read csv file and create School objects from it """ school_objects_list = [] elementary_schools = csv.DictReader(open( 'data_transformation/2017-18 Elementary School Description- Responses.csv', 'rU'), dialect=csv.excel_tab, delimiter=",") middle_schools = csv.DictReader(open( 'data_transformation/2017-18 Middle School Description- Responses.csv', 'rU'), dialect=csv.excel_tab, delimiter=",") high_schools = csv.DictReader(open( 'data_transformation/2017-18 High School Description- Responses.csv', 'rU'), dialect=csv.excel_tab, delimiter=",") for elementary_school in elementary_schools: new_school_object = School(elementary_school) school_objects_list.append(new_school_object) for middle_school in middle_schools: new_school_object = School(middle_school) school_objects_list.append(new_school_object) for high_school in high_schools: new_school_object = School(high_school) school_objects_list.append(new_school_object) # edit the multilingual pathways and before/after school programs school_objects_list = fix_school_programs(school_objects_list) school_objects_list = fix_multilingual_pathways(school_objects_list) return school_objects_list
def test_add_course_already_exists(self): """ 020C - Course Already Exists """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_school = School("Computing and Academic Studies") self.assertEqual(test_school.get_num_courses(), 0, "School must have no courses") test_school.add_course(test_course_1) self.assertEqual(test_school.get_num_courses(), 1, "School must have 1 course") # Add the same course again test_school.add_course(test_course_1) self.assertEqual(test_school.get_num_courses(), 1, "School must still have only 1 course")
def test_get_non_existent_course(self): """ 050C - Invalid Get Course Non-Existent """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertIsNone(test_school.get_course("ACIT1234"), "No course should exists for ACIT1234")
def test_course_exists_not_existent_course(self): """ 030C - Valid Course Does Not Exist """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertFalse(test_school.course_exists("ACIT1234"), "Course ACIT1234 must NOT exist") self.assertFalse(test_school.course_exists("COMP4321"), "Course4321 must NOT exist")
def test_course_exists(self): """ 030A - Valid Course Exists """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") test_school.add_course(test_course_1) test_school.add_course(test_course_2) self.assertTrue(test_school.course_exists("ACIT2515"), "Course ACIT2515 must exist") self.assertTrue(test_school.course_exists("COMP1510"), "Course COMP1510 must exist")
def test_get_non_existent_student(self): """ 050C - Invalid Get Student Non-Existent """ test_student_1 = Student("Bill", "Smith", "A0100000000", "CIT") test_student_1.add_course("ACIT2515") test_student_2 = Student("Ken", "Rodgers", "A0100000001", "CIT") test_student_2.add_course("ACIT2515") test_student_2.add_course("COMP1409") test_school = School("Computing and Academic Studies") test_school.add_student(test_student_1) test_school.add_student(test_student_2) self.assertIsNone(test_school.get_student("AXXXYYYZZZ"), "No student should exists for AXXXYYYZZZ")
def test_add_course(self): """ 020A - Valid Add Course """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("Computing and Academic Studies") self.assertEqual(test_school.get_num_courses(), 0, "School must have no courses") test_school.add_course(test_course_1) self.assertEqual(test_school.get_num_courses(), 1, "School must have 1 course") test_school.add_course(test_course_2) self.assertEqual(test_school.get_num_courses(), 2, "School must have 2 courses")
def test_get_school_details(self): """ 050A - Valid Get Course """ test_course_1 = Course("ACIT2515", "123456", "CIT") test_course_1.add_student("A010000056") test_course_2 = Course("COMP1510", "456321", "CST") test_course_2.add_student("A010000056") test_course_2.add_student("A010450012") test_school = School("BCIT") test_school.add_course(test_course_1) test_school.add_course(test_course_2) retreived_school = test_school.get_school_details() self.assertEqual(retreived_school["school_name"], "BCIT", "School must be named BCIT") self.assertEqual(retreived_school["num_courses"], 2, "School must have two programs") self.assertEqual(sorted(retreived_school["programs"]), sorted(["CIT", "CST"]), "School must have CST as the program")