22import sys
33from pathlib import Path
44
5- def run_cargo ():
5+ def run_cargo_build ():
66 """Compileaza si ruleaza cargo pentru a verifica daca exista erori."""
7- print ("Compiling Rust project... " )
7+ print ("========== Compiling Rust project ========== " )
88 result = subprocess .run (
99 ["cargo" , "build" ],
1010 stdout = subprocess .PIPE ,
@@ -18,7 +18,25 @@ def run_cargo():
1818 print ("Eroare la compilare! Oprire program." )
1919 sys .exit (1 )
2020
21- def run_test (db_file , test_idx ):
21+
22+ def run_cargo_test ():
23+ """Ruleaza testele unitare (pentru Task 1 si Task 2)"""
24+ print ("========== Running Rust unit tests ==========" )
25+ result = subprocess .run (
26+ ["cargo" , "test" ],
27+ stdout = subprocess .PIPE ,
28+ stderr = subprocess .PIPE ,
29+ text = True
30+ )
31+ # Afiseaza warning-uri si erori
32+ print (result .stdout )
33+ print (result .stderr )
34+ if result .returncode != 0 :
35+ print ("Eroare la rularea testelor unitare! Oprire program." )
36+ sys .exit (1 )
37+ return result .stdout
38+
39+ def run_task2_test (db_file , test_idx ):
2240 """Ruleaza un singur test si returneaza True daca trece, False altfel."""
2341 input_file = Path (f"../tests/input/test{ test_idx } .in" )
2442 output_dir = Path ("../tests/output-rust-method" )
@@ -52,19 +70,67 @@ def run_test(db_file, test_idx):
5270 else :
5371 print (f"Test { test_idx } cu { db_file .name } : FAILED" )
5472 return False
73+
5574
56- def main ():
57- run_cargo ()
75+ def test_task2 ():
76+ print ("========== TASK 3 ==========" )
77+ score = 0
5878 db_files = [Path ("../tests/db/small.db" ), Path ("../tests/db/big.db" )]
59- total_score = 0
6079 points_per_test = 3.5
6180 for db_file in db_files :
6281 print (f"\n --- Testare pentru { db_file .name } ---" )
6382 for i in range (1 , 11 ):
64- if run_test (db_file , i ):
65- total_score += points_per_test
83+ if run_task2_test (db_file , i ):
84+ score += points_per_test
85+ print ()
86+ return score
87+
88+ def test_task1 (stdout_result ):
89+ """stdout_result -> rezultatul testelor unitare, rulate cu `cargo test`"""
90+ print ("========== TASK 1 ==========" )
91+ score = 0
92+
93+ print ("Verificare task 1.1 [citire_secretariat]: " , end = '' )
94+ if stdout_result .find ("test_citire_secretariat ... ok" ) >= 0 :
95+ score += 7
96+ print ("OK" )
97+ else :
98+ print ("FAIL" )
99+
100+ print ("Verificare task 1.2 [adauga_student]: " , end = '' )
101+ if stdout_result .find ("test_adauga_student ... ok" ) >= 0 :
102+ score += 3
103+ print ("OK" )
104+ else :
105+ print ("FAIL" )
66106
67- print (f"\n Scor total: { total_score } /70" )
107+ print ()
108+ return score
109+
110+ def test_task3 (stdout_result ):
111+ """stdout_result -> rezultatul testelor unitare, rulate cu `cargo test`"""
112+ print ("========== TASK 1 ==========" )
113+ score = 0
114+
115+ for i in range (1 , 6 ):
116+ print (f"Test with `test{ i } `.db: " , end = '' )
117+ if stdout_result .find (f"test_cripteaza_studenti::case_{ i } ... ok" ) >= 0 :
118+ score += 4
119+ print ("OK" )
120+ else :
121+ print ("FAIL" )
122+ return score
123+
124+
125+
126+ def main ():
127+ run_cargo_build ()
128+ unit_tests_results = run_cargo_test ()
129+ total_score = 0
130+ total_score += test_task1 (unit_tests_results )
131+ total_score += test_task2 ()
132+ total_score += test_task3 (unit_tests_results )
133+ print (f"\n Scor total: { total_score } /100" )
68134
69135if __name__ == '__main__' :
70136 main ()
0 commit comments