def setUp(self): self.student = Student(1, "Vlad") self.course = Course(10, "Asc", "Vancea") self.grade = Grade(self.student, self.course, 10) self.invalid_grade = Grade(self.student, self.course, 30) self.invalid_grade2 = Grade(self.student, self.course, -30) self.validator_g = GradeValidator()
def testStat2(self): self._grCtr.giveAssigToGroup(3, "12") self._grCtr.giveAssigToGroup(3, "10") self._grCtr.add(Grade(3, 8, 8.0)) self._grCtr.add(Grade(5, 3, 5.5)) x = self._stat.getLateStuds() self.assertEqual(len(x), 8)
def testRemoveGr(self): self._grCtr.add(self.grade) self._grCtr.add(Grade(3, 2, 2.2)) self.assertEqual(len(self._grCtr.getAll()), 2) self._grCtr.remove(1, 1) self.assertEqual(len(self._grCtr.getAll()), 1) self.assertEqual(self._grCtr.getAll()[0], Grade(3, 2, 2.2)) self.assertRaises(ValueError, self._grCtr.remove, 1, 1)
def testSetGrade(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self.assertTrue(self._grCtr.setGrade(1, 2, 9.0)) self.assertEqual(self._grCtr.getAll()[0], Grade(2, 1, 9.0)) self.undo.undo() self.assertRaises(ControllerException, self._grCtr.setGrade, 1, 1, 2.3) self.assertRaises(ValueError, self._grCtr.setGrade, 3, 1, 2.3)
def testStat4(self): self._grCtr.giveAssigToGroup(3, "10") self._grCtr.add(Grade(1, 8, 6.0)) self._grCtr.add(Grade(3, 8, 8.0)) x = self._stat.getAssigByGrade() self.assertEqual(len(x), 2) self.assertEqual(x[0].grade, 8.0) self.assertEqual(x[1].grade, 6.0)
def testFindByID(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) x = self._grCtr.findByID(1, 1) self.assertEqual(x, Grade(1, 1, 2.0)) x = self._grCtr.findByID(3, 1) self.assertEqual(x, -1) x = self._grCtr.filterGradesBy(1, 1) self.assertEqual(x[0], Grade(1, 1, 2.0)) x = self._grCtr.filterGradesBy(3, 1) self.assertEqual(x, [])
class TestGrade(TestCase): def setUp(self): self.__grade = Grade(3, 7, 9) def test_get_assignment_id(self): self.assertEqual(self.__grade.get_assignment_id(), 3) def test_get_student_id(self): self.assertEqual(self.__grade.get_student_id(), 7) def test_get_grade(self): self.assertEqual(self.__grade.get_grade(), 9)
def testUngradeStud(self): self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.add(Grade(2, 3, 3.0)) self._grCtr.add(Grade(4, 2, 0.0)) self._grCtr.add(Grade(3, 2, 0.0)) x = self._grCtr.getStudUngrade(1) self.assertEqual(len(x), 1) x = self._grCtr.getStudUngrade(2) self.assertEqual(len(x), 2) x = self._grCtr.getStudUngrade(3) self.assertEqual(len(x), 0) self.assertIsInstance(str(self._grCtr), str)
def removeGrade(self, studIdentifier, discIdentifier, gradeValue): """ Sterge o nota pentru studentul studIdentifier, la disciplina discIdentifier cu valoarea gradeValue :param studIdentifier: id-ul studentului - string :param discIdentifier: id-ul disciplinei - string :param gradeValue: valoarea notei - float :raise: InvalidIDError - daca id-ul studentului sau al disciplinei este invalid :raise: InvalidGradeError - daca valoarea notei este invalida :raise: NonExistentIDError - daca disciplina cu id-ul dat nu exista """ try: self.__studValidator.validateID(studIdentifier) self.__discValidator.validateID(discIdentifier) except InvalidIDError as err: raise InvalidIDError(str(err)) try: self.__gradeValidator.validateGrade(gradeValue) except InvalidGradeError as err: raise InvalidGradeError(str(err)) try: self.__catalogue.findDisciplineByID(discIdentifier) self.__catalogue.findStudentByID(studIdentifier) except NonExistentIDError as err: raise NonExistentIDError(str(err)) try: self.__gradesRepo.removeGrade( Grade(gradeValue, studIdentifier, discIdentifier)) except NonExistentGradeError as err: raise NonExistentGradeError(str(err))
def read_from_file(self): ''' read_from_file -> list of Grades Reads information about grades from a file and puts it in a list, raises IOError if the file is corrupted ''' grades = [] try: f = open("data/grades", "r") line = f.readline() while line != "": object = line.split(",") student = None course = None for i in range(0, len(self.students)): if self.students[i].get_id() == int(object[0]): student = self.students[i] if student == None: raise IOError for i in range(0, len(self.courses)): if self.courses[i].get_id() == int(object[1]): course = self.courses[i] if course == None: raise IOError gr = float(object[2]) grade = Grade(student, course, gr) self.validator.validate(grade) grades.append(grade) line = f.readline() f.close() return grades except IOError: raise ValueError("Cannot read grades")
def __load_from_file(self): try: file = open(self.__file_name, "r") line = file.readline().strip() while line != "": attributes = line.split(";") if attributes[2] != "None": grade = Grade(int(attributes[0]), int(attributes[1]), int(attributes[2])) else: grade = Grade(int(attributes[0]), int(attributes[1])) Grade_repository.add(self, grade) line = file.readline().strip() except IOError as ioerror: raise RepositoryError(str(ioerror)) finally: file.close()
def test_add(self): self.assertEqual(len(self.__grade_repository), 0) self.__grade_repository.add(self.__grade) self.assertEqual(len(self.__grade_repository), 1) grade2 = Grade(5, 8, None) self.__grade_repository.add(grade2) self.assertEqual(len(self.__grade_repository), 2) self.assertEqual(self.__grade_repository.get_all()[1], grade2)
def generate_grades(self, amount): for value in range(amount): assignment_id = Generator.get_random_number(1, 100) student_id = Generator.get_random_number(1, 100) grade = Generator.get_random_number(2, 10) self.__grade_repository.add( Grade(assignment_id, student_id, grade if grade >= 6 else None))
def setUp(self): self.students = StudentRepository() courses = CourseRepository() grades = GradeRepository() self.course1 = Course(1, "Asc", "Vancea") self.student1 = Student(1, "Vlad") self.student2 = Student(2, "Alex") courses.save(self.course1) self.students.save(self.student1) self.students.save(self.student2) self.course2 = Course(2, "Fp", "I") courses.save(self.course2) self.grade1 = Grade(self.student1, self.course1, 10) self.grade2 = Grade(self.student1, self.course2, 4) grades.save(self.grade1) grades.save(self.grade2) self.grade_controller = GradeController(courses, self.students, grades)
def testRemoveGrade(self): gr = Grade(2, 3, 6.3) self.r.add(gr) self.r.add(self.g) self.assertEqual(len(self.r.getAll()), 2) self.assertRaises(RepoException, self.r.removeGrade, self.s) self.r.removeGrade(gr) self.assertEqual(len(self.r.getAll()), 1) self.assertRaises(RepoException, self.r.removeGrade, gr)
def setUp(self): self.undo = UndoController() self.stCtr = StudentController(Repository(), StudentValidator(), self.undo) self.asCtr = AssignmnetController(Repository(), AssignmentValidator(), self.undo) self.grade = Grade(1, 1, 5.0) self._grCtr = GradeController(Repository(), GradeValidator(), self.stCtr, self.asCtr, self.undo)
def give_assignment(self, assignment_id, student_id): """ Method for giving an assignment (empty grade) to a student assignment_id - The assignment's ID (integer) student_id - The student's ID (integer) """ grade = Grade(assignment_id, student_id, None) self.__grade_validator.validate(grade) self.__grade_repository.add(grade)
def setUp(self): self.grades = GradeRepository() self.course1 = Course(1, "Asc", "Vancea") self.student1 = Student(1, "Vlad") self.student2 = Student(2, "Ion") self.course2 = Course(2, "Fp", "I") self.grade1 = Grade(self.student1, self.course1, 10) self.grade2 = Grade(self.student1, self.course2, 4) self.grade3 = Grade(self.student2, self.course1, 7) self.grade4 = Grade(self.student1, self.course1, 8) self.grades.save(self.grade1) self.grades.save(self.grade2)
def grade_student(self, student_id, assignment_id, grade_value): """ Method for grading a student (update an empty grade) student_id - The student's ID (integer) assignment_id - The assignment's ID (integer) grade_value - The grade's value (integer) """ grade = Grade(assignment_id, student_id, grade_value) self.__grade_validator.validate(grade) self.__grade_repository.update(assignment_id, student_id, grade)
def testRmvStGr(self): self._grCtr.student.add(Student(1, "John", "913")) self.stCtr.add(Student(2, "Mary", "913")) self.assertEqual(len(self.stCtr.getAll()), 2) self._grCtr.add(Grade(3, 1, 2.0)) self._grCtr.add(Grade(4, 1, 7.0)) self._grCtr.add(Grade(2, 1, 5.0)) self._grCtr.add(Grade(2, 2, 3.0)) self.assertEqual(len(self._grCtr.getAll()), 4) self._grCtr.removeStud(1) self.assertEqual(len(self.stCtr.getAll()), 1) self.assertEqual(len(self._grCtr.getAll()), 1) self.undo.undo() self.assertEqual(len(self.stCtr.getAll()), 2) self.assertEqual(len(self._grCtr.getAll()), 4) self.undo.redo() self.assertEqual(self.stCtr.getAll()[0], Student(2, "Mary", "913")) self.assertEqual(self._grCtr.getAll()[0], Grade(2, 2, 3.0)) self.assertFalse(self._grCtr.removeStud(1))
def create(self, student, course, grade): ''' create -> Grade Creates and returns a Grade that is assigned to the given student at the given course :param student: Student :param course: Course :param grade: int ''' grade = Grade(student, course, grade) return grade
def testAdd(self): self.assertEqual(len(self._grCtr.getAll()), 0) self._grCtr.add(self.grade) self.assertEqual(len(self._grCtr.getAll()), 1) self._grCtr.add(Grade(3, 2, 2.2)) self.assertEqual(len(self._grCtr.getAll()), 2) self.undo.undo() self.undo.undo() self.assertEqual(len(self._grCtr.getAll()), 0) self.assertRaises(ControllerException, self.undo.undo) self.assertRaises(TypeError, self._grCtr.add, 1)
def load_grades(self): try: file = open(self.__filename, 'r') line = file.readline().strip() while len(line) > 0: line = line.split(',') self.__grades.add(Grade(int(line[0]), int(line[1]), None if line[2] == 'None' else int(line[2]))) line = file.readline().strip() file.close() except IOError as e: raise e
def getGrades(nb): lista = [] frNameAr = [0] * (nb + 1) frAssigAr = [0] * (nb + 1) while nb > 0: n = randint(1, 100) if frNameAr[n] == 0: frNameAr[n] = 1 for i in range(randint(1, 8)): a = randint(1, 100) if frAssigAr[a] == 0: frAssigAr[a] = 1 lista.append(Grade(n, a, round(uniform(0, 10), 2))) nb -= 1 frAssigAr[i] = 0 return lista
def setGrade(self, studID, assigID, grade): ''' Sets grade at a given assignment of a given student Input: studID - positive integer assigID - positive int grade - float in [0,10] Output: True - if setting succeded False - otherwise ''' newGrade = Grade(assigID, studID, grade) GradeValidator().validate(newGrade) oldGrade = self.findByID(studID, assigID) if type(oldGrade) != Grade: raise ValueError("There does not exist such a grade!") if oldGrade.grade != 0.0: raise ControllerException("This grade was already assigned!") self.update(newGrade) return True
def generate_random_grades(self): grades = [None,'1','2','3','4','5','6','7','8','9','10'] i = 0 while i < 100: done = False random_stud_id = random.randint(0, len(self.llist_s) - 1) random_assign_id = random.randint(0, len(self.llist_a) - 1) if len(self._grades_list) > 0: for grade in self._grades_list: if grade.student_id == self.llist_s.student_list_service[random_stud_id].student_id and grade.assignment_ID == self.llist_a.list_of_assignments[random_assign_id].assignment_ID: done = True break if done == False: rand_grade_index = random.randint(0,10) grade = Grade(self.llist_s.student_list_service[random_stud_id].student_id, self.llist_a.list_of_assignments[random_assign_id].assignment_ID, grades[rand_grade_index]) i += 1 self._grades_list.grade_list.add_grade(grade)
def testStat3(self): self._grCtr.giveAssigToGroup(3, "10") self._grCtr.add(Grade(1, 8, 6.0)) self._grCtr.add(Grade(3, 8, 8.0)) self._grCtr.add(Grade(5, 3, 5.5)) self._grCtr.add(Grade(2, 8, 10.0)) self._grCtr.add(Grade(4, 2, 7.0)) self._grCtr.add(Grade(6, 3, 5.5)) x = self._stat.getStudBestGrSchool() self.assertEqual(len(x), 10) self.assertEqual(x[0].grade, 8.0) self.assertEqual(x[1].grade, 7.0) self.assertEqual(x[2].grade, 5.5) self.assertEqual(x[3].grade, 0.0)
def setAssigStud(self, assignmentID, studentID, cascade=None): ''' Assign an assignment to a student by adding in grades list a grade assignmenID, studentID and a mark of 0 Input: - assignmentID - int >=0 - studentID - int >=0 Output: - True - if setting succeded - Fale - otherwise ''' if self.filterGradesBy(studentID, assignmentID) == []: redo = FunctionCall(self.setAssigStud, assignmentID, studentID, 0.0) undo = FunctionCall(self.remove, studentID, assignmentID, True) if not isinstance(cascade, OperationsCascade): self._undo.addOperation(Operation(redo, undo)) else: cascade.addOp(Operation(redo, undo)) self.add(Grade(assignmentID, studentID, 0.0), True) return True return False
def testRmvAsGr(self): self._grCtr.assignment.add(Assignment(1, "ASC", "8/10/2018")) self.asCtr.add(Assignment(2, "FP", "10/10/2018")) self.assertEqual(len(self.asCtr.getAll()), 2) self._grCtr.add(Grade(2, 1, 0.0)) self._grCtr.add(Grade(1, 1, 2.0)) self._grCtr.add(Grade(1, 1, 7.0)) self._grCtr.add(Grade(2, 1, 5.0)) self._grCtr.add(Grade(2, 2, 3.0)) self.undo.undo() self.undo.undo() self._grCtr.add(Grade(2, 1, 8.0)) self._grCtr.add(Grade(2, 2, 9.0)) self.assertEqual(len(self._grCtr.getAll()), 5) self._grCtr.removeAssign(2) self.assertEqual(len(self.asCtr.getAll()), 1) self.assertEqual(len(self._grCtr.getAll()), 2) self.undo.undo() self.assertEqual(len(self.asCtr.getAll()), 2) self.assertEqual(len(self._grCtr.getAll()), 5) self.undo.redo() self.assertEqual(self._grCtr.getAll()[1], Grade(1, 1, 7.0)) self.assertFalse(self._grCtr.removeAssign(2))
def testGiveAssign(self): self.stCtr.add(Student(1, "John", "913")) self.stCtr.add(Student(2, "Mary", "913")) self.stCtr.add(Student(3, "Oliver", "914")) self.stCtr.add(Student(4, "Greg", "913")) self.stCtr.add(Student(5, "Silvia", "914")) self.assertEqual(len(self.stCtr.getAll()), 5) self.asCtr.add(Assignment(1, "ASC", "08/12/2018")) self.asCtr.add(Assignment(2, "FP", "29/11/2018")) self.assertEqual(len(self.asCtr.getAll()), 2) self._grCtr.giveAssigToGroup(2, "913") self.assertEqual(len(self._grCtr.getAll()), 3) self._grCtr.giveAssigToGroup(1, "914") self.assertEqual(len(self._grCtr.getAll()), 5) self.undo.undo() self.undo.undo() self._grCtr.setAssigStud(2, 3) self.assertEqual(len(self._grCtr.getAll()), 1) self.assertEqual(self._grCtr.getAll()[0], Grade(2, 3, 0.0)) self.assertRaises(ValueError, self._grCtr.giveAssigToGroup, 5, "dsadas2") self.assertFalse(self._grCtr.setAssigStud(2, 3))
def _test_grade(self): ''' Tests if creating a grade works ''' grade = [Grade("test", 123, "John", 10), Grade(" test 2 ", "123", 5, "9.5"), Grade(1, 125.5, "Johnny Money ", 15), Grade("", "125.5", "", "15.5"), Grade(False, False, True, True)] assert Grade.getDiscipline(grade[0]) == "test" assert Grade.getStudentID(grade[0]) == 123 assert Grade.getTeacher(grade[0]) == "John" assert Grade.getGrade(grade[0]) == 10.0 assert Grade.getDiscipline(grade[1]) == " test 2 " assert Grade.getStudentID(grade[1]) == 123 assert Grade.getTeacher(grade[1]) == "" assert Grade.getGrade(grade[1]) == 9.5 assert Grade.getDiscipline(grade[2]) == "" assert Grade.getStudentID(grade[2]) == -1 assert Grade.getTeacher(grade[2]) == "Johnny Money " assert Grade.getGrade(grade[2]) == -1 assert Grade.getDiscipline(grade[3]) == "" assert Grade.getStudentID(grade[3]) == -1 assert Grade.getTeacher(grade[3]) == "" assert Grade.getGrade(grade[3]) == -1 assert Grade.getDiscipline(grade[4]) == "" assert Grade.getStudentID(grade[4]) == -1 assert Grade.getTeacher(grade[4]) == "" assert Grade.getGrade(grade[4]) == 1