def testGradeController(self): graRepo = GradeRepository() disRepo = DisciplineRepository() stuRepo = StudentRepository() undoCtrl = UndoController() ctrl = GradeController(graRepo, disRepo, stuRepo, undoCtrl) assert len(ctrl) == 0 grade = Grade(1, 1, 9) try: ctrl.addGrade(grade) assert False except (DisciplineException, StudentException): assert True d = Discipline(1, "Japanese") s = Student(1, "Naruto") disRepo.add(d) stuRepo.add(s) ctrl.addGrade(grade) assert len(ctrl) == 1
def testGradeRepository(self): repo = GradeRepository() disrepo = DisciplineRepository() sturepo = StudentRepository() stu = Student(1, "Putin") dis = Discipline(1, "Maths") sturepo.add(stu) disrepo.add(dis) assert len(repo) == 0 gra1 = Grade(1, 1, 10) repo.addGrade(gra1, sturepo, disrepo) assert len(repo) == 1 repo.removeGrade(1, 1) assert len(repo) == 0 try: repo.removeGrade(1, 1) assert False except GradeException: assert True
def listInit(studentList, assignmentList, gradeList): firstName = [ "James ", "John ", "Robert ", "Michael ", "William ", "Mary ", "Patricia ", "Jennifer ", "Linda ", "Elizabeth " ] lastName = [ "Smith", "Johnson", "Williams", "Brown", "Jonrs", "Garcia", "Miller", "Davis", "Rodriguez", "Martinez" ] group = [511, 512, 513, 514, 515, 516] for i in range(100): studentList.addObject( Student(i + 1, choice(firstName) + choice(lastName), choice(group))) desc1 = [ "Copper ", "Nitric Acid ", "Potassium Iodide ", "Hydrogen Peroxide ", "Alkali Metal " ] desc2 = [ "in Water", "reaction", "coloring Fire", "dehydration", "and thermite" ] deadline = [3, 4, 5, 6] for i in range(100): assignmentList.addObject( Assignment(i + 1, choice(desc1) + choice(desc2), choice(deadline))) nr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] for i in range(100): gradeList.addObject(Grade(1 + i, 100 - i, choice(nr)))
def addStudentToDiscipline(self, discipline, studentID): ''' adds a student to a discipline Input: discipline - string, the name of the discipline that the student must be added to studentID - positive integer, the ID of the student to add to the discipline Output: the given Grade is added, if no other Grade with the same discipline and studentID exists ! the given Grade's grade is initialized with 0 Exceptions: raises DisciplineException if the given discipline's name does not exist in DisciplineRepository raises StudentException if the given student's ID does not exist in StudentRepository raises GradeException if another Grade with the same discipline and studentID already exists ''' # remove undo indexes self.__operations = self.__operations[0:self.__index] if self.__disRepo.findByName(discipline) == None: raise DisciplineException("There is no Discipline with name " + discipline + "!") if self.__stuRepo.findByID(studentID) == None: raise StudentException("The is no Student with ID " + str(studentID) + "!") self.__repo.addStudentToDiscipline(discipline, studentID) gra = Grade(discipline, studentID, 0) # if no exceptions were raised => record the operation for undo self.__operations.append(AddOperation(gra)) self.__index += 1 self.__undoCtrl.recordUpdatedController([self])
def test_grade_add(self): gradeToAdd = Grade(12, 12, 13) try: self.validator.gradeInStudentAndDisciplineRepository( gradeToAdd, self.studentController.get_repository(), self.disciplineController.get_repository()) self.assertTrue(True) except: self.assertFalse(True) gradeToAdd = Grade(16, 12, 13) try: self.validator.gradeInStudentAndDisciplineRepository( gradeToAdd, self.studentController.get_repository(), self.disciplineController.get_repository()) self.assertFalse(True) except: self.assertTrue(True)
def giveAssigmenttoStudent(self,ids,ida): undo = FunctionCall(self.removeAssignment,ids,ida) redo = FunctionCall(self.giveAssigmenttoStudent,ids, ida) oper = Operation(undo,redo) self._undoController.addOperation(oper) for i in range(len(self._gradeList)): if self._gradeList.getObject(i).getStudentID() == ids and self._gradeList.getObject(i).getAssignmentID() == ida: return None self._gradeList.addObject(Grade(ida,ids,-1))
def add_grade(self, studentID, disciplineID, gradeValue): """ Description:adds a grade to the gradeRepository """ self.history.append( ["addGrade", [studentID, disciplineID, gradeValue]]) gradeToAdd = Grade(studentID, disciplineID, gradeValue) self.validator.gradeInStudentAndDisciplineRepository( gradeToAdd, self.get_student_repostiory(), self.get_discipline_repostiory()) self.__gradeController.add(studentID, disciplineID, gradeValue)
def addStudentToDiscipline(self, discipline, studentID): ''' adds a student to a discipline Input: discipline - string, the name of the discipline that the student must be added to studentID - positive integer, the ID of the student to add to the discipline Output: the given Grade is added to the repository, if no other Grade with the same discipline and studentID exists ! the given Grade's grade is initialized with 0 Exceptions: raises GradeException if another Grade with the same discipline and studentID already exists ''' if self.findByDisciplineAndStudentID(discipline, studentID) != None: raise GradeException("Student with ID " + str(studentID) + " already added to discipline " + discipline + "!") gra = Grade(discipline, studentID, 0) self.__data.append(gra)
def testGradeRepository(): repo = GradeRepository() assert len(repo) == 0 repo.addStudentToDiscipline("maths", 1) assert len(repo) == 1 g1 = Grade("maths", 1, 0) assert repo.findByDisciplineAndStudentID("maths", 1) == g1 try: repo.addStudentToDiscipline("maths", 1) assert False except GradeException: assert True try: repo.updateGrade("maths", 8, 10) assert False except GradeException: assert True repo.updateGrade("maths", 1, 10) assert len(repo) == 1 g2 = Grade("maths", 1, 10) assert repo.findByDisciplineAndStudentID("maths", 1) == g2 repo.removeStudentFromDiscipline("maths", 1) assert len(repo) == 0 try: repo.removeStudentFromDiscipline("maths", 1) assert False except GradeException: assert True
def __addGradeMenu(self): """ adds a Grade to the list Input: none Output: a new Grade is read and added (assuming there that given ID's for student and discipline are valid) """ disciplineID = UI.readPositiveInteger( "Please enter the discipline ID: ") studentID = UI.readPositiveInteger("Please enter the student ID: ") grade = UI.readGrade("Please enter the grade") try: gra = Grade(disciplineID, studentID, grade) self.__graCtrl.addGrade(gra) except (GradeException, DisciplineException, StudentExcetpion) as ex: print(ex)
def testStatisticsController(self): graRepo = GradeRepository() stuRepo = StudentRepository() disRepo = DisciplineRepository() disRepo.add(Discipline(1, "Dragons Language")) disRepo.add(Discipline(2, "How to draw anime")) disRepo.add(Discipline(3, "Japanese")) stuRepo.add(Student(1, "Putin")) stuRepo.add(Student(2, "Sheldon Cooper")) stuRepo.add(Student(3, "Nietzsche")) stuRepo.add(Student(4, "Mio Naruse")) graRepo.addGrade(Grade(1, 1, 9.9), stuRepo, disRepo) graRepo.addGrade(Grade(2, 1, 4.8), stuRepo, disRepo) graRepo.addGrade(Grade(3, 1, 5.7), stuRepo, disRepo) graRepo.addGrade(Grade(2, 2, 9.0), stuRepo, disRepo) graRepo.addGrade(Grade(1, 3, 6.0), stuRepo, disRepo) graRepo.addGrade(Grade(2, 3, 7.3), stuRepo, disRepo) graRepo.addGrade(Grade(3, 3, 4.2), stuRepo, disRepo) graRepo.addGrade(Grade(3, 3, 7.9), stuRepo, disRepo) ctrl = StatisticsController(stuRepo, disRepo, graRepo) assert ctrl.byDisciplineAlphabetically(3) == [[3, 'Nietzsche'], [1, 'Putin']] assert ctrl.byDisciplineAlphabetically(2) == [[3, 'Nietzsche'], [1, 'Putin'], [2, 'Sheldon Cooper']] assert ctrl.failingStudents() == [[1, 'Putin']] assert ctrl.topStudents() == [[9.0, 2, 'Sheldon Cooper'], [6.8, 1, 'Putin'], [6.45, 3, 'Nietzsche']] assert ctrl.topDiscipline() == [[7.95, 1, 'Dragons Language'], [ 7.033333333333334, 2, 'How to draw anime' ], [5.933333333333334, 3, 'Japanese']]
def setUp(self): self.gra = Grade("maths", 1, 8)
class GradeDomainTestCase(unittest.TestCase): ''' unit test for GradeDomain ''' def setUp(self): self.gra = Grade("maths", 1, 8) def testGetters(self): self.assertEqual(self.gra.getDiscipline(), "maths") self.assertEqual(self.gra.getStudentID(), 1) self.assertEqual(self.gra.getGrade(), 8) def testSetters(self): self.gra.setDiscipline("physics") self.gra.setStudentID(2) self.gra.setGrade(9) self.assertEqual(self.gra.getDiscipline(), "physics") self.assertEqual(self.gra.getStudentID(), 2) self.assertEqual(self.gra.getGrade(), 9)
repoStudent.add(Student(23, "Light Yagami")) repoStudent.add(Student(24, "Axl Rose")) repoStudent.add(Student(25, "Harry Potter")) repoStudent.add(Student(26, "Gottfried Wilhelm von Leibniz")) repoStudent.add(Student(27, "Rene Descartes")) repoStudent.add(Student(28, "Antoine Griezmann")) repoStudent.add(Student(29, "Rafael Nadal")) repoStudent.add(Student(30, "Barney Stinson")) repoStudent.add(Student(31, "Lucy Heartfilia")) repoStudent.add(Student(32, "Edward Elric")) repoStudent.add(Student(33, "Erza Scarlet")) repoStudent.add(Student(34, "Sena Kashiwazaki")) repoStudent.add(Student(35, "Yusuke Urameshi")) repoStudent.add(Student(36, "John von Neumann")) repoGrade.addGrade(Grade(1, 1, 10), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(2, 12, 2.49), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(6, 33, 1.43), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(9, 2, 7.89), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(9, 34, 9.84), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(13, 5, 6.22), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(14, 28, 7.6), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(8, 14, 7.62), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(8, 30, 6.7), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(10, 27, 5.1), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(4, 10, 7.91), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(8, 29, 7.78), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(11, 22, 9.69), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(13, 5, 1.22), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(11, 6, 8.77), repoStudent, repoDiscipline) repoGrade.addGrade(Grade(14, 11, 7.19), repoStudent, repoDiscipline)