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 _storeToFile(self): ''' stores information to the file Input: - Output: stored information ''' f = open(self._fName, "w") grades = GradeRepository.getAll(self) for gra in grades: graf = gra.getDiscipline() + ";" + str(gra.getStudentID()) + ";" + str(gra.getGrade()) + "\n" f.write(graf) f.close()
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 testStatisticsController(): graRepo = GradeRepository() disRepo = DisciplineRepository() stuRepo = StudentRepository() ctrl = StatisticsController(graRepo, disRepo, stuRepo) try: ctrl.byDiscipline("Algebra") assert False except DisciplineException: assert True assert ctrl.byAverageGrades() == []
def testDisciplineController(self): disRepo = DisciplineRepository() graRepo = GradeRepository() stuRepo = StudentRepository() undoCtrl = UndoController() ctrl = DisciplineController(disRepo, graRepo, stuRepo, undoCtrl) d1 = Discipline(1, "Japanese") d2 = Discipline(1, "Anime") assert len(ctrl) == 0 ctrl.addDiscipline(d1) assert len(ctrl) == 1 assert ctrl.searchDisciplineID(1) == d1 try: ctrl.addDiscipline(d1) assert False except DisciplineException: assert True try: ctrl.addDiscipline(d2) assert False except DisciplineException: assert True d2 = Discipline(2, "Manga") ctrl.addDiscipline(d2) assert len(ctrl) == 2 assert ctrl.searchStringinNameDiscipline("ANG") == [d2] assert ctrl.searchStringinNameDiscipline("nes") == [d1] ctrl.updateDiscipline(1,"Anime") assert ctrl.searchStringinNameDiscipline("nim") == [d1] assert len(ctrl) == 2 ctrl.removeDiscipline(1) assert len(ctrl) == 1 assert ctrl.searchDisciplineID(1) == None assert ctrl.searchDisciplineID(2) == d2 try: ctrl.removeDiscipline(1) assert False except DisciplineException: assert True ctrl.removeDiscipline(2) assert len(ctrl) == 0
def testStudentController(): stuRepo = StudentRepository() graRepo = GradeRepository() undoCtrl = UndoController() ctrl = StudentController(stuRepo, graRepo, undoCtrl) s1 = Student(1, "Vasilica") s2 = Student(1, "Gheorghidiu") assert len(ctrl) == 0 ctrl.addStudent(s1) assert len(ctrl) == 1 assert ctrl.findStudentByName("Vasilica") == [s1] assert ctrl.findStudentByName("John") == [] try: ctrl.addStudent(s1) assert False except StudentException: assert True try: ctrl.addStudent(s2) assert False except StudentException: assert True s2 = Student(2, "Gheorghidiu") ctrl.addStudent(s2) assert len(ctrl) == 2 assert ctrl.findStudentByName("Vasilica") == [s1] assert ctrl.findStudentByName("Gheorghidiu") == [s2] ctrl.updateStudent(2, "Johnny Bravo") assert len(ctrl) == 2 ctrl.removeStudent(1) assert len(ctrl) == 1 assert ctrl.findStudentByName("Johnny Bravo") == [s2] assert ctrl.findStudentByName("Vasilica") == [] try: ctrl.removeStudent(1) assert False except StudentException: assert True ctrl.removeStudent(2) assert len(ctrl) == 0
def testStudentController(self): stuRepo = StudentRepository() graRepo = GradeRepository() undoCtrl = UndoController() disRepo = DisciplineRepository() ctrl = StudentController(stuRepo, graRepo, disRepo, undoCtrl) s1 = Student(1, "Putin") s2 = Student(1, "Boruto") assert len(ctrl) == 0 ctrl.addStudent(s1) assert len(ctrl) == 1 assert ctrl.searchStudentID(1) == s1 try: ctrl.addStudent(s1) assert False except StudentException: assert True try: ctrl.addStudent(s2) assert False except StudentException: assert True s2 = Student(2, "Naruse") ctrl.addStudent(s2) assert len(ctrl) == 2 assert ctrl.searchStringinNameStudent("TIN") == [s1] assert ctrl.searchStringinNameStudent("rus") == [s2] ctrl.updateStudent(1, "Hagi") assert len(ctrl) == 2 ctrl.removeStudent(1) assert len(ctrl) == 1 assert ctrl.searchStudentID(1) == None assert ctrl.searchStudentID(2) == s2 try: ctrl.removeStudent(1) assert False except StudentException: assert True ctrl.removeStudent(2) assert len(ctrl) == 0
def testDisciplineController(): disRepo = DisciplineRepository() graRepo = GradeRepository() undoCtrl = UndoController() ctrl = DisciplineController(disRepo, graRepo, undoCtrl) d1 = Discipline("maths", "Andrea") d2 = Discipline("maths", "Columban") assert len(ctrl) == 0 ctrl.addDiscipline(d1) assert len(ctrl) == 1 assert ctrl.findDisciplineByTeacher("Andrea") == [d1] try: ctrl.addDiscipline(d1) assert False except DisciplineException: assert True try: ctrl.addDiscipline(d2) assert False except DisciplineException: assert True d2 = Discipline("physics", "Huber") ctrl.addDiscipline(d2) assert len(ctrl) == 2 assert ctrl.findDisciplineByTeacher("Andrea") == [d1] assert ctrl.findDisciplineByTeacher("Huber") == [d2] ctrl.updateDiscipline("physics", "Corega") assert len(ctrl) == 2 ctrl.removeDiscipline("maths") assert len(ctrl) == 1 assert ctrl.findDisciplineByTeacher("Corega") == [d2] assert ctrl.findDisciplineByTeacher("Andrea") == [] try: ctrl.removeDiscipline("maths") assert False except DisciplineException: assert True ctrl.removeDiscipline("physics") assert len(ctrl) == 0
dis = dis.split('=') gra = f.readline().replace(' ', '') gra = gra.replace('"', '') gra = gra.strip('\n') gra = gra.split('=') return rep[1], stu[1], dis[1], gra[1] reads = repomode() if reads[0] == "inmemory": repoDiscipline = DisciplineRepository() repoStudent = StudentRepository() repoGrade = GradeRepository() elif reads[0] == "textfiles": repoDiscipline = DisciplineRepositoryFile(readDisfromLine, writeDistoLine) repoStudent = StudentRepositoryFile(readStufromLine, writeStutoLine) repoGrade = GradeRepositoryFile(readGrafromLine, writeGratoLine) elif reads[0] == "binaryfiles": repoDiscipline = DisciplineRepositoryPickle(readDisfromLine, writeDistoLine, 'Disciplines.pickle') repoStudent = StudentRepositoryPickle(readStufromLine, writeStutoLine, 'Students.pickle') repoGrade = GradeRepositoryPickle(readGrafromLine, writeGratoLine,
from Controller.GradeController import GradeController from Controller.StatisticsController import StatisticsController from Controller.UndoController import UndoController from UI.UI import UI option = input("Do you want to operate (load/store information) with the file? If yes, type 'yes'. Otherwise, type anything else: ") if option == "yes": repoDiscipline = FileDisciplineRepository() repoStudent = FileStudentRepository() repoGrade = FileGradeRepository() else: repoDiscipline = DisciplineRepository() repoStudent = StudentRepository() repoGrade = GradeRepository() # add initial data repoDiscipline.add(Discipline("Algebra", "Crivei")) repoDiscipline.add(Discipline("Analysis", "no ideea")) repoDiscipline.add(Discipline("Computational Logic", "Lupea")) repoDiscipline.add(Discipline("Computational Systems Architecture", "Vancea")) repoDiscipline.add(Discipline("Fundamentals of Programming", "Arthur")) repoDiscipline.add(Discipline("Communication and Personal Development in Computer Science", "Motogna")) repoStudent.add(Student(1, "Harap-Alb")) repoStudent.add(Student(2, "Bestia")) repoStudent.add(Student(3, "Luceafarul")) repoStudent.add(Student(4, "Afrodita")) repoStudent.add(Student(5, "Shrek")) repoStudent.add(Student(6, "Bula"))
print(rep) print(stu) print(dis) print(gra) return rep[1], stu[1], dis[1], gra[1] reads = repomode() if reads[0] == "inmemory": repoDiscipline = DisciplineRepository() repoStudent = StudentRepository() repoGrade = GradeRepository() elif reads[0] == "textfiles": repoDiscipline = DisciplineRepositoryFile(readDisfromLine, writeDistoLine) repoStudent = StudentRepositoryFile(readStufromLine, writeStutoLine) repoGrade = GradeRepositoryFile(readGrafromLine, writeGratoLine) elif reads[0] == "binaryfiles": repoDiscipline = DisciplineRepositoryPickle(readDisfromLine, writeDistoLine, 'Disciplines.pickle') repoStudent = StudentRepositoryPickle(readStufromLine, writeStutoLine, 'Students.pickle') repoGrade = GradeRepositoryPickle(readGrafromLine, writeGratoLine,
def __init__(self, readGrafromLine, writeGratoLine, fname="Grades.txt"): self._fname = fname GradeRepository.__init__(self) self._readGrafromLine = readGrafromLine self._writeGratoLine = writeGratoLine
def testGradeController(): graRepo = GradeRepository() disRepo = DisciplineRepository() stuRepo = StudentRepository() undoCtrl = UndoController() ctrl = GradeController(graRepo, disRepo, stuRepo, undoCtrl) assert len(ctrl) == 0 try: ctrl.addStudentToDiscipline("maths", 1) assert False except (DisciplineException, StudentException): assert True try: ctrl.updateGrade("maths", 1, 0) assert False except (DisciplineException, StudentException): assert True try: ctrl.removeStudentFromDiscipline("maths", 1) assert False except (DisciplineException, StudentException): assert True d1 = Discipline("maths", "Andrea") disRepo.add(d1) assert disRepo.findByName("maths") == d1 s1 = Student(1, "Harap-Alb") stuRepo.add(s1) assert stuRepo.findByID(1) == s1 ctrl.addStudentToDiscipline("maths", 1) assert len(ctrl) == 1 try: ctrl.addStudentToDiscipline("maths", 1) assert False except GradeException: assert True try: ctrl.updateGrade("maths", 8, 10) assert False except (GradeException, DisciplineException, StudentException): assert True ctrl.updateGrade("maths", 1, 10) assert len(ctrl) == 1 ctrl.removeStudentFromDiscipline("maths", 1) assert len(ctrl) == 0 try: ctrl.removeStudentFromDiscipline("maths", 1) assert False except GradeException: assert True