コード例 #1
0
ファイル: testUndo.py プロジェクト: Threnx33/S-Catalog
 def test_srvUndo(self):
     repoUndo = RepositoryUndo()
     srvUndo = ServiceUndo(repoUndo)
     srvStud = ServiceStudUndo(RepositoryStud(), ValidatorStudent(),
                               repoUndo)
     id_stud = 1
     nume_stud = "Dorin"
     stud = Student(id_stud, nume_stud)
     srvStud.adauga_stud(id_stud, nume_stud)
     id_stud2 = 2
     nume_stud2 = "Dorin2"
     srvStud.adauga_stud(id_stud2, nume_stud2)
     srvUndo.act_undo()
     assert len(srvStud) == 1
     srvUndo.act_undo()
     assert len(srvStud) == 0
     srvUndo.act_redo()
     assert len(srvStud) == 1
     tot = srvStud.get_studenti()
     assert tot == [stud]
     nume_stud_modif = "Dorin3"
     stud_modif = Student(id_stud, nume_stud_modif)
     srvStud.modifica_stud(id_stud, nume_stud_modif)
     srvUndo.act_undo()
     tot2 = srvStud.get_studenti()
     assert tot2 == [stud]
     srvUndo.act_redo()
     tot3 = srvStud.get_studenti()
     assert tot3 == [stud_modif]
コード例 #2
0
 def test_domeniuStud(self):
     id_stud = 1
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud, nume_stud)
     assert stud.get_id_stud() == id_stud
     assert stud.get_nume_stud() == nume_stud
     assert str(stud) == "1 | Mircea Augustin"
     stud2 = Student(id_stud, "Horatiu Murdar")
     assert stud == stud2
コード例 #3
0
 def test_validareStud(self):
     validStud = ValidatorStudent()
     stud = Student(1, "Caine Rau")
     validStud.valideaza_stud(stud)
     stud2 = Student(-1, "")
     try:
         validStud.valideaza_stud(stud2)
         assert False
     except ValidError as ve:
         assert str(ve) == "Id student invalid!Nume student invalid!"
コード例 #4
0
ファイル: testUndo.py プロジェクト: Threnx33/S-Catalog
 def test_repoUndo(self):
     repoUndo = RepositoryUndo()
     try:
         repoUndo.peek()
         assert False
     except RepoError as re:
         assert str(re) == "Undo indisponibil!"
     repoStud = RepositoryStud()
     cmd_undo = repoStud.sterge_stud
     cmd_redo = repoStud.adauga_stud
     id_stud = 1
     nume_stud = "Dorin"
     stud = Student(id_stud, nume_stud)
     actUndo = ActiuneUndo(cmd_undo, cmd_redo, id_stud, stud)
     repoUndo.push(actUndo)
     assert len(repoUndo) == 1
     assert repoUndo.peek() == actUndo
     cmd_undo2 = repoStud.adauga_stud
     cmd_redo2 = repoStud.sterge_stud
     id_stud2 = 2
     nume_stud2 = "Dorin2"
     stud2 = Student(id_stud2, nume_stud2)
     actUndo2 = ActiuneUndo(cmd_undo2, cmd_redo2, stud2, id_stud2)
     repoUndo.push(actUndo2)
     assert len(repoUndo) == 2
     assert repoUndo.peek() == actUndo2
     repoUndo.pop()
     assert len(repoUndo) == 1
     cmd_undo3 = repoStud.modifica_stud
     cmd_redo3 = repoStud.modifica_stud
     id_stud3 = 1
     nume_stud3 = "Dorin3"
     stud3_precedent = Student(id_stud3, nume_stud)
     stud3 = Student(id_stud3, nume_stud3)
     actUndo3 = ActiuneUndo(cmd_undo3, cmd_redo3, stud3_precedent, stud3)
     repoUndo.push(actUndo3)
     assert len(repoUndo) == 2
     assert repoUndo.peek() == actUndo3
     try:
         repoUndo.pull()
         assert False
     except RepoError as re:
         assert str(re) == "Redo indisponibil!"
     repoUndo.pop()
     assert len(repoUndo) == 1
     repoUndo.pop()
     assert len(repoUndo) == 0
     try:
         repoUndo.peek()
         assert False
     except RepoError as re:
         assert str(re) == "Undo indisponibil!"
     repoUndo.pull()
     assert len(repoUndo) == 1
コード例 #5
0
 def test_sterge_get_stud(self):
     self.__srvStud.sterge_stud(1)
     studenti = self.__srvStud.get_studenti()
     self.assertEqual(studenti,[Student(0,"Chef Dumitrescu")])
     self.assertRaisesRegex(RepoError,"Student inexistent!",self.__srvStud.sterge_stud,1)
     self.assertRaisesRegex(RepoError,"Student inexistent!",self.__srvStud.sterge_stud,99)
     self.__srvStud.sterge_studenti()
     self.assertEqual(len(self.__srvStud),0)
コード例 #6
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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
コード例 #7
0
 def setUp(self):
     self.__repoStud = RepositoryStud()
     self.__repoStud.adauga_stud(Student(0,"Chef Dumitrescu"))
     self.__repoStud.adauga_stud(Student(1,"Chef Scarlatescu"))
     self.__repoStud.adauga_stud(Student(2,"Chef Bontea"))
     self.__repoStud.adauga_stud(Student(3,"Chef Dorin"))
     self.__repoDisc = RepositoryDisc()
     self.__repoDisc.adauga_disc(Disciplina(0,"Analiza","Berinde"))
     self.__repoDisc.adauga_disc(Disciplina(1,"Algebra","Mo2"))
     self.__repoDisc.adauga_disc(Disciplina(2,"Logica","Pop"))
     self.__repoNota = RepositoryNota()
     self.__srvNota = ServiceNota( self.__repoNota, ValidatorNota(), self.__repoStud, ValidatorStudent(), self.__repoDisc, ValidatorDisciplina(),)
     self.__srvNota.adauga_nota(0,0,0,10)
     self.__srvNota.adauga_nota(2,0,1,10)
     self.__srvNota.adauga_nota(4,0,2,10)
     self.__srvNota.adauga_nota(1,1,1,4.5)
     self.__srvNota.adauga_nota(3,2,1,7.5)
     self.__srvNota.adauga_nota(5,1,2,9.5)
コード例 #8
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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
     
     
     
     
コード例 #9
0
ファイル: testUndo.py プロジェクト: Threnx33/S-Catalog
 def test_domeniuUndo(self):
     repoStud = RepositoryStud()
     cmd_undo = repoStud.sterge_stud
     cmd_redo = repoStud.adauga_stud
     id_stud = 1
     nume_stud = "Dorin"
     stud = Student(id_stud, nume_stud)
     actUndo = ActiuneUndo(cmd_undo, cmd_redo, id_stud, stud)
     assert actUndo.get_cmd_undo() == cmd_undo
     assert actUndo.get_cmd_redo() == cmd_redo
     assert actUndo.get_entitate_undo() == id_stud
     assert actUndo.get_entitate_redo() == stud
コード例 #10
0
 def test_repoStudFile(self, repoStudF):
     lung_init = len(repoStudF)
     assert lung_init == 6
     self.test_repoStud(repoStudF, lung_init)
     id_stud = 1
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud, nume_stud)
     try:
         repoStudF.adauga_stud(stud)
         assert False
     except RepoError as re:
         assert str(re) == "Student existent!"
     assert len(repoStudF) == lung_init
コード例 #11
0
 def adauga_stud(self, id_stud, nume_stud):
     """
     metoda care adauga student in lista de studenti | sau eroare daca exista deja
     date de intrare:
         stud-studentul pe care vrem sa il aduagam
     date de iesire:-
     date de exceptie:
         RepoError-"Student existent!"
     """
     stud = Student(id_stud, nume_stud)
     self._validStud.valideaza_stud(stud)
     self._repoStud.adauga_stud(stud)
     return stud
コード例 #12
0
 def modifica_stud(self, id_stud, nume_stud_modif):
     """
     metoda care modifica student in lista de studenti dupa id, id-ul ramanand la fel | sau eroare daca nu il gaseste
     date de intrare:
         stud_modif-inlocuitorul studentului pe care vrem sa-l schimbam
     date de iesire:-
     date de exceptie:
         RepoError-"Student inexistent!"
     """
     stud_modif = Student(id_stud, nume_stud_modif)
     self._validStud.valideaza_stud(stud_modif)
     stud_precedent = self._repoStud.modifica_stud(stud_modif)
     return [stud_precedent, stud_modif]
コード例 #13
0
 def cauta_stud(self, id_stud):
     """
     metoda care returneaza un student dupa id in lista de studenti | sau eroare daca nu il gaseste
     date de intrare:
         id_stud-idul studentului pe care il cautam
     date de iesire:
         el-studentul pe care il cautam
     date de exceptie:
         RepoError-"Student inexistent!"
     """
     key_stud = Student(id_stud, "anything")
     self._validStud.valideaza_stud(key_stud)
     return self._repoStud.cauta_stud(id_stud)
コード例 #14
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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))
コード例 #15
0
 def test_repoStud(self, repoStud, lung_init):
     assert len(repoStud) == 0 + lung_init
     id_stud = 0
     nume_stud = "Mircea Augustin"
     stud = Student(id_stud, nume_stud)
     repoStud.adauga_stud(stud)
     assert len(repoStud) == 1 + lung_init
     try:
         repoStud.adauga_stud(stud)
         assert False
     except RepoError as re:
         assert str(re) == "Student existent!"
     gasit = repoStud.cauta_stud(id_stud)
     assert gasit.get_nume_stud() == "Mircea Augustin"
     try:
         repoStud.cauta_stud(id_stud + 99)
         assert False
     except RepoError as re:
         assert str(re) == "Student inexistent!"
     stud_modif = Student(id_stud, "Mirciulica Schimbat")
     repoStud.modifica_stud(stud_modif)
     gasit = repoStud.cauta_stud(id_stud)
     assert gasit.get_nume_stud() == "Mirciulica Schimbat"
     stud_modif_rau = Student(id_stud + 99, "")
     try:
         repoStud.modifica_stud(stud_modif_rau)
         assert False
     except RepoError as re:
         assert str(re) == "Student inexistent!"
     alll = repoStud.get_studenti()
     assert len(alll) == 1 + lung_init
     repoStud.sterge_stud(id_stud)
     assert len(repoStud) == 0 + lung_init
     try:
         repoStud.sterge_stud(id_stud)
         assert False
     except RepoError as re:
         assert str(re) == "Student inexistent!"
コード例 #16
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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!")
コード例 #17
0
 def adauga_studenti_r(self, nr_studenti):
     letters = string.ascii_lowercase
     for i in range(nr_studenti):
         ok = 0
         while ok == 0:
             try:
                 id_stud = random.randint(1, 10000)
                 self._repoStud.cauta_stud(id_stud)
             except RepoError:
                 ok = 1
         nume_stud = ''.join(random.choice(letters) for k in range(15))
         stud = Student(id_stud, nume_stud)
         self._validStud.valideaza_stud(stud)
         self._repoStud.adauga_stud(stud)
コード例 #18
0
 def __load_studenti(self):
     """
     metoda care incarca toti studentii din fisier
     date de intrare:-
     date de iesire:-
     exceptii:-
     """
     with open(self.__file, "r") as fs:
         for line in fs:
             atr_stud = line.split(",")
             for i in range(len(atr_stud)):
                 atr_stud[i] = atr_stud[i].strip()
             atr_stud[0] = int(atr_stud[0])
             stud = Student(atr_stud[0], atr_stud[1])
             self._studenti.append(stud)
コード例 #19
0
ファイル: repositoryNota.py プロジェクト: Threnx33/S-Catalog
 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)
コード例 #20
0
 def setUp(self):
     self.__repoStud = RepositoryStud()
     self.__repoStud.adauga_stud(Student(0,"Chef Dumitrescu"))
     self.__repoStud.adauga_stud(Student(1,"Chef Scarlatescu"))
コード例 #21
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) 
コード例 #22
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)
コード例 #23
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)
コード例 #24
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)
コード例 #25
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))
コード例 #26
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) ] )
コード例 #27
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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
コード例 #28
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)
コード例 #29
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)
コード例 #30
0
ファイル: testeNota.py プロジェクト: Threnx33/S-Catalog
 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