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 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()
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 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']]
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, 'Grades.pickle') repoDiscipline.add(Discipline(1, "How to draw manga")) repoDiscipline.add(Discipline(2, "Japanese")) repoDiscipline.add(Discipline(3, "Philosophy")) repoDiscipline.add(Discipline(4, "Anime")) repoDiscipline.add(Discipline(5, "Algebra")) repoDiscipline.add(Discipline(6, "Introduction to Economics")) repoDiscipline.add(Discipline(7, "Mathematical Analysis")) repoDiscipline.add(Discipline(8, "Football")) repoDiscipline.add(Discipline(9, "Table Tennis")) repoDiscipline.add(Discipline(10, "Tennis")) repoDiscipline.add(Discipline(11, "Introduction to Algorithms")) repoDiscipline.add(Discipline(12, "Dragons Language")) repoDiscipline.add( Discipline(13, "Introduction to How not to be a Social Outcast")) repoDiscipline.add(Discipline(14, "Game Theory"))
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