def TestValidareNota(self): ''' Testeaza functia de validare a unei discipline ''' nota = Nota(1, 1, 10) try: self.__validator.ValidareNota(nota) assert True except ValidationNotaException: assert False nota = Nota(1, 1, 12) try: self.__validator.ValidareNota(nota) assert False except ValidationNotaException: assert True nota = Nota(1, -5, 10) try: self.__validator.ValidareNota(nota) assert False except ValidationNotaException: assert True nota = Nota(-5, 1, 10) try: self.__validator.ValidareNota(nota) assert False except ValidationNotaException: assert True
def TestAdaugaNota(self): ''' Testeaza functia de initializare a NotaService ''' repo = RepositoryNota () NoteServ = NotaService(repo) nota1 = Nota (1,4,7) NoteServ.AdaugaNota(nota1) assert NoteServ.GetNote() == [nota1] nota2 = Nota (2,4,9) NoteServ.AdaugaNota(nota2) assert NoteServ.GetNote() == [nota1, nota2]
def TestGetNoteDisciplinaStudent (self): ''' Testeaza functia de obtinere a tuturor notelor pentru un student la o anumita disciplina ''' 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.GetNoteStudentDisciplina(2, 1) == [nota1, nota3, nota5] assert NoteServ.GetNoteStudentDisciplina(5,1) == [nota2, nota4] assert NoteServ.GetNoteStudentDisciplina(2, 2) == [nota6, nota7] assert NoteServ.GetNoteStudentDisciplina(5,5) == [] assert NoteServ.GetNoteStudentDisciplina(10, 1) == [] assert NoteServ.GetNoteStudentDisciplina(17, 20) == []
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 __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 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 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 TestGetMedieStudentDisciplina (self): ''' Testeaza functia de obtinere a mediei unui student la o anumita disciplina ''' 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.GetMedieStudentDisc(1, 2) == 8 assert NoteServ.GetMedieStudentDisc(1,5) == 8.5 assert NoteServ.GetMedieStudentDisc(2,2) == 8.5
def TestRemoveNoteDisciplina(self): ''' Testeaza functia de stergere a tuturor notelor de la o anumita disciplina ''' 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) NoteServ.RemoveNoteDisciplina(2) assert NoteServ.GetNote() == [nota2, nota4] NoteServ.RemoveNoteDisciplina(5) assert NoteServ.GetNote() == []
def TestRemoveNoteStudent(self): ''' Testeaza functia de stergere a tuturor notelor 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) NoteServ.RemoveNoteStudent(1) assert NoteServ.GetNote() == [nota6, nota7] NoteServ.RemoveNoteStudent(2) assert NoteServ.GetNote() == []
def TestLt (self): ''' Testeaza functia de stabilire a unei note mai mici decat alta ''' assert Nota(1,2,8) < Nota (5,6,8.1) assert Nota(1,1,10) > Nota (1,1,9.9)
def TestStr (self): ''' Testeaza functia de conversie in string a unei nota ''' n = Nota (1,1,10) assert str (n) == '10'
def TestEq (self): ''' Testeaza functia de egalitate intre doua note ''' assert Nota(1, 1, 10) != Nota (2, 5, 10) assert Nota(1, 1, 5) == Nota (1, 1, 7)
def TestInit(self): ''' Testeaza functiile de initializare, get-urile si set-urile a unei note ''' n = Nota (1, 2, 9.5) assert n.GetIdsNota() == 1 assert n.GetIddNota() == 2 assert n.GetNota() == 9.5 n.SetIddNota(4) assert n.GetIddNota() == 4 n.SetIdsNota(10) assert n.GetIdsNota() == 10 n.SetNota(7.4) assert n.GetNota() == 7.4