1+ import os
2+ import pandas as pd
3+
4+ # TODO: add import for the function
5+
6+
7+ def test_exercise_1 ():
8+ run_test ("ex1" )
9+
10+ def test_exercise_2 ():
11+ run_test ("ex2" )
12+
13+ def test_exercise_3 ():
14+ run_test ("ex3" )
15+
16+ def run_test (filename :str ):
17+ solution_file = os .path .join (get_res_path (),"solutions" ,f"{ filename } _s.csv" )
18+
19+ input_file = os .path .join (get_res_path (),"inputs" ,f"{ filename } .csv" )
20+ output_file = os .path .join (get_tmp_path (),f"{ filename } _s.csv" )
21+
22+ # TODO: call the function to test
23+
24+ output_df = pd .read_csv (output_file )
25+ solution_df = pd .read_csv (solution_file )
26+
27+ print (f"Output dataframe shape: { output_df .shape } " )
28+ print (f"Solution dataframe shape: { solution_df .shape } " )
29+ if not output_df .shape == solution_df .shape :
30+ print ("Error: dataframe shape are different" )
31+ assert (False )
32+
33+ print ("Output dataframe:" )
34+ print (output_df )
35+ print ("==============================" )
36+
37+ print ("Solution dataframe:" )
38+ print (solution_df )
39+ print ("==============================" )
40+ assert (output_df .equals (solution_df ))
41+
42+ def get_root ():
43+ '''
44+ Get the project root
45+ '''
46+ return os .path .dirname (os .path .dirname (__file__ ))
47+
48+ def get_res_path ():
49+ '''
50+ Get the absoulte path of the tests/res folder
51+ '''
52+ return os .path .join (get_root (),"tests" ,"res" )
53+
54+ def get_tmp_path ():
55+ '''
56+ Get the absoulte path of the tests/.tmp folder.
57+ If it doesn't exist it creates it
58+ '''
59+ tmp_path = os .path .join (get_root (), "tests" , ".tmp" )
60+ if not os .path .exists (tmp_path ):
61+ os .makedirs (tmp_path )
62+ return tmp_path
0 commit comments