예제 #1
0
 def test_validareNota(self):
     validNota = ValidatorNota()
     id_nota = 0
     stud = Student(3,"Mircea Augustin")
     disc = Disciplina(2,"Analiza","Berinde Stefan")
     val_nota = 9.5
     nota = Nota(id_nota,stud,disc,val_nota)
     validNota.valideaza_nota(nota)
     nota_gresita = Nota(-1,stud,disc,10.3)
     try:
         validNota.valideaza_nota(nota_gresita)
         assert False
     except ValidError as ve:
         assert str(ve) == ("Id nota invalid! Valoare nota invalida!")
예제 #2
0
 def test_func(self):
     repoStud = RepositoryStud()
     srvNota = ServiceNota(RepositoryNota(),ValidatorNota(),repoStud,ValidatorStudent(),RepositoryDisc(),ValidatorDisciplina())
     note_disc = [["nutu",5],["andrei",10],["aandrei",4.5],["nutu",7],["cosmin",10]]
     srvNota.sort_by_nume_stud(note_disc)
     assert note_disc == [["aandrei",4.5],["andrei",10],["cosmin",10],["nutu",7],["nutu",5]]
     note_disc2 = []
     srvNota.sort_by_nume_stud(note_disc2)
     assert note_disc2 == []
     
     note_disc3 = [["nutu",5],["cosmin",10],["andrei",10],["aandrei",4.5],["nutu",7]]
     srvNota.sort_by_nota(note_disc3)
     assert note_disc3 == [["andrei",10],["cosmin",10],["nutu",7],["nutu",5],["aandrei",4.5]]
     note_disc4 = []
     srvNota.sort_by_nota(note_disc4)
     assert note_disc4 == []
     
     s1 = Student(1,"Chef Scarlatescu")
     s2 = Student(2,"Chef Dumitrescu")
     s3 = Student(5,"Turturica Dorin")
     repoStud.adauga_stud(s1)
     repoStud.adauga_stud(s2)
     repoStud.adauga_stud(Student(3,"Messi"))
     repoStud.adauga_stud(Student(4,"Ronaldo"))
     repoStud.adauga_stud(s3)
     repoStud.adauga_stud(Student(6,"a"))
     repoStud.adauga_stud(Student(7,"b"))
     repoStud.adauga_stud(Student(8,"c"))
     repoStud.adauga_stud(Student(9,"d"))
     repoStud.adauga_stud(Student(10,"e"))
     studenti = repoStud.get_studenti()
     d1 = Disciplina(1,"Analiza","Berinde")
     d2 = Disciplina(2,"Algebra","Mo2")
     d3 = Disciplina(4,"ASC","Vancea")
     note = [Nota(1,s1,d1,9.95),Nota(2,s2,d2,5),Nota(3,s2,d1,9.80),Nota(4,s2,d1,7),Nota(6,s1,d3,9),Nota(7,s3,d1,10)]
     medii = srvNota.get_lista_nume_si_medie(studenti,note)
     assert abs(medii[0][1]-9.475) < 0.001
     assert abs(medii[1][1]-7.2666) < 0.1
     assert abs(medii[4][1]-10) < 0.001
     assert abs(medii[2][1]-0) < 0.001
     
     
     
     
예제 #3
0
 def __ex_valori_note(self,repoNota):
     id_disc = 1
     disc = Disciplina(id_disc,"Analiza","Berinde")
     disc2 = Disciplina(3,"ASC","Vancea")
     disc3 = Disciplina(4,"LC","Pop")
     repoNota.adauga_nota(Nota(1,Student(1,"nutu"),disc,5))
     repoNota.adauga_nota(Nota(10,Student(7,"bologneze"),disc2,9))
     repoNota.adauga_nota(Nota(2,Student(2,"andrei"),disc,10))
     repoNota.adauga_nota(Nota(5,Student(4,"aandrei"),disc,4.5))
     repoNota.adauga_nota(Nota(8,Student(2,"andrei"),disc2,8.6))
     repoNota.adauga_nota(Nota(3,Student(2,"andrei"),disc3,1))
     repoNota.adauga_nota(Nota(9,Student(1,"nutu"),disc,7))
예제 #4
0
 def test_domeniuNota(self):
     id_nota = 0
     id_stud = 3
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud,nume_stud)
     id_disc = 2
     nume_disc = "Analiza"
     nume_prof = "Berinde Stefan"
     disc = Disciplina(id_disc,nume_disc,nume_prof)
     val_nota = 9.5
     nota = Nota(id_nota,stud,disc,val_nota)
     assert nota.get_id_nota() == id_nota
     assert nota.get_stud() == stud
     assert nota.get_disc() == disc
     assert abs(nota.get_val_nota() - val_nota) < 0.0001
     nota2 = Nota(id_nota,Student(0,"a"),Disciplina(0,"a","a"),5.4)
     assert nota == nota2
예제 #5
0
 def __load_note(self):
     """
     metoda care incarca toate notele din fisier
     date de intrare:-
     date de iesire:-
     exceptii:-
     """
     with open(self.__file, "r") as fn:
         for line in fn:
             atr_nota = line.split(",")
             for i in range(len(atr_nota)):
                 atr_nota[i] = atr_nota[i].strip()
             atr_nota[0] = int(atr_nota[0])
             atr_nota[1] = int(atr_nota[1])
             atr_nota[3] = int(atr_nota[3])
             atr_nota[6] = float(atr_nota[6])
             nota = Nota(atr_nota[0], Student(atr_nota[1], atr_nota[2]),
                         Disciplina(atr_nota[3], atr_nota[4], atr_nota[5]),
                         atr_nota[6])
             self._note.append(nota)
예제 #6
0
 def setUp(self):
     self.__repoNota = RepositoryNotaFile("test_unit_lista_note.txt")
     self.__repoNota.adauga_nota(Nota(0,Student(0,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),10))
     self.__repoNota.adauga_nota(Nota(1,Student(1,"Chef Dumitrescu"),Disciplina(1,"Algebra","Modoi"),4.5))
     self.__repoNota.adauga_nota(Nota(3,Student(0,"Chef Scarlatescu"),Disciplina(1,"Algebra","Modoi"),8.55))
예제 #7
0
 def test_sterge_get_nota(self):
     self.__repoNota.sterge_nota(1)
     self.assertEqual(self.__repoNota.get_note(),[Nota(0,Student(0,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),10),Nota(3,Student(0,"Chef Scarlatescu"),Disciplina(1,"Algebra","Modoi"),8.55)])
     self.assertRaisesRegex(RepoError,"Nota inexistenta!",self.__repoNota.sterge_nota,99)
     self.__repoNota.sterge_note()
     self.assertEqual(len(self.__repoNota),0)
예제 #8
0
 def test_modifica_cauta_nota(self):
     self.__repoNota.modifica_nota(Nota(3,Student(5,"Gicu Camataru"),Disciplina(5,"Sport","Nicu Camataru"),1))
     self.assertEqual(self.__repoNota.cauta_nota(3).get_stud(),Student(5,"Gicu Camataru"))
     self.assertRaisesRegex(RepoError,"Nota inexistenta!",self.__repoNota.modifica_nota,Nota(99,Student(5,"Gicu Camataru"),Disciplina(5,"Sport","Nicu Camataru"),1))
     self.assertRaisesRegex(RepoError,"Nota inexistenta!",self.__repoNota.cauta_nota,99)
예제 #9
0
 def test_modifica_stud_note(self):
     self.__repoNota.modifica_stud_note(Student(0,"Chef Bontea"))
     note = [Nota(0,Student(0,"Chef Bontea"),Disciplina(0,"Analiza","Berinde"),10), Nota(1,Student(1,"Chef Dumitrescu"),Disciplina(1,"Algebra","Modoi"),4.5), Nota(3,Student(0,"Chef Bontea"),Disciplina(1,"Algebra","Modoi"),8.55)]
     self.assertEqual(self.__repoNota.get_note(),note)
     self.__repoNota.modifica_stud_note(Student(99,"a"))
     self.assertEqual(self.__repoNota.get_note(),note) 
예제 #10
0
 def test_repoNotaFile(self,file,file2):
     repoNotaF = RepositoryNotaFile(file)
     repoNotaF2 = RepositoryNotaFile(file2)
     note = repoNotaF2.get_note()
     assert abs(note[0].get_val_nota()-9.95) < 0.001
     repoNotaF.set_note(note)
     #daca pun cele 5 valori din fisierul "valori" ca sa verific load
     assert len(repoNotaF) == 6
     id_nota = 1
     nota_cautata = repoNotaF.cauta_nota(id_nota)
     assert abs(nota_cautata.get_val_nota()-9.95) < 0.001
     
     id_nota2 = 9
     stud2 = Student(3,"Messi")
     disc2 = Disciplina(5,"Sport","Prof Sport")
     val_nota2 = 10
     nota2 = Nota(id_nota2,stud2,disc2,val_nota2)
     repoNotaF.adauga_nota(nota2) # 9,3,Messi,5,Sport,Prof Sport
     assert len(repoNotaF) == 1+6
     id_nota = 0
     stud = Student(3,"Messi")
     disc = Disciplina(2,"Analiza","Berinde Stefan")
     val_nota = 9.5
     nota = Nota(id_nota,stud,disc,val_nota)
     repoNotaF.adauga_nota(nota)
     assert len(repoNotaF) == 2+6
     try:
         repoNotaF.adauga_nota(nota)
         assert False
     except RepoError as re:
         assert str(re) == "Nota existenta!"
     assert len(repoNotaF) == 2+6
     try:
         repoNotaF.adauga_nota(Nota(1,Student(99,"a"),Disciplina(99,"a","a"),10))
         assert False
     except RepoError as re:
         assert str(re) == "Nota existenta!"
     stud2 = Student(11,"Andrei George")
     nota_modif = Nota(id_nota,stud2,disc,10)
     repoNotaF.modifica_nota(nota_modif)
     nota_modif_gr = Nota(id_nota+99,stud2,disc,4)
     try:
         repoNotaF.modifica_nota(nota_modif_gr)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     gasit = repoNotaF.cauta_nota(id_nota)
     assert gasit == nota_modif
     try:
         repoNotaF.cauta_nota(id_nota+99)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     tot = repoNotaF.get_note()
     assert len(tot) == 2+6
     try:
         repoNotaF.sterge_nota(id_nota+99)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     repoNotaF.sterge_nota(id_nota)
     assert len(repoNotaF) == 1+6
     try:
         repoNotaF.sterge_nota(id_nota)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
         
         
     """
     test get toate notele de la o disciplina
     """      
     disc = Disciplina(1,"a","a")
     note_disc = repoNotaF.get_note_by_disc(disc)
     assert note_disc == [["Chef Scarlatescu",9.95],["Chef Dumitrescu",9.8],["Messi",7.474]]
     disc2 = Disciplina(99,"a","a")
     note_disc2 = repoNotaF.get_note_by_disc(disc2)
     assert note_disc2 == []
     
     """
     test sterge note de la stud
     """
     id_stud = 2
     repoNotaF.sterge_note_stud(id_stud)
     assert len(repoNotaF) == 5
     id_stud2 = 99
     repoNotaF.sterge_note_stud(id_stud2)
     assert len(repoNotaF) == 5
     id_stud3 = 3
     repoNotaF.sterge_note_stud(id_stud3)
     assert len(repoNotaF) == 3
 
 
     """
     test sterge note de la disc
     """
     assert len(repoNotaF) == 3
     id_disc = 2
     repoNotaF.sterge_note_disc(id_disc)
     assert len(repoNotaF) == 1
     id_disc2 = 99
     repoNotaF.sterge_note_disc(id_disc2)
     assert len(repoNotaF) == 1
예제 #11
0
 def test_append_nota(self):
     self.__repoNota.adauga_nota(Nota(2,Student(3,"Gicu Camataru"),Disciplina(4,"Sport","Gicu Necamataru"),10))
     repoNota2 = RepositoryNotaFile("test_unit_lista_note.txt")
     self.assertEqual(len(repoNota2), 4)
예제 #12
0
 def test_modifica_cauta_nota(self):
     self.__srvNota.modifica_nota(3,1,0,2.5)
     self.assertEqual(self.__srvNota.cauta_nota(3),Nota(3,Student(1,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),2.5))
     self.assertRaisesRegex(RepoError,"Nota inexistenta!",self.__srvNota.modifica_nota,99,2,1,10)
     self.assertRaisesRegex(RepoError,"Nota inexistenta!",self.__srvNota.cauta_nota,99)
예제 #13
0
 def test_adaugare_len_nota(self):
     self.assertEqual(len(self.__repoNota),3)
     self.assertRaisesRegex(RepoError,"Nota existenta!",self.__repoNota.adauga_nota,Nota(3,Student(0,"Chef Scarlatescu"),Disciplina(1,"Algebra","Modoi"),8.55))
     self.assertEqual(len(self.__repoNota),3)
예제 #14
0
 def test_repoNota(self):
     repoNota = RepositoryNota()
     id_nota = 0
     stud = Student(3,"Mircea Augustin")
     disc = Disciplina(2,"Analiza","Berinde Stefan")
     val_nota = 9.5
     nota = Nota(id_nota,stud,disc,val_nota)
     repoNota.adauga_nota(nota)
     assert len(repoNota) == 1
     try:
         repoNota.adauga_nota(nota)
         assert False
     except RepoError as re:
         assert str(re) == "Nota existenta!"
     assert len(repoNota) == 1
     stud2 = Student(2,"Andrei George")
     nota_modif = Nota(id_nota,stud2,disc,10)
     repoNota.modifica_nota(nota_modif)
     nota_modif_gr = Nota(id_nota+5,stud2,disc,4)
     try:
         repoNota.modifica_nota(nota_modif_gr)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     gasit = repoNota.cauta_nota(id_nota)
     assert gasit == nota_modif
     try:
         repoNota.cauta_nota(id_nota+5)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     tot = repoNota.get_note()
     assert len(tot) == 1
     try:
         repoNota.sterge_nota(id_nota+5)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
     repoNota.sterge_nota(id_nota)
     assert len(repoNota) == 0
     try:
         repoNota.sterge_nota(id_nota)
         assert False
     except RepoError as re:
         assert str(re) == "Nota inexistenta!"
         
         
     """
     test get toate notele de la o disciplina
     """      
     self.__ex_valori_note(repoNota)
     disc = Disciplina(1,"Analiza","Berinde")
     note_disc = repoNota.get_note_by_disc(disc)
     assert note_disc == [["nutu",5],["andrei",10],["aandrei",4.5],["nutu",7]]
     disc2 = Disciplina(5,"Sport","HabarNam")
     note_disc2 = repoNota.get_note_by_disc(disc2)
     assert note_disc2 == []
     
     """
     test modifica note de la stud
     """
     stud_modif = Student(2,"andrei")
     repoNota.modifica_stud_note(stud_modif)
     tot_note = repoNota.get_note()
     assert tot_note[2].get_stud() == stud_modif
     assert tot_note[4].get_stud() == stud_modif
     assert tot_note[5].get_stud() == stud_modif
     
     
     """
     test modifica note de la disc
     """
     disc_modif = Disciplina(3,"TIC","Amanoae")
     repoNota.modifica_disc_note(disc_modif)
     tot_note = repoNota.get_note()
     assert tot_note[1].get_disc() == disc_modif
     assert tot_note[4].get_disc() == disc_modif
     
     
     """
     test sterge note de la stud
     """
     id_stud = 2
     repoNota.sterge_note_stud(id_stud)
     assert len(repoNota) == 4
     id_stud2 = 7
     repoNota.sterge_note_stud(id_stud2)
     assert len(repoNota) == 3
     id_stud3 = 99
     repoNota.sterge_note_stud(id_stud3)
     assert len(repoNota) == 3
     
     
     """
     test sterge note de la stud
     """
     repoNota.sterge_note()
     self.__ex_valori_note(repoNota)
     assert len(repoNota) == 7
     id_disc = 1
     repoNota.sterge_note_disc(id_disc)
     assert len(repoNota) == 3
     id_disc2 = 10
     repoNota.sterge_note_disc(id_disc2)
     assert len(repoNota) == 3
     id_disc3 = 3
     repoNota.sterge_note_disc(id_disc3)
     assert len(repoNota) == 1
     id_disc4 = 4
     repoNota.sterge_note_disc(id_disc4)
     assert len(repoNota) == 0
예제 #15
0
 def test_sterge_note_disc(self):
     self.__repoNota.sterge_note_disc(1)
     note = [Nota(0,Student(0,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),10)]
     self.assertEqual(self.__repoNota.get_note(),note)
     self.__repoNota.sterge_note_disc(99)
     self.assertEqual(self.__repoNota.get_note(),note)
예제 #16
0
 def test_sterge_note_stud(self):
     self.__repoNota.sterge_note_stud(0)
     note = [Nota(1,Student(1,"Chef Dumitrescu"),Disciplina(1,"Algebra","Modoi"),4.5)]
     self.assertEqual(self.__repoNota.get_note(),note)
     self.__repoNota.sterge_note_stud(99)
     self.assertEqual(self.__repoNota.get_note(),note)
예제 #17
0
 def test_modifica_disc_note(self):
     self.__repoNota.modifica_disc_note(Disciplina(1,"Logica","Pop"))
     note = [Nota(0,Student(0,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),10), Nota(1,Student(1,"Chef Dumitrescu"),Disciplina(1,"Logica","Pop"),4.5), Nota(3,Student(0,"Chef Scarlatescu"),Disciplina(1,"Logica","Pop"),8.55)]
     self.assertEqual(self.__repoNota.get_note(),note)
     self.__repoNota.modifica_disc_note(Disciplina(99,"a","a"))
     self.assertEqual(self.__repoNota.get_note(),note)
예제 #18
0
 def test_load_note(self):
     repoNota2 = RepositoryNotaFile("test_unit_lista_note.txt")
     self.assertEqual(repoNota2.get_note(), [Nota(0,Student(0,"Chef Scarlatescu"),Disciplina(0,"Analiza","Berinde"),10), Nota(1,Student(1,"Chef Dumitrescu"),Disciplina(1,"Algebra","Modoi"),4.5), Nota(3,Student(0,"Chef Scarlatescu"),Disciplina(1,"Algebra","Modoi"),8.55) ] )
예제 #19
0
 def test_domain_validator(self):
     """
     test domeniu pt student
     """
     id_stud = 1
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud,nume_stud)
     self.assertEqual(stud.get_id_stud(),id_stud)
     self.assertEqual(stud.get_nume_stud(),nume_stud)
     self.assertEqual(str(stud),"1 | Mircea Augustin")
     stud2 = Student(id_stud,"Horatiu Murdar")
     self.assertEqual(stud,stud2)
     """
     test validator student
     """
     validStud = ValidatorStudent()
     stud = Student(1,"Caine Rau")
     validStud.valideaza_stud(stud)
     stud2 = Student(-1,"")
     self.assertRaisesRegex(ValidError,"Id student invalid!Nume student invalid!",validStud.valideaza_stud,stud2)
     """
     test domeniu pt disc
     """
     id_disc = 1
     nume_disc = "Analiza"
     nume_prof = "Berinde Stefan"
     disc = Disciplina(id_disc,nume_disc,nume_prof)
     self.assertEqual(disc.get_id_disc(),id_disc)
     self.assertEqual(disc.get_nume_disc(),nume_disc)
     self.assertEqual(disc.get_nume_prof(),nume_prof)
     self.assertEqual(str(disc),"1 | Analiza | Berinde Stefan")
     disc2 = Disciplina(id_disc,"Logica","Pop")
     self.assertEqual(disc,disc2)
     """
     test validare disc
     """
     validDisc = ValidatorDisciplina()
     id_disc = 1
     nume_disc = "Analiza"
     nume_prof = "Berinde Stefan"
     disc = Disciplina(id_disc,nume_disc,nume_prof)
     validDisc.valideaza_disc(disc)
     disc_gresit = Disciplina(-1,"","")
     self.assertRaisesRegex(ValidError,"Id disciplina invalid!Nume disciplina invalid!Nume profesor invalid!",validDisc.valideaza_disc,disc_gresit)
     """
     test domeniu pt note
     """
     id_nota = 0
     id_stud = 3
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud,nume_stud)
     id_disc = 2
     nume_disc = "Analiza"
     nume_prof = "Berinde Stefan"
     disc = Disciplina(id_disc,nume_disc,nume_prof)
     val_nota = 9.5
     nota = Nota(id_nota,stud,disc,val_nota)
     self.assertEqual(nota.get_id_nota(),id_nota)
     self.assertEqual(nota.get_stud(),stud)
     self.assertEqual(nota.get_disc(),disc)
     self.assertEqual(nota.get_val_nota(),val_nota)
     nota2 = Nota(id_nota,Student(0,"a"),Disciplina(0,"a","a"),5.4)
     self.assertEqual(nota,nota2)
     """
     test validare pt note - BlackBox
     """
     validNota = ValidatorNota()
     stud = Student(0,"a")
     disc = Disciplina(0,"a","a")
     validNota.valideaza_nota(Nota(3,Student(3,"Chef Scarlatescu"),Disciplina(2,"Analiza","Berinde Stefan"),5.4))
     validNota.valideaza_nota(Nota(0,Student(-1,"a"),Disciplina(0,"","a"),1))
     validNota.valideaza_nota(Nota(0,stud,disc,10))
     self.assertRaisesRegex(ValidError,"Id nota invalid! Valoare nota invalida!",validNota.valideaza_nota, Nota(-1,stud,disc,0.9) )
     self.assertRaisesRegex(ValidError,"Id nota invalid! Valoare nota invalida!",validNota.valideaza_nota, Nota(-50,stud,disc,0) )
     self.assertRaisesRegex(ValidError,"Valoare nota invalida!",validNota.valideaza_nota, Nota(0,stud,disc,-1) )
     self.assertRaisesRegex(ValidError,"Valoare nota invalida!",validNota.valideaza_nota, Nota(0,stud,disc,10.1) )
     self.assertRaisesRegex(ValidError,"Valoare nota invalida!",validNota.valideaza_nota, Nota(0,stud,disc,50) )