-
Notifications
You must be signed in to change notification settings - Fork 9
/
check.sh
executable file
·91 lines (71 loc) · 2.03 KB
/
check.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
#!/bin/bash
# set -e
# Check if arguments passed are OK
if [ $# != 3 ]
then
echo "Usage: ./check.sh <Program File> <Correct Program File> <Generator File>"
echo "
✳️ Use this script with
1) Original Algorithm Program C++ file
2) Safe & Working Algorithm Program C++ file (Brute Force 🤔)
3) Program which will be used to generate test case - Generator
✳️ Script will generate at most 500 test cases and stop whenever output
of (1) and (2) differ showing both the input & outputs.
"
GCC_VERSION=`g++ --version | head -n1`
echo "NOTE: All files should compile using ${GCC_VERSION}"
exit 0
fi
if [ ! -f "$1" ]; then
echo "Program File '$1' does not exist."
exit 0
fi
if [ ! -f "$2" ]; then
echo "Correct Program File '$2' does not exist."
exit 0
fi
if [ ! -f "$3" ]; then
echo "Generator File '$3' does not exist."
exit 0
fi
HOME_DIR=`pwd`
# Create a new folder with random name to save generated data
TEST_DIR=`uuidgen`
mkdir -p $TEST_DIR
echo "Created folder $TEST_DIR 💿"
removeGeneratedFiles() {
cd $HOME_DIR
rm -rf $TEST_DIR
echo "Deleted folder $TEST_DIR 📀"
exit 0
}
# Set a trap so that we make sure generated files are always deleted
trap removeGeneratedFiles 0
g++ -std=c++17 $1 -o $TEST_DIR/program
g++ -std=c++17 $2 -o $TEST_DIR/safe
g++ -std=c++17 $3 -o $TEST_DIR/generator
cd $TEST_DIR
for i in {1..5000}
do
./generator $i > input.txt
./program < input.txt > output_program.txt
./safe < input.txt > output_safe.txt
DIFF=`diff -b output_program.txt output_safe.txt`
if [ ! -z "${DIFF}" ]
then
echo -e "Wrong Answer on "
echo -e "\n❌ Wrong answer on TEST CASE $i:\n"
cat input.txt
echo -e "\nOutput of $1:\n"
cat output_program.txt
echo -e "\nOutput of $2:\n"
cat output_safe.txt
diff output_program.txt output_safe.txt
cp output_program.txt $HOME_DIR/output_program.txt
cp output_safe.txt $HOME_DIR/output_safe.txt
cp input.txt $HOME_DIR/input.txt
break
fi
echo -n "✅"
done
removeGeneratedFiles