-
Notifications
You must be signed in to change notification settings - Fork 0
/
testinette.sh
executable file
·208 lines (191 loc) · 5.4 KB
/
testinette.sh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/sh
numbers=""
spinner="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
delay=0.1
#fonctions
generate_unique_random()
{
local num
while true; do
num=$((1 + RANDOM % 1000000))
if [[ ! " ${numbers[*]} " =~ " $num " ]]; then
numbers+="$num "
break
fi
done
}
generate()
{
for ((i=0; i<count; i++)); do
generate_unique_random
done
}
loading_animation()
{
local string=$1
while true; do
for char in $(echo "$spinner" | grep -o .); do
printf "\r\033[96m$char $string\033[0m"
sleep $delay
done
done
}
# scrypt beggening
echo "\033[94m╔════════════════════════════════════════════════════════════════════════╗\033[0m"
echo "\033[94m║\033[0m \033[95mWelcome to \033[0m\033[32;4mTestinette\033[0m \033[95m, by ilyanar 🌸\033[0m \033[94m ║\033[0m"
echo "\033[94m╚════════════════════════════════════════════════════════════════════════╝\033[0m\n"
sleep 0.1
# check push_swap file
(loading_animation "checking files.") &
loading_pid=$!
sleep 1
if ! [ -e "./push_swap" ]; then
printf "\033[1A\033[K"
printf "\n \033[31mpush_swap file does not exist.\033[0m"
kill -TERM "$loading_pid"
disown "$loading_pid"
wait "$loading_pid"
exit
fi
kill -TERM "$loading_pid"
disown "$loading_pid"
wait "$loading_pid"
echo "\033[1A\033[K"
#
#
#
printf "\033[3;1;95mDo you want random numbers?\033[0m \033[32m<y/n>\033[0m \033[95m: \033[0m"
read random
echo "\033[2A\033[K"
if [[ "$random" != "y" && "$random" != "n" ]]
then
printf "\033[31mBad format.\033[0m"
exit
fi
printf "\033[3;1;95mwhich checker do you want to use?\033[0m \033[32m<1=original/2=bonus>\033[0m \033[95;1m: \033[0m"
read check
echo "\033[1A\033[K"
echo "\033[2A\033[K"
if [[ "$check" != "1" && "$check" != "2" ]]
then
printf "\033[31mBad format.\033[0m"
exit
fi
if ! [ -e "./checker" ]; then
if [ "$check" != "1" ]; then
printf "\033[1A\033[K"
printf "\n\033[31mchecker file does not exist.\033[0m"
exit
fi
fi
#
# check if files existe
if ! [ -e "./push_swap" ]; then
printf "\033[31mBad format.\033[0m"
exit
fi
#
# grep the random numbers
if [ "$random" == "n" ]
then
echo "\033[94m════════════\033[0m\033[95mARGUMENTS\033[0m\033[94m════════════"
printf "\033[95mARG = \033[0m"
read numbers
(loading_animation "running push_swap...") &
loading_pid=$!
echo "\033[94m════════════\033[0m\033[95mTIME\033[0m\033[94m════════════"
sleep 1
LINE=$(time ./push_swap $numbers | wc -l)
kill -TERM "$loading_pid"
disown "$loading_pid"
wait "$loading_pid"
printf "\033[2A\033[K"
elif [ "$random" == "y" ]
then
printf "\033[3;1;95mHow many numbers you want : \033[0m"
read count
echo "\033[1A\033[K"
echo "\033[2A\033[K"
if ! [[ "$count" =~ ^[0-9]+$ ]]; then
printf "\033[31mBad format.\033[0m"
exit
fi
generate
(loading_animation "running push_swap...") &
loading_pid=$!
echo "\n\033[94m════════════\033[0m\033[95mTIME\033[0m\033[94m════════════"
sleep 0.5
LINE=$(time ./push_swap $numbers | wc -l)
echo "\033[1A\033[K"
kill -TERM "$loading_pid"
disown "$loading_pid"
wait "$loading_pid"
printf "\033[2A\033[K"
else
echo "\033[31mError bad format.\033[0m"
exit
fi
#
# the checker
if [ "$check" == "2" ]
then
CHECK=$(./push_swap $numbers | ./checker $numbers)
else
CHECK=$(./push_swap $numbers | ./srcs/checker_Mac $numbers)
fi
#
# grep the time
echo "\033[94m════════════\033[0m\033[95mOPERATIONS\033[0m\033[94m════════════\033[0m"
echo "\033[92m"$LINE"\033[0m \033[32minstructions with $count numbers\033[0m"
echo "\033[94m══════════════════════════════════\033[0m\n"
#
# check for checker
if [ "$CHECK" == "OK" ]
then
echo "✅ \033[95mChecker say : \033[0m[\033[32mOK\033[0m]\033[95m, Good job ;)\033[0m"
elif [ "$CHECK" == "KO" ]
then
echo "Checker say : ❌ [\033[31mKO\033[0m], Retry it :("
elif [ "$CHECK" == "Error" ]
then
echo "\033[95mChecker say : \033[0m⛔️ \033[31;4mError\033[0m"
else
echo "$CHECK bad format"
fi
echo ""
#
# print the stacks
echo "\033[94m════════════════════════\033[0m"
printf "\033[95mDo you want print the stack A and B?\033[0m \033[92m<y/n>\033[95m : \033[0m"
read prints
ARCH=$(sysctl -a | grep Intel)
if [ "$(./push_swap $numbers)" == "Error" ]
then
printf "\033[92mError\033[0m\n"
elif [ "$prints" == "y" ]
then
if [ ! "$ARCH" ]
then
./push_swap $numbers | ./srcs/print_stack $numbers
else
./push_swap $numbers | ./srcs/print_mac_intel $numbers
fi
fi
#
# print the instructions
echo "\033[94m════════════════════════\033[0m"
printf "\033[95mWant to see the instructions?\033[0m \033[92m<y/n>\033[95m : \033[0m"
read intr
if [ "$(./push_swap $numbers)" == "Error" ]
then
printf "\033[92mError\033[0m\n"
elif [ "$intr" == "y" ]
then
./push_swap $numbers
fi
#
#end
#
echo "\033[94m════════════════════════\033[0m"
echo "\n\033[90mEND\033[0m"
exit