diff --git a/.gitignore b/.gitignore index 496ee2c..9605ff6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -.DS_Store \ No newline at end of file +.DS_Store +tests/.tmp +.pytest_cache +.vscode +__pycache__ \ No newline at end of file diff --git a/tests/res/inputs/ex1.csv b/tests/res/inputs/ex1.csv new file mode 100644 index 0000000..a9aed26 --- /dev/null +++ b/tests/res/inputs/ex1.csv @@ -0,0 +1,8 @@ +Task,BCET,WCET,Period,Deadline,Priority +T1,0,1,6,6,1 +T2,3,4,60,60,7 +T3,1,1,10,10,2 +T4,1,2,12,12,3 +T5,1,2,15,15,4 +T6,1,3,20,20,5 +T7,1,4,30,30,6 diff --git a/tests/res/inputs/ex2.csv b/tests/res/inputs/ex2.csv new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/res/inputs/ex2.csv @@ -0,0 +1 @@ + diff --git a/tests/res/inputs/ex3.csv b/tests/res/inputs/ex3.csv new file mode 100644 index 0000000..e69de29 diff --git a/tests/res/solutions/ex1_s.csv b/tests/res/solutions/ex1_s.csv new file mode 100644 index 0000000..82d76d8 --- /dev/null +++ b/tests/res/solutions/ex1_s.csv @@ -0,0 +1,8 @@ +Task,WCRT,Deadline,Status +T1,1.0,6,true +T2,54.0,60,true +T3,2.0,10,true +T4,4.0,12,true +T5,6.0,15,true +T6,10.0,20,true +T7,28.0,30,true diff --git a/tests/res/solutions/ex2_s.csv b/tests/res/solutions/ex2_s.csv new file mode 100644 index 0000000..27cee2c --- /dev/null +++ b/tests/res/solutions/ex2_s.csv @@ -0,0 +1,12 @@ +Task,WCRT,Deadline,Status +T1,1.0,15,true +T2,3.0,20,true +T3,6.0,25,true +T4,10.0,30,true +T5,15.0,50,true +T6,23.0,60,true +T7,37.0,75,true +T8,49.0,100,true +T9,98.0,120,true +T10,197.0,150,false +T11,580.0,300,false diff --git a/tests/res/solutions/ex3_s.csv b/tests/res/solutions/ex3_s.csv new file mode 100644 index 0000000..bd4875b --- /dev/null +++ b/tests/res/solutions/ex3_s.csv @@ -0,0 +1,10 @@ +Task,WCRT,Deadline,Status +T1,3.0,40,true +T2,10.0,80,true +T3,23.0,100,true +T4,44.0,160,true +T5,66.0,200,true +T6,116.0,300,true +T7,148.0,320,true +T8,258.0,400,true +T9,296.0,480,true diff --git a/tests/test_exercises.py b/tests/test_exercises.py new file mode 100644 index 0000000..59ee4ca --- /dev/null +++ b/tests/test_exercises.py @@ -0,0 +1,62 @@ +import os +import pandas as pd + +# TODO: add import for the function + + +def test_exercise_1(): + run_test("ex1") + +def test_exercise_2(): + run_test("ex2") + +def test_exercise_3(): + run_test("ex3") + +def run_test(filename:str): + solution_file = os.path.join(get_res_path(),"solutions",f"{filename}_s.csv") + + input_file = os.path.join(get_res_path(),"inputs",f"{filename}.csv") + output_file = os.path.join(get_tmp_path(),f"{filename}_s.csv") + + # TODO: call the function to test + + output_df = pd.read_csv(output_file) + solution_df = pd.read_csv(solution_file) + + print(f"Output dataframe shape: {output_df.shape}") + print(f"Solution dataframe shape: {solution_df.shape}") + if not output_df.shape == solution_df.shape: + print("Error: dataframe shape are different") + assert(False) + + print("Output dataframe:") + print(output_df) + print("==============================") + + print("Solution dataframe:") + print(solution_df) + print("==============================") + assert(output_df.equals(solution_df)) + +def get_root(): + ''' + Get the project root + ''' + return os.path.dirname(os.path.dirname(__file__)) + +def get_res_path(): + ''' + Get the absoulte path of the tests/res folder + ''' + return os.path.join(get_root(),"tests","res") + +def get_tmp_path(): + ''' + Get the absoulte path of the tests/.tmp folder. + If it doesn't exist it creates it + ''' + tmp_path = os.path.join(get_root(), "tests", ".tmp") + if not os.path.exists(tmp_path): + os.makedirs(tmp_path) + return tmp_path \ No newline at end of file diff --git a/tests/test_main.py b/tests/test_main.py deleted file mode 100644 index 52c2135..0000000 --- a/tests/test_main.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_main(): - assert True \ No newline at end of file