def setUp(self): self.repo = DisciplineRepository() d1 = Discipline("maths", "Andrea") d2 = Discipline("physics", "Columban") self.repo.add(d1) self.repo.add(d2)
def test_discipline__add(self): disicplineToTest = Discipline(1, "Chemistry") self.disciplineController.add(1, "Chemistry") self.assertEqual( self.disciplineController.get_repository().get_list()[2].get_ID(), disicplineToTest.get_ID()) self.assertEqual( self.disciplineController.get_repository().get_list() [2].get_name(), disicplineToTest.get_name())
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 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 testDisciplineRepository(self): repo = DisciplineRepository() d1 = Discipline(1, "Japanese") d2 = Discipline(1, "How to draw anime") assert len(repo) == 0 repo.add(d1) assert len(repo) == 1 assert repo.findBydID(1) == d1 assert repo.searchStringinName("AP") == [d1] assert repo.searchStringinName("ta") == [] try: repo.add(d1) assert False except DisciplineException: assert True try: repo.add(d2) assert False except DisciplineException: assert True d2 = Discipline(2, "How to draw anime") repo.add(d2) assert len(repo) == 2 assert repo.findBydID(1) == d1 assert repo.findBydID(2) == d2 repo.update(2, "Anime") repo.remove(1) assert len(repo) == 1 assert repo.findBydID(2) == d2 assert repo.findBydID(1) == None try: repo.remove(1) assert False except DisciplineException: assert True repo.remove(2) assert len(repo) == 0
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 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 testDisciplineRepository(): repo = DisciplineRepository() d1 = Discipline("maths", "Andrea") d2 = Discipline("maths", "Columban") assert len(repo) == 0 repo.add(d1) assert len(repo) == 1 assert repo.findByName("maths") == d1 try: repo.add(d1) assert False except DisciplineException: assert True try: repo.add(d2) assert False except DisciplineException: assert True d2 = Discipline("physics", "Huber") repo.add(d2) assert len(repo) == 2 assert repo.findByName("maths") == d1 assert repo.findByName("physics") == d2 repo.update("physics", "Corega") assert len(repo) == 2 repo.remove("maths") assert len(repo) == 1 assert repo.findByName("physics") == d2 assert repo.findByName("maths") == None try: repo.remove("maths") assert False except DisciplineException: assert True repo.remove("physics") assert len(repo) == 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 __addDisciplineMenu(self): ''' adds a Discipline to the register Input: - Output: a new Discipline is read and added (if there is no other Discipline with the same name) ''' name = input("Please enter the Discipline name: ") teacher = input("Please enter the Discipline teacher: ") try: dis = Discipline(name, teacher) self.__disCtrl.addDiscipline(dis) except DisciplineException as ex: print(ex)
def __addDisciplineMenu(self): """ adds a Discipline to the list Input: none Output: a new Discipline is read and added (assuming there is no discipline with the same ID already) """ ID = UI.readPositiveInteger("Please enter the discipline ID: ") name = input("Please enter the discipline name: ") try: dis = Discipline(ID, name) self.__disCtrl.addDiscipline(dis) except DisciplineException as ex: print(ex)
class DisciplineDomainTestCase(unittest.TestCase): ''' unit test for DisciplineDomain ''' def setUp(self): self.dis = Discipline("maths", "Andrea") def testGetters(self): self.assertEqual(self.dis.getName(), "maths") self.assertEqual(self.dis.getTeacher(), "Andrea") def testSetters(self): self.dis.setName("physics") self.dis.setTeacher("Corega") self.assertEqual(self.dis.getName(), "physics") self.assertEqual(self.dis.getTeacher(), "Corega")
def _loadFromFile(self): ''' loads information from the file Input: - Output: loaded information ''' try: f = open(self._fName, "r") except IOError: return line = f.readline().strip() while line != "": t = line.split(";") dis = Discipline(t[0], t[1]) self.add(dis) line = f.readline().strip() f.close()
def pop(self, key): self.__data.pop(key) def getAll(self): return self.__data def filternewlist(self, newlist): self.__data = newlist DisRepo = Repo() for i in DisRepo: print(i) d1 = Discipline(1, "Japanese") d2 = Discipline(2, "Manga") d3 = Discipline(3, "History") d4 = Discipline(4, "Game Theory") DisRepo.append(d1) DisRepo.append(d2) DisRepo.append(d4) DisRepo.append(d3) #DisRepo.__delitem__(1) # DisRepo.__setitem__(0, d2) def GnomeSort(List, cmpfunction): pos = 0
def testUpdate(self): upD = Discipline("physics", "Huber") self.repo.update("physics", "Huber") d = self.repo.findByName("physics") self.assertEqual(d, upD)
def testAdd(self): d = Discipline("chemistry", "Baiazid") self.repo.add(d) self.assertEqual(len(self.repo), 3) self.assertRaises(DisciplineException, self.repo.add, d)
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"))
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")) repoGrade.addStudentToDiscipline("Algebra", 1) repoGrade.addStudentToDiscipline("Analysis", 1)
def setUp(self): self.dis = Discipline("maths", "Andrea")
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