def TestInit(self): ''' Testeaza functia de initializare a unui student ''' studNou = Student(1, 'Tofan Paul-Adrian') assert studNou.GetIdStudent() == 1 assert studNou.GetNumeStudent() == 'Tofan Paul-Adrian'
def TestSetNumeStudent(self): ''' Testeaza functia de setare a unui nume a unui student ''' stud = Student(12, 'Asd') Student.SetNumeStudent(stud, 'Adi') assert Student.GetNumeStudent(stud) == 'Adi'
def TestGetTopMedii (self): ''' Testeaza functia de obtinere a mediilor in ordine descrescatoare ''' repo = RepositoryNota () NoteServ = NotaService (repo) StudServ = StudentService(Repository()) StudServ.adaugaStudent(Student(1,'asd')) StudServ.adaugaStudent(Student(2,'asd')) nota1 = Nota (1,2,9) nota2 = Nota (1,5,10) nota3 = Nota (1,2,7) nota4 = Nota (1,5,7) nota5 = Nota (1,2,8) nota6 = Nota (2,2,9) nota7 = Nota (2,2,8) NoteServ.AdaugaNota(nota1) NoteServ.AdaugaNota(nota2) NoteServ.AdaugaNota(nota3) NoteServ.AdaugaNota(nota4) NoteServ.AdaugaNota(nota5) NoteServ.AdaugaNota(nota6) NoteServ.AdaugaNota(nota7) listNote = NoteServ.GetNote() listStud = StudServ.getStudenti() assert NoteServ.GetTopMedii(listNote, listStud) == [8.5, 8.2]
def TestSetIdStudent(self): ''' Testeaza functia de setare a unui id a unui student ''' stud = Student(12, 'ASD') Student.SetIdStudent(stud, 1) assert Student.GetIdStudent(stud) == 1
def TestGetNumeStudent(self): ''' Testeaza functia de obtinere a unui nume a unui student ''' assert (Student.GetNumeStudent(Student( 5, 'Tofan Paul-Adrian')) == 'Tofan Paul-Adrian') assert (Student.GetNumeStudent(Student( 5, 'Trifescu Stefan')) == 'Trifescu Stefan')
def ValidareStudent(self, stud): ''' Valideaza un student ''' erori = '' if self.__validator.ValidareId(Student.GetIdStudent(stud)) == False: erori += 'Id-ul introdus nu este valid.' if self.__validator.ValidareNume( Student.GetNumeStudent(stud)) == False: erori += 'Numele introdus nu este valid.' if len(erori) > 0: raise ValidationStudentException(erori)
def TestEq(self): ''' Testeaza functia de egalitate dintre noi studenti ''' stud1 = Student(12, 'asd') stud2 = Student(25, 'asd') stud3 = Student(12, 'nsa') if stud1 == stud2: assert False if stud2 == stud3: assert False if stud1 == stud3: assert True
def __uiUpdateStudent(self): ''' Modifica un student vechi din lista de studenti Se citesc: id-ul vechi, numele vechi, id-ul nou, numele nou ''' idsVechi = input('Id: ') numeNou = input('Nume nou: ') studVechi = Student(idsVechi, 'asd') studNou = Student(idsVechi, numeNou) try: self.__validatorStudent.ValidareStudent(studVechi) self.__validatorStudent.ValidareStudent(studNou) try: self.__StudServ.updateStudent(studVechi, studNou) print('Student modificat cu succes!') except RepositoryExceptions as ve: print(ve) except ValidationStudentException as ve: print(ve)
def TestGetNoteStudent (self): ''' Testeaza functia de obtiere a tuturor notelor unui student ''' repo = RepositoryNota () nota1 = Nota (1,2,9) nota2 = Nota (1,5,10) nota3 = Nota (1,2,7) nota4 = Nota (1,5,7) nota5 = Nota (1,2,8) nota6 = Nota (2,2,9) nota7 = Nota (2,2,8) NoteServ = NotaService (repo) NoteServ.AdaugaNota(nota1) NoteServ.AdaugaNota(nota2) NoteServ.AdaugaNota(nota3) NoteServ.AdaugaNota(nota4) NoteServ.AdaugaNota(nota5) NoteServ.AdaugaNota(nota6) NoteServ.AdaugaNota(nota7) assert NoteServ.GetNoteStudent(Student(1,'Paul')) == [nota1, nota2, nota3, nota4, nota5] assert NoteServ.GetNoteStudent(Student(2,'Adi')) == [nota6, nota7]
def TestGetMedieStudent (self): ''' Testeaza functia de obtinere a mediei unui student ''' repo = RepositoryNota () NoteServ = NotaService (repo) nota1 = Nota (1,2,9) nota2 = Nota (1,5,10) nota3 = Nota (1,2,7) nota4 = Nota (1,5,7) nota5 = Nota (1,2,8) nota6 = Nota (2,2,9) nota7 = Nota (2,2,8) NoteServ.AdaugaNota(nota1) NoteServ.AdaugaNota(nota2) NoteServ.AdaugaNota(nota3) NoteServ.AdaugaNota(nota4) NoteServ.AdaugaNota(nota5) NoteServ.AdaugaNota(nota6) NoteServ.AdaugaNota(nota7) assert NoteServ.GetMedieStudent(Student(1,'asd')) == 8.2 assert NoteServ.GetMedieStudent(Student(2,'asd')) == 8.5
def TestValidareStudent(self): ''' Testeaza functia de validare a unui student ''' st1 = Student(1, 'Stefan Marian') try: self.__ValidatorStudent.ValidareStudent(st1) assert True except ValidationStudentException: assert False st2 = Student(1, '123') try: self.__ValidatorStudent.ValidareStudent(st2) assert False except ValidationStudentException: assert True st3 = Student(-15, '123') try: self.__ValidatorStudent.ValidareStudent(st3) assert False except ValidationStudentException: assert True
def __uiPrintMedieStudent(self): ''' Afiseaza media unui student dupa id Id-ul se citeste ''' ids = input('Id-ul studentului: ') stud = Student(ids, 'asd') try: self.__validatorStudent.ValidareStudent(stud) medie = self.__NotaServ.GetMedieStudent(stud) print(medie) except ValidationStudentException as ve: print(ve)
def __uiPrintDiscStud(self): ''' Afiseaza disciplinele la care participa un student ''' ids = input('Id student: ') stud = Student(ids, 'asd') try: self.__validatorStudent.ValidareStudent(stud) listDiscip = self.__DiscServ.getDiscipline() listDisc = self.__NotaServ.GetDiscStud(ids, listDiscip) if len(listDisc): for disc in listDisc: print(disc) except ValidationStudentException as ve: print(ve)
def __uiFindStudent(self): ''' Cauta un student dupa id in lista de studenti Id-ul se citeste ''' ids = input('Id: ') stud = Student(ids, 'asd') try: self.__validatorStudent.ValidareStudent(stud) try: studCautat = self.__StudServ.findStudent(stud) print('Student cautat: ' + str(studCautat)) except RepositoryExceptions as ve: print(ve) except ValidationStudentException as ve: print(ve)
def __uiAddStudent(self): ''' Adauga un student nou la lista de studenti. Id-ul si numele studentului se citesc ''' ids = input('Id: ') nume = input('Nume: ') stud = Student(ids, nume) try: self.__validatorStudent.ValidareStudent(stud) try: self.__StudServ.adaugaStudent(stud) print('Student adaugat cu succes!') except RepositoryExceptions as ve: print(ve) except ValidationStudentException as ve: print(ve)
def __uiRemoveStudent(self): ''' Sterge un student dupa id din lista de studenti Id-ul se citeste ''' ids = input('Id: ') stud = Student(ids, 'asd') try: self.__validatorStudent.ValidareStudent(stud) try: self.__StudServ.removeStudent(stud) self.__NotaServ.RemoveNoteStudent(ids) print('Stergerea s-a efectuat cu succes!') except RepositoryExceptions as ve: print(ve) except ValidationStudentException as ve: print(ve)
def __uiPrintNoteStudentiDisciplinaAlfabetic(self): ''' Afiseaza notele tuturor studentilor la o anumita disciplina ordonati in ordine alfabetica ''' idd = input('Id-ul disciplinei: ') try: self.__validatorDisciplina.ValidareDisciplina( Disciplina(idd, 'asd', 'asd')) listStudenti = self.__StudServ.getStudenti() listNoteStudenti = self.__NotaServ.GetNoteStudDiscAlfabetic( idd, listStudenti) n = len(listNoteStudenti) listStudAlfabetic = sorted( listStudenti, key=lambda Student: Student.GetNumeStudent()) for stud in range(n): noteStud = '' for nota in listNoteStudenti[stud]: noteStud += str(nota) noteStud += ' ' print(listStudAlfabetic[stud], ': ', noteStud) except ValidationDisciplinaException as ve: print(ve)
def __uiAddNota(self): ''' Adauga o noua nota in lista de note Id-ul studentului, id-ul disciplinei si calificativul se citesc ''' ids = input('Id student: ') idd = input('Id disciplina: ') calificativ = input('Calificativ: ') stud = Student(ids, 'asd') disc = Disciplina(idd, 'asd', 'asd') Erori = '' try: self.__validatorNota.ValidareNota(Nota(ids, idd, calificativ)) if stud not in self.__StudServ.getStudenti(): Erori += 'Student inexistent.' if disc not in self.__DiscServ.getDiscipline(): Erori += 'Disciplina inexistenta.' if len(Erori) > 0: print(Erori) else: self.__NotaServ.AdaugaNota(Nota(ids, idd, calificativ)) print('Nota adaugata cu succes!') except ValidationNotaException as ve: print(ve)
def TestGetIdStudent(self): ''' Testeaza functia de obtinere a unui id a unui student ''' assert (Student.GetIdStudent(Student(10, 'Tofan')) == 10) assert (Student.GetIdStudent(Student(312, 'Tofan')) == 312)