Skip to content

Commit 54eeec8

Browse files
authored
Merge pull request #10 from pierGit7/feature/tests
added tests
2 parents f7c8d3c + 991dff9 commit 54eeec8

9 files changed

Lines changed: 106 additions & 3 deletions

File tree

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
.DS_Store
1+
.DS_Store
2+
tests/.tmp
3+
.pytest_cache
4+
.vscode
5+
__pycache__

tests/res/inputs/ex1.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Task,BCET,WCET,Period,Deadline,Priority
2+
T1,0,1,6,6,1
3+
T2,3,4,60,60,7
4+
T3,1,1,10,10,2
5+
T4,1,2,12,12,3
6+
T5,1,2,15,15,4
7+
T6,1,3,20,20,5
8+
T7,1,4,30,30,6

tests/res/inputs/ex2.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/res/inputs/ex3.csv

Whitespace-only changes.

tests/res/solutions/ex1_s.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Task,WCRT,Deadline,Status
2+
T1,1.0,6,true
3+
T2,54.0,60,true
4+
T3,2.0,10,true
5+
T4,4.0,12,true
6+
T5,6.0,15,true
7+
T6,10.0,20,true
8+
T7,28.0,30,true

tests/res/solutions/ex2_s.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Task,WCRT,Deadline,Status
2+
T1,1.0,15,true
3+
T2,3.0,20,true
4+
T3,6.0,25,true
5+
T4,10.0,30,true
6+
T5,15.0,50,true
7+
T6,23.0,60,true
8+
T7,37.0,75,true
9+
T8,49.0,100,true
10+
T9,98.0,120,true
11+
T10,197.0,150,false
12+
T11,580.0,300,false

tests/res/solutions/ex3_s.csv

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Task,WCRT,Deadline,Status
2+
T1,3.0,40,true
3+
T2,10.0,80,true
4+
T3,23.0,100,true
5+
T4,44.0,160,true
6+
T5,66.0,200,true
7+
T6,116.0,300,true
8+
T7,148.0,320,true
9+
T8,258.0,400,true
10+
T9,296.0,480,true

tests/test_exercises.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

tests/test_main.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)