Bash script for playground updated

This commit is contained in:
Hizenberg469
2024-12-01 23:04:18 +05:30
parent b46c486580
commit 4ff34765fc
2 changed files with 104 additions and 26 deletions

View File

@@ -1,11 +1,32 @@
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Provide the limit of stress testing"
echo "$0 'test case limit'"
echo "$0 -1 (for unlimited)"
exit 1
fi
# if [ $# -ne 1 ]; then
# echo "Provide the limit of stress testing"
# echo "$0 'test case limit'"
# echo "$0 -1 (for unlimited)"
# echo "OPTIONAL: $0 -n (for running with bruteforce)"
# exit 1
# fi
limit=0
flag=true
while getopts l:nh param; do
case $param in
l)
limit=$OPTARG
;;
n)
flag=false
;;
h)
echo "Provide the limit of stress testing"
echo "$0 'test case limit'"
echo "$0 -1 (for unlimited)"
echo "OPTIONAL: $0 -n (for running with bruteforce)"
exit 0
;;
esac
done
#Required tools
SOLUTION=build/solution
@@ -24,24 +45,34 @@ pass_count=0
while (( 1 ))
do
./generator > $TESTCASE_FILE
./SOLUTION < $TESTCASE_FILE > $OUTPUT_FILE
./BRUTEFORCE < $TESTCASE_FILE > $CORRECT_ANSWER_FILE
./$GENERATOR $(($pass_count+1)) > $TESTCASE_FILE
./$SOLUTION < $TESTCASE_FILE > $OUTPUT_FILE
if diff -q -Z $OUTPUT_FILE $CORRECT_ANSWER_FILE >> /dev/null; then
echo -e "\033[0;31mTest #$(($pass_count+1)): FAIL\033[0m"
if $flag ; then
./$BRUTEFORCE < $TESTCASE_FILE > $CORRECT_ANSWER_FILE
if diff -q -Z $OUTPUT_FILE $CORRECT_ANSWER_FILE >> /dev/null; then
echo -e "\033[0;31mTest #$(($pass_count+1)): FAIL\033[0m"
echo "Test case:"
cat $TESTCASE_FILE
echo "Your output:"
cat $OUTPUT_FILE
echo "Correct output:"
cat $CORRECT_ANSWER_FILE
break
fi
echo -e "\033[0;32mPassed test: #$(($pass_count+1))\033[0m"
else
echo -e "Test #$(($pass_count+1)):"
echo "Test case:"
cat $TESTCASE_FILE
echo "Your output:"
cat $OUTPUT_FILE
echo "Correct output:"
cat $CORRECT_ANSWER_FILE
break
fi
echo -e "\033[0;32mPassed test: #$(($pass_count+1))\033[0m"
if [ $1 -ne -1 ] || [ $pass_count -lt $1 ]; then
let pass_count++
if [ $limit -ne -1 ] && [ $pass_count -ge $limit ]; then
break
fi
done