836 lines
19 KiB
Bash
Executable File
836 lines
19 KiB
Bash
Executable File
# **************************************************************************** #
|
|
# #
|
|
# .--. _ #
|
|
# test.sh |o_o || | #
|
|
# |:_/ || |_ _ ___ __ #
|
|
# By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / #
|
|
# (| | )|_| |_| |> < #
|
|
# Created: 2023/02/20 12:46:17 by houtworm /'\_ _/`\__|\__,_/_/\_\ #
|
|
# Updated: 2023/03/09 18:58:35 by djonker \___)=(___/ #
|
|
# #
|
|
# **************************************************************************** #
|
|
|
|
#!/bin/bash
|
|
|
|
checkchecker()
|
|
{
|
|
ls $1 > /dev/null 2>&1
|
|
if [ $? -ne $2 ]
|
|
then
|
|
printf "\e[1;31mchecker $OS is missing from $1\e[0;00m\n"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
checkfile()
|
|
{
|
|
ls $1 2> /dev/null | grep $1 > /dev/null
|
|
if [ $? -ne $2 ]
|
|
then
|
|
printf "\e[1;31mMakefile does not create $1\e[0;00m\n"
|
|
rm -rf tmp
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
searchobj()
|
|
{
|
|
FILES=$(find . -name '*.o' | wc -l)
|
|
if [ $1 -eq 0 ]
|
|
then
|
|
if [ $FILES -ne 0 ]
|
|
then
|
|
printf "\e[1;31mObject files found after clean\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
fi
|
|
if [ $1 -eq 1 ]
|
|
then
|
|
if [ $FILES -eq 0 ]
|
|
then
|
|
printf "\e[1;31mObject files not found after make\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
fi
|
|
}
|
|
|
|
checkrule()
|
|
{
|
|
make $1 > /dev/null 2>&1
|
|
if [ $? -eq 2 ]
|
|
then
|
|
printf "\e[1;31mMissing rule $1\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
count()
|
|
{
|
|
MOVES=$(./push_swap $6 | wc -l)
|
|
if [ $MOVES -gt $5 ]
|
|
then
|
|
printf "\e[1;31mIt took $MOVES moves which is way too much\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
elif [ $MOVES -gt $4 ]
|
|
then
|
|
printf "\e[1;33mIt took $MOVES moves which is barely acceptable\e[0;00m\n"
|
|
elif [ $MOVES -gt $3 ]
|
|
then
|
|
printf "\e[1;36mIt took $MOVES moves which is okay... I guess\e[0;00m\n"
|
|
elif [ $MOVES -gt $2 ]
|
|
then
|
|
printf "\e[1;34mIt took $MOVES moves which is still pretty slow\e[0;00m\n"
|
|
elif [ $MOVES -gt $1 ]
|
|
then
|
|
printf "\e[1;35mIt took $MOVES moves which is better than the average\e[0;00m\n"
|
|
else
|
|
printf "\e[1;32mIt took $MOVES moves which is perfect\e[0;00m\n"
|
|
fi
|
|
}
|
|
|
|
countsilently()
|
|
{
|
|
MOVES=$(./push_swap $6 | wc -l)
|
|
if [ $MOVES -gt $5 ]
|
|
then
|
|
COUNT0=$(($COUNT0+1))
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
if [ $MOVES -gt $4 ]
|
|
then
|
|
COUNT1=$(($COUNT1+1))
|
|
fi
|
|
if [ $MOVES -gt $3 ]
|
|
then
|
|
COUNT2=$(($COUNT2+1))
|
|
fi
|
|
if [ $MOVES -gt $2 ]
|
|
then
|
|
COUNT3=$(($COUNT3+1))
|
|
fi
|
|
if [ $MOVES -gt $1 ]
|
|
then
|
|
COUNT4=$(($COUNT4+1))
|
|
fi
|
|
}
|
|
|
|
pushswap()
|
|
{
|
|
./push_swap $2 > tmp/output 2>&1
|
|
if [ $? -eq $1 ]
|
|
then
|
|
printf "\e[1;32mReturn value OK\e[0;00m\n"
|
|
else
|
|
printf "\e[1;31mBad Return Value\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
pushswapvalgrind()
|
|
{
|
|
CURFUNERR=0
|
|
valgrind --leak-check=full ./push_swap $1 2> tmp/memorycheck > /dev/null
|
|
cat tmp/memorycheck | grep indirectly | grep "[123456789] bytes" > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n"
|
|
cat tmp/memorycheck
|
|
FAULTS=$(($FAULTS+1))
|
|
CURFUNERR=1
|
|
fi
|
|
if [ $CURFUNERR -eq 0 ]
|
|
then
|
|
cat tmp/memorycheck | grep definitely | grep "[123456789] bytes" > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n"
|
|
cat tmp/memorycheck
|
|
FAULTS=$(($FAULTS+1))
|
|
CURFUNERR=1
|
|
fi
|
|
fi
|
|
if [ $CURFUNERR -eq 0 ]
|
|
then
|
|
printf "\e[1;32mValgrind OK\e[0;00m\n"
|
|
fi
|
|
}
|
|
|
|
checker()
|
|
{
|
|
./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
|
|
if [ $? -eq $1 ]
|
|
then
|
|
printf "\e[1;32mReturn value OK\e[0;00m\n"
|
|
else
|
|
printf "\e[1;31mBad Return Value\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
onlychecker()
|
|
{
|
|
$CHECKER $2 > tmp/output 2>&1
|
|
if [ $? -eq $1 ]
|
|
then
|
|
printf "\e[1;32mReturn value OK\e[0;00m\n"
|
|
else
|
|
printf "\e[1;31mBad Return Value\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
onlycheckervalgrind()
|
|
{
|
|
CURFUNERR=0
|
|
valgrind --leak-check=full $CHECKER $1 2> tmp/memorycheck > /dev/null
|
|
cat tmp/memorycheck | grep indirectly | grep "[123456789] bytes" > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n"
|
|
cat tmp/memorycheck
|
|
FAULTS=$(($FAULTS+1))
|
|
CURFUNERR=1
|
|
fi
|
|
if [ $CURFUNERR -eq 0 ]
|
|
then
|
|
cat tmp/memorycheck | grep definitely | grep "[123456789] bytes" > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
printf "\e[1;31mLeaks Valgrind $1\e[0;00m\n"
|
|
cat tmp/memorycheck
|
|
FAULTS=$(($FAULTS+1))
|
|
CURFUNERR=1
|
|
fi
|
|
fi
|
|
if [ $CURFUNERR -eq 0 ]
|
|
then
|
|
printf "\e[1;32mValgrind OK\e[0;00m\n"
|
|
fi
|
|
}
|
|
|
|
checkersilent()
|
|
{
|
|
./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
|
|
if [ $? -ne $1 ]
|
|
then
|
|
printf "\e[1;31mBad Return Value\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
checkoutput()
|
|
{
|
|
diff tmp/output $1 > /dev/null 2>&1
|
|
if [ $? -eq 0 ]
|
|
then
|
|
printf "\e[1;32mOutput OK\e[0;00m\n"
|
|
else
|
|
printf "\e[1;31mBad Output\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
checkoutputsilent()
|
|
{
|
|
diff tmp/output $1 > /dev/null 2>&1
|
|
if [ $? -ne 0 ]
|
|
then
|
|
printf "\e[1;31mBad Output\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
fi
|
|
}
|
|
|
|
checkoutputsupersilent()
|
|
{
|
|
diff tmp/output $1 > /dev/null 2>&1
|
|
if [ $? -ne 0 ]
|
|
then
|
|
FAULTS=$(($FAULTS+1))
|
|
CHECKF=$(($CHECKF+1))
|
|
fi
|
|
}
|
|
|
|
printresult()
|
|
{
|
|
if [ $COUNT0 -gt 0 ]
|
|
then
|
|
printf "\e[1;31mYou went over $5 $COUNT0 times which is way too much\e[0;00m\n"
|
|
fi
|
|
if [ $COUNT1 -gt 0 ]
|
|
then
|
|
printf "\e[1;33mYou went over $4 $COUNT1 times which is barely acceptable\e[0;00m\n"
|
|
fi
|
|
if [ $COUNT2 -gt 0 ]
|
|
then
|
|
printf "\e[1;36mYou went over $3 $COUNT2 times which is okay... I guess\e[0;00m\n"
|
|
fi
|
|
if [ $COUNT3 -gt 0 ]
|
|
then
|
|
printf "\e[1;34mYou went over $2 $COUNT3 times which is still pretty slow\e[0;00m\n"
|
|
fi
|
|
if [ $COUNT4 -gt 0 ]
|
|
then
|
|
printf "\e[1;35mYou went over $1 $COUNT4 times which is better than the average\e[0;00m\n"
|
|
else
|
|
printf "\e[1;32mNone of the attempts went over $1 moves which is perfect\e[0;00m\n"
|
|
fi
|
|
COUNT0=0
|
|
COUNT1=0
|
|
COUNT2=0
|
|
COUNT3=0
|
|
COUNT4=0
|
|
}
|
|
|
|
batchtester()
|
|
{
|
|
for (( i=1;i<=$2;i++ ))
|
|
do
|
|
ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ')
|
|
checkersilent 0 "$ARG"
|
|
checkoutputsilent tmp/ok
|
|
countsilently $3 $4 $5 $6 $7 "$ARG"
|
|
done
|
|
}
|
|
|
|
batchchecker()
|
|
{
|
|
for (( i=1;i<=$2;i++ ))
|
|
do
|
|
ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ')
|
|
checkersilent 0 "$ARG"
|
|
checkoutputsupersilent tmp/ok
|
|
done
|
|
}
|
|
|
|
OS=$(uname -s)
|
|
if [ $OS == "Linux" ]
|
|
then
|
|
CHECKER=./tests/lchecker
|
|
else
|
|
CHECKER=./tests/mchecker
|
|
fi
|
|
checkchecker $CHECKER 0
|
|
chmod +x $CHECKER
|
|
COUNT0=0
|
|
COUNT1=0
|
|
COUNT2=0
|
|
COUNT3=0
|
|
COUNT4=0
|
|
SLEEP=1
|
|
FAULTS=0
|
|
CHECKF=0
|
|
VALGRIND=0
|
|
which valgrind > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
VALGRIND=1
|
|
else
|
|
printf "\n\e[1;31mInstall Valgrind for extra Memory Checking\e[0;00m\n"
|
|
fi
|
|
mkdir -p tmp
|
|
touch tmp/empty
|
|
echo "Error" > tmp/error
|
|
echo "OK" > tmp/ok
|
|
echo "KO" > tmp/ko
|
|
if [ $2 ]
|
|
then
|
|
if [ $1 -eq 100 ]
|
|
then
|
|
printf "\e[1;36mRunning push_swap against checker with 100 random values $2 times\e[0;00m\n"
|
|
make > /dev/null
|
|
batchtester 100 $2 700 900 1100 1300 1500
|
|
printresult 700 900 1100 1300 1500
|
|
rm -rf tmp
|
|
exit 0
|
|
elif [ $1 -eq 500 ]
|
|
then
|
|
printf "\e[1;36mRunning push_swap against checker with 500 random values $2 times\e[0;00m\n"
|
|
make > /dev/null
|
|
batchtester 500 $2 5500 7000 8500 10000 11500
|
|
printresult 5500 7000 8500 10000 11500
|
|
rm -rf tmp
|
|
exit 0
|
|
else
|
|
printf "\e[1;31mRun the test in one of the following ways\n./test\n./test.sh [SLEEPTIME]\n./test 100 [ITERATIONS]\n./test 500 [ITERATIONS]\e[0;00m\n"
|
|
rm -rf tmp
|
|
exit 1
|
|
fi
|
|
fi
|
|
if [ $1 ]
|
|
then
|
|
SLEEP=$1
|
|
fi
|
|
|
|
|
|
# Test 1
|
|
printf "\e[1;36mTest 1 Checking all source with Norminette\e[0;00m\n"
|
|
norminette > /dev/null 2>&1
|
|
if [ $? -eq 1 ]
|
|
then
|
|
printf "\e[1;31mYour shit is not norm!\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
else
|
|
printf "\e[1;32mNorminette OK\e[0;00m\n"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 2
|
|
printf "\e[1;36mTest 2 Checking all mandatory rules Makefile\e[0;00m\n"
|
|
checkrule all
|
|
checkfile push_swap 0
|
|
searchobj 1
|
|
checkrule clean
|
|
searchobj 0
|
|
checkrule push_swap
|
|
checkfile push_swap 0
|
|
searchobj 1
|
|
checkrule fclean
|
|
searchobj 0
|
|
checkfile push_swap 1
|
|
checkrule re
|
|
searchobj 1
|
|
checkfile push_swap 0
|
|
if [ $FAULTS -eq 0 ]
|
|
then
|
|
printf "\e[1;32mMakefile rules OK\e[0;00m\n"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 3
|
|
printf "\e[1;36mTest 3 Checking if Makefile relinks\e[0;00m\n"
|
|
make 2>&1 | grep Nothing
|
|
if [ $? -eq 1 ]
|
|
then
|
|
printf "\e[1;31mMakefile relinks\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
else
|
|
printf "\e[1;32mMakefile OK\e[0;00m\n"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 4
|
|
printf "\e[1;36mTest 4 Running push_swap with non numeric value\e[0;00m\n"
|
|
pushswap 1 "a"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind 1 "a"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 5
|
|
printf "\e[1;36mTest 5 Running push_swap with hidden non numeric value begin\e[0;00m\n"
|
|
pushswap 1 "a1234"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "a1234"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 6
|
|
printf "\e[1;36mTest 6 Running push_swap with hidden non numeric value middle\e[0;00m\n"
|
|
pushswap 1 "12/34"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "12/34"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 7
|
|
printf "\e[1;36mTest 7 Running push_swap with hidden non numeric value end\e[0;00m\n"
|
|
pushswap 1 "1234-"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1234-"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 8
|
|
printf "\e[1;36mTest 8 Running push_swap with duplicate number\e[0;00m\n"
|
|
pushswap 1 "-"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1 2 3 4 5 6 7 1"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 8
|
|
printf "\e[1;36mTest 8 Running push_swap with duplicate number\e[0;00m\n"
|
|
pushswap 1 "1 2 3 4 5 6 7 1"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1 2 3 4 5 6 7 1"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 9
|
|
printf "\e[1;36mTest 9 Running push_swap with max int + 1\e[0;00m\n"
|
|
pushswap 1 "1 2 3 4 5 6 7 8 9 2147483648"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1 2 3 4 5 6 7 8 9 2147483648"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 10
|
|
printf "\e[1;36mTest 10 Running push_swap with min int - 1\e[0;00m\n"
|
|
pushswap 1 "-2147483649 1 2 3 4 5 6 7 8 9"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "-2147483649 1 2 3 4 5 6 7 8 9"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 11
|
|
printf "\e[1;36mTest 11 Running push_swap without arguments\e[0;00m\n"
|
|
pushswap 0
|
|
checkoutput tmp/empty
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 12
|
|
printf "\e[1;36mTest 12 Running push_swap with one number\e[0;00m\n"
|
|
pushswap 0 "42"
|
|
checkoutput tmp/empty
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 13
|
|
printf "\e[1;36mTest 13 Running push_swap with numbers in order\e[0;00m\n"
|
|
pushswap 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
|
|
checkoutput tmp/empty
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 14
|
|
printf "\e[1;36mTest 14 Running push_swap against checker with 2 1 0\e[0;00m\n"
|
|
checker 0 "2 1 0"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "2 1 0"
|
|
fi
|
|
count 2 3 3 3 3 "2 1 0"
|
|
sleep $SLEEP
|
|
|
|
# Test 15
|
|
printf "\e[1;36mTest 15 Running push_swap against checker with 1 5 2 4 3\e[0;00m\n"
|
|
checker 0 "1 5 2 4 3"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
pushswapvalgrind "1 5 2 4 3"
|
|
fi
|
|
count 7 8 9 10 12 "1 5 2 4 3"
|
|
sleep $SLEEP
|
|
|
|
# Test 16
|
|
printf "\e[1;36mTest 16 Running push_swap against checker with 5 random values 100 times\e[0;00m\n"
|
|
batchtester 5 100 7 8 9 10 12
|
|
printresult 7 8 9 10 12
|
|
sleep $SLEEP
|
|
|
|
# Test 17
|
|
printf "\e[1;36mTest 17 Running push_swap against checker with 100 random values 100 times\e[0;00m\n"
|
|
batchtester 100 100 700 900 1100 1300 1500
|
|
printresult 700 900 1100 1300 1500
|
|
sleep $SLEEP
|
|
|
|
# Test 18
|
|
printf "\e[1;36mTest 18 Running push_swap against checker with 500 random values 100 times\e[0;00m\n"
|
|
batchtester 500 100 5500 7000 8500 10000 11500
|
|
printresult 5500 7000 8500 10000 11500
|
|
sleep $SLEEP
|
|
|
|
# Test 19
|
|
printf "\e[1;36mTest 19 Checking if Makefile bonus rule exists\e[0;00m\n"
|
|
make fclean > /dev/null
|
|
make bonus >/dev/null 2>&1
|
|
if [ $? -eq 2 ]
|
|
then
|
|
printf "\e[1;31mNo bonus? I am a little dissapointed...\e[0;00m\n"
|
|
if [ $FAULTS -eq 0 ]
|
|
then
|
|
printf "\e[1;35mBut we got no errors, Congratulations\e[0;00m\n"
|
|
make fclean > /dev/null
|
|
rm -rf tmp
|
|
exit 0
|
|
else
|
|
printf "\e[1;31mAnd we got $FAULTS errors\nSo that's a bummer\e[0;00m\n"
|
|
make fclean > /dev/null
|
|
rm -rf tmp
|
|
exit 1
|
|
fi
|
|
fi
|
|
checkfile checker 0
|
|
CHECKER=./checker
|
|
printf "\e[1;32mbonus rule OK\e[0;00m\n"
|
|
sleep $SLEEP
|
|
|
|
# Test 20
|
|
printf "\e[1;36mTest 20 Checking if Makefile relinks for bonus\e[0;00m\n"
|
|
make bonus 2>&1 | grep Nothing
|
|
if [ $? -eq 1 ]
|
|
then
|
|
printf "\e[1;31mMakefile relinks on bonus\e[0;00m\n"
|
|
FAULTS=$(($FAULTS+1))
|
|
else
|
|
printf "\e[1;32mMakefile bonus OK\e[0;00m\n"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 21
|
|
printf "\e[1;36mTest 21 Running checker with non numeric value\e[0;00m\n"
|
|
onlychecker 1 "a"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "a"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 22
|
|
printf "\e[1;36mTest 22 Running checker with hidden non numeric value begin\e[0;00m\n"
|
|
onlychecker 1 "a1234"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "a1234"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 23
|
|
printf "\e[1;36mTest 23 Running checker with hidden non numeric value middle\e[0;00m\n"
|
|
onlychecker 1 "12/34"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "12/34"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 24
|
|
printf "\e[1;36mTest 24 Running checker with hidden non numeric value end\e[0;00m\n"
|
|
onlychecker 1 "1234-"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "1324-"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 25
|
|
printf "\e[1;36mTest 25 Running checker with duplicate number\e[0;00m\n"
|
|
onlychecker 1 "1 2 3 4 5 6 7 1"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "1 2 3 4 5 6 7 1"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 26
|
|
printf "\e[1;36mTest 26 Running checker with max int + 1\e[0;00m\n"
|
|
onlychecker 1 "1 2 3 4 5 6 7 8 9 2147483648"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "1 2 3 4 5 6 7 8 9 2147483648"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 27
|
|
printf "\e[1;36mTest 27 Running checker with min int - 1\e[0;00m\n"
|
|
onlychecker 1 "-2147483649 1 2 3 4 5 6 7 8 9"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind "-2147483649 1 2 3 4 5 6 7 8 9"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 28
|
|
printf "\e[1;36mTest 28 Running checker without arguments\e[0;00m\n"
|
|
onlychecker 0
|
|
checkoutput tmp/empty
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
onlycheckervalgrind
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 29
|
|
printf "\e[1;36mTest 29 Running checker with no stdin\e[0;00m\n"
|
|
printf "Please press CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "42"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please press CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 30
|
|
printf "\e[1;36mTest 30 Running checker with all possible moves\e[0;00m\n"
|
|
printf "Please type pb, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr, pa and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "42 21 420 210"
|
|
checkoutput tmp/ko
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type pb, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr, pa and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 31
|
|
printf "\e[1;36mTest 31 Running checker with some impossible moves\e[0;00m\n"
|
|
printf "Please type pa, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "42"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type pa, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 32
|
|
printf "\e[1;36mTest 32 Running checker invalid stdin\e[0;00m\n"
|
|
printf "Please type br and press enter Do Not hit CTRL+D\n"
|
|
onlychecker 1 "42"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type br and press enter Do Not hit CTRL+D\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 33
|
|
printf "\e[1;36mTest 33 Running checker invalid stdin space before\e[0;00m\n"
|
|
printf "Please type ' sa' and press enter Do Not hit CTRL+D\n"
|
|
onlychecker 1 "42"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type ' sa' and press enter Do Not hit CTRL+D\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 34
|
|
printf "\e[1;36mTest 34 Running checker invalid stdin space after\e[0;00m\n"
|
|
printf "Please type 'sa ' and press enter Do Not hit CTRL+D\n"
|
|
onlychecker 1 "42"
|
|
checkoutput tmp/error
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type 'sa ' and press enter Do Not hit CTRL+D\n"
|
|
onlycheckervalgrind "42"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 35
|
|
printf "\e[1;36mTest 35 Running checker with wrong stdin 0 9 1 8 2 7 3 6 4 5\e[0;00m\n"
|
|
printf "Please type sa, pb, rrr and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "0 9 1 8 2 7 3 6 4 5"
|
|
checkoutput tmp/ko
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type sa, pb, rrr and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "0 9 1 8 2 7 3 6 4 5"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 36
|
|
printf "\e[1;36mTest 36 Running checker with wrong stdin 32 -65 12 83 55 23 54 53 16\e[0;00m\n"
|
|
printf "Please type sa, ra, rra and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "32 -65 12 83 55 23 54 53 16"
|
|
checkoutput tmp/ko
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type sa, ra, rra and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "32 -65 12 83 55 23 54 53 16"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 37
|
|
printf "\e[1;36mTest 37 Running checker with numbers 1 - 20 in order\e[0;00m\n"
|
|
printf "Please hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 38
|
|
printf "\e[1;36mTest 38 Running checker with valid input 0 9 1 8 2\e[0;00m\n"
|
|
printf "Please type pb, ra, pb, ra, sa, ra, pa, pa and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "0 9 1 8 2"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type pb, ra, pb, ra, sa, ra, pa, pa and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "0 9 1 8 2"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 39
|
|
printf "\e[1;36mTest 39 Running checker with valid input a little harder\e[0;00m\n"
|
|
printf "Please type rra, rra and hit CTRL+D (maybe twice)\n"
|
|
onlychecker 0 "12345 23456 34567 45678 56789 67890 -98765 -87654"
|
|
checkoutput tmp/ok
|
|
if [ $VALGRIND -eq 1 ]
|
|
then
|
|
printf "Please type rra, rra and hit CTRL+D (maybe twice)\n"
|
|
onlycheckervalgrind "12345 23456 34567 45678 56789 67890 -98765 -87654"
|
|
fi
|
|
sleep $SLEEP
|
|
|
|
# Test 40
|
|
make > /dev/null
|
|
printf "\e[1;36mTest 40 Running checker with input from push_swap 500 random values 100 times\e[0;00m\n"
|
|
batchchecker 500 100
|
|
if [ $CHECKF -gt 0 ]
|
|
then
|
|
printf "\e[1;31mwe got $CHECKF cases where the output was not OK\e[0;00m\n"
|
|
else
|
|
printf "\e[1;32mBatch test finished with no problems\e[0;00m\n"
|
|
fi
|
|
|
|
sleep $SLEEP
|
|
|
|
# Conclusion
|
|
if [ $FAULTS -eq 0 ]
|
|
then
|
|
printf "\e[1;35mwe got no errors, Congratulations\e[0;00m\n"
|
|
else
|
|
printf "\e[1;31mwe got $FAULTS errors\nSo that's a bummer\e[0;00m\n"
|
|
make fclean > /dev/null
|
|
rm -rf tmp
|
|
exit 1
|
|
fi
|
|
make fclean > /dev/null
|
|
rm -rf tmp
|
|
exit 0
|