-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_python
More file actions
executable file
·125 lines (97 loc) · 2.62 KB
/
run_python
File metadata and controls
executable file
·125 lines (97 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NC=$(tput sgr0)
display_top_message()
{
echo "${NC}Starting Test Suite ${NC} "
}
display_message_start_running_tests()
{
echo "${NC}Running tests ${NC} "
}
display_message_stop_running_tests()
{
echo "${NC}Running tests Done ${NC} "
}
display_message_start_cleaning_tests()
{
echo "${NC}Cleaning tests ${NC} "
}
display_message_stop_cleaning_tests()
{
echo "${NC}Cleaning tests Done ${NC} "
}
display_message_compile_results()
{
echo "${NC}Compiling Results ${NC} "
}
clean_tests()
{
local idx=1
for f in *.cpp;
do
filename="${f%.*}"
rm -f $filename
if [ $? -eq 0 ];
then
printf '%4s %-60s \t %s\n' "$idx" " [ ${YELLOW} Clean ${NC} ] $filename" "[ ${GREEN} OK ${NC} ]"
else
printf '%4s %-60s \t %s\n' "$idx" " [ ${YELLOW} Clean ${NC} ] $filename" "[ ${RED} Failed ${NC} ]"
fi
idx=$((idx+1))
done
}
idx=1
run_tests()
{
for f in $(ls problem*.* | sort -n -t - -k 2);
do
filename="${f%.*}"
extention="${f##*.}"
case $extention in
"py")
exe="${filename}.py"
;;
"cpp")
c++ -o $filename "$filename.cpp" -std=c++11
exe="${filename}"
;;
*)
continue
;;
esac
start_time=$(date +%s.%N)
if [ -f "$filename.in" ];
then
./$exe < "$filename.in" > /dev/null 2>&1
else
./$exe > /dev/null 2>&1
fi
end_time=$(date +%s.%N)
execution_time=$(echo "$end_time - $start_time" | bc)
if [ $? -eq 0 ]; then
printf '%4s %-60s \t %s %4.4s %4s\n' "$idx" " [ ${YELLOW} Executing ${NC} ] $filename" "[ ${GREEN} OK ${NC} ]" "$execution_time" "seconds"
else
printf '%4s %-60s \t %s %4.4s \n' "$idx" " [ ${YELLOW} Executing ${NC} ] $filename" "[ ${RED} Failed ${NC} ]" "na"
fi
idx=$((idx+1))
done
}
pushd Python
# Run Tests
display_message_start_running_tests
total_start_time=$(date +%s.%N)
run_tests
total_end_time=$(date +%s.%N)
#Clean Tests
display_message_start_cleaning_tests
clean_tests
#Compile Results
display_message_compile_results
idx=$((idx-1))
total_execution_time=$(echo "$total_end_time - $total_start_time" | bc)
printf '%-60s \t %s %s\n' " [ ${YELLOW} Finished ${NC} ] Tests $idx .. Execution time" "[ ${GREEN} $total_execution_time ${NC} ]" "seconds"
rm -rf a.out
popd