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 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 setUp(self): self.repo = DisciplineRepository() d1 = Discipline("maths", "Andrea") d2 = Discipline("physics", "Columban") self.repo.add(d1) self.repo.add(d2)
def update(self, name, newTeacher): ''' updates a discipline in the DisciplineRepository Input: name - string, newTeacher - string Output: updates the updated discipline in the file ''' DisciplineRepository.update(self, name, newTeacher) self._storeToFile()
def add(self, dis): ''' adds a discipline to the DisciplineRepository Input: dis - discipline object Output: stores the added discipline to the file ''' DisciplineRepository.add(self, dis) self._storeToFile()
def __init__(self, readDisfromLine, writeDistoLine, fname='Disciplines.txt'): self._fname = fname DisciplineRepository.__init__(self) self._readDisfromLine = readDisfromLine self._writeDistoLine = writeDistoLine
def remove(self, name): ''' removes a discipline in the DisciplineRepository Input: name - string Output: removes the removed discipline from the file ''' dis = DisciplineRepository.remove(self, name) self._storeToFile() return dis
def _storeToFile(self): ''' stores information to the file Input: - Output: stored information ''' f = open(self._fName, "w") disciplines = DisciplineRepository.getAll(self) for dis in disciplines: disf = dis.getName() + ";" + dis.getTeacher() + "\n" f.write(disf) f.close()
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(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
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 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
class DisciplineRepositoryTestCase(unittest.TestCase): ''' unit test for DisciplineRepository ''' def setUp(self): self.repo = DisciplineRepository() d1 = Discipline("maths", "Andrea") d2 = Discipline("physics", "Columban") self.repo.add(d1) self.repo.add(d2) def testAdd(self): d = Discipline("chemistry", "Baiazid") self.repo.add(d) self.assertEqual(len(self.repo), 3) self.assertRaises(DisciplineException, self.repo.add, d) def testFindByName(self): d = self.repo.findByName("maths") self.assertEqual(d, Discipline("maths", "Andrea")) d = self.repo.findByName("js") self.assertEqual(d, None) self.assertTrue(d == None) def testUpdate(self): upD = Discipline("physics", "Huber") self.repo.update("physics", "Huber") d = self.repo.findByName("physics") self.assertEqual(d, upD) def testRemove(self): self.repo.remove("maths") self.assertEqual(len(self.repo), 1) self.assertRaises(DisciplineException, self.repo.remove, "chemistry")
def __init__(self, fname="Repository\\storedDisciplines.txt"): self._fName = fname DisciplineRepository.__init__(self) self._loadFromFile()
gra = gra.strip('\n') gra = gra.split('=') 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,
dis = dis.replace('"', '') dis = dis.strip('\n') 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,
from Controller.DisciplineController import DisciplineController from Controller.StudentController import StudentController 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"))