something

This commit is contained in:
djonker 2023-03-01 17:42:12 +01:00
parent 2b8a0803cf
commit 5a5847e7ee

106
test.sh
View File

@ -28,7 +28,7 @@ checkfile()
if [ $? -ne $2 ] if [ $? -ne $2 ]
then then
printf "\e[1;31mMakefile does not create $1\e[0;00m\n" printf "\e[1;31mMakefile does not create $1\e[0;00m\n"
rm -rf tests/files rm -rf tmp
exit 1 exit 1
fi fi
} }
@ -116,7 +116,7 @@ countsilently()
pushswap() pushswap()
{ {
./push_swap $2 > tests/files/output 2>&1 ./push_swap $2 > tmp/output 2>&1
if [ $? -eq $1 ] if [ $? -eq $1 ]
then then
printf "\e[1;32mReturn value OK\e[0;00m\n" printf "\e[1;32mReturn value OK\e[0;00m\n"
@ -128,7 +128,7 @@ pushswap()
checker() checker()
{ {
./push_swap $2 | $CHECKER $2 > tests/files/output 2>&1 ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
if [ $? -eq $1 ] if [ $? -eq $1 ]
then then
printf "\e[1;32mReturn value OK\e[0;00m\n" printf "\e[1;32mReturn value OK\e[0;00m\n"
@ -140,7 +140,7 @@ checker()
onlychecker() onlychecker()
{ {
$CHECKER $2 > tests/files/output 2>&1 $CHECKER $2 > tmp/output 2>&1
if [ $? -eq $1 ] if [ $? -eq $1 ]
then then
printf "\e[1;32mReturn value OK\e[0;00m\n" printf "\e[1;32mReturn value OK\e[0;00m\n"
@ -152,7 +152,7 @@ onlychecker()
checkersilent() checkersilent()
{ {
./push_swap $2 | $CHECKER $2 > tests/files/output 2>&1 ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
if [ $? -ne $1 ] if [ $? -ne $1 ]
then then
printf "\e[1;31mBad Return Value\e[0;00m\n" printf "\e[1;31mBad Return Value\e[0;00m\n"
@ -162,7 +162,7 @@ checkersilent()
checkoutput() checkoutput()
{ {
diff tests/files/output $1 > /dev/null 2>&1 diff tmp/output $1 > /dev/null 2>&1
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then
printf "\e[1;32mOutput OK\e[0;00m\n" printf "\e[1;32mOutput OK\e[0;00m\n"
@ -174,7 +174,7 @@ checkoutput()
checkoutputsilent() checkoutputsilent()
{ {
diff tests/files/output $1 > /dev/null 2>&1 diff tmp/output $1 > /dev/null 2>&1
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
printf "\e[1;31mBad Output\e[0;00m\n" printf "\e[1;31mBad Output\e[0;00m\n"
@ -184,7 +184,7 @@ checkoutputsilent()
checkoutputsupersilent() checkoutputsupersilent()
{ {
diff tests/files/output $1 > /dev/null 2>&1 diff tmp/output $1 > /dev/null 2>&1
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
FAULTS=$(($FAULTS+1)) FAULTS=$(($FAULTS+1))
@ -229,7 +229,7 @@ batchtester()
do do
ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ') ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ')
checkersilent 0 "$ARG" checkersilent 0 "$ARG"
checkoutputsilent tests/files/ok checkoutputsilent tmp/ok
countsilently $3 $4 $5 $6 $7 "$ARG" countsilently $3 $4 $5 $6 $7 "$ARG"
done done
} }
@ -240,7 +240,7 @@ batchchecker()
do do
ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ') ARG=$(for (( i=1;i<=10000;i++ )) do echo $RANDOM $i; done | sort -k1 | cut -d' ' -f2 | head -$1 | tr '\n' ' ')
checkersilent 0 "$ARG" checkersilent 0 "$ARG"
checkoutputsupersilent tests/files/ok checkoutputsupersilent tmp/ok
done done
} }
@ -261,11 +261,11 @@ COUNT4=0
SLEEP=1 SLEEP=1
FAULTS=0 FAULTS=0
CHECKF=0 CHECKF=0
mkdir -p tests/files mkdir -p tmp
touch tests/files/empty touch tmp/empty
echo "Error" > tests/files/error echo "Error" > tmp/error
echo "OK" > tests/files/ok echo "OK" > tmp/ok
echo "KO" > tests/files/ko echo "KO" > tmp/ko
if [ $2 ] if [ $2 ]
then then
if [ $1 -eq 100 ] if [ $1 -eq 100 ]
@ -274,7 +274,7 @@ then
make > /dev/null make > /dev/null
batchtester 100 $2 700 900 1100 1300 1500 batchtester 100 $2 700 900 1100 1300 1500
printresult 700 900 1100 1300 1500 printresult 700 900 1100 1300 1500
rm -rf tests/files rm -rf tmp
exit 0 exit 0
elif [ $1 -eq 500 ] elif [ $1 -eq 500 ]
then then
@ -282,11 +282,11 @@ then
make > /dev/null make > /dev/null
batchtester 500 $2 5500 7000 8500 10000 11500 batchtester 500 $2 5500 7000 8500 10000 11500
printresult 5500 7000 8500 10000 11500 printresult 5500 7000 8500 10000 11500
rm -rf tests/files rm -rf tmp
exit 0 exit 0
else 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" 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 tests/files rm -rf tmp
exit 1 exit 1
fi fi
fi fi
@ -345,74 +345,74 @@ sleep $SLEEP
# Test 4 # Test 4
printf "\e[1;36mTest 4 Running push_swap with non numeric value\e[0;00m\n" printf "\e[1;36mTest 4 Running push_swap with non numeric value\e[0;00m\n"
pushswap 1 "a" pushswap 1 "a"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 5 # Test 5
printf "\e[1;36mTest 5 Running push_swap with hidden non numeric value begin\e[0;00m\n" printf "\e[1;36mTest 5 Running push_swap with hidden non numeric value begin\e[0;00m\n"
pushswap 1 "a1234" pushswap 1 "a1234"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 6 # Test 6
printf "\e[1;36mTest 6 Running push_swap with hidden non numeric value middle\e[0;00m\n" printf "\e[1;36mTest 6 Running push_swap with hidden non numeric value middle\e[0;00m\n"
pushswap 1 "12/34" pushswap 1 "12/34"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 7 # Test 7
printf "\e[1;36mTest 7 Running push_swap with hidden non numeric value end\e[0;00m\n" printf "\e[1;36mTest 7 Running push_swap with hidden non numeric value end\e[0;00m\n"
pushswap 1 "1234-" pushswap 1 "1234-"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 8 # Test 8
printf "\e[1;36mTest 8 Running push_swap with duplicate number\e[0;00m\n" 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" pushswap 1 "1 2 3 4 5 6 7 1"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 9 # Test 9
printf "\e[1;36mTest 9 Running push_swap with max int + 1\e[0;00m\n" 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" pushswap 1 "1 2 3 4 5 6 7 8 9 2147483648"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 10 # Test 10
printf "\e[1;36mTest 10 Running push_swap with min int - 1\e[0;00m\n" 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" pushswap 1 "-2147483649 1 2 3 4 5 6 7 8 9"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 11 # Test 11
printf "\e[1;36mTest 11 Running push_swap without arguments\e[0;00m\n" printf "\e[1;36mTest 11 Running push_swap without arguments\e[0;00m\n"
pushswap 0 pushswap 0
checkoutput tests/files/empty checkoutput tmp/empty
sleep $SLEEP sleep $SLEEP
# Test 12 # Test 12
printf "\e[1;36mTest 12 Running push_swap with one number\e[0;00m\n" printf "\e[1;36mTest 12 Running push_swap with one number\e[0;00m\n"
pushswap 0 "42" pushswap 0 "42"
checkoutput tests/files/empty checkoutput tmp/empty
sleep $SLEEP sleep $SLEEP
# Test 13 # Test 13
printf "\e[1;36mTest 13 Running push_swap with numbers in order\e[0;00m\n" 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" pushswap 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
checkoutput tests/files/empty checkoutput tmp/empty
sleep $SLEEP sleep $SLEEP
# Test 14 # Test 14
printf "\e[1;36mTest 14 Running push_swap against checker with 2 1 0\e[0;00m\n" printf "\e[1;36mTest 14 Running push_swap against checker with 2 1 0\e[0;00m\n"
checker 0 "2 1 0" checker 0 "2 1 0"
checkoutput tests/files/ok checkoutput tmp/ok
count 2 3 3 3 3 "2 1 0" count 2 3 3 3 3 "2 1 0"
sleep $SLEEP sleep $SLEEP
# Test 15 # Test 15
printf "\e[1;36mTest 15 Running push_swap against checker with 1 5 2 4 3\e[0;00m\n" 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" checker 0 "1 5 2 4 3"
checkoutput tests/files/ok checkoutput tmp/ok
count 7 8 9 10 12 "1 5 2 4 3" count 7 8 9 10 12 "1 5 2 4 3"
sleep $SLEEP sleep $SLEEP
@ -445,12 +445,12 @@ then
then then
printf "\e[1;35mBut we got no errors, Congratulations\e[0;00m\n" printf "\e[1;35mBut we got no errors, Congratulations\e[0;00m\n"
make fclean > /dev/null make fclean > /dev/null
rm -rf tests/files rm -rf tmp
exit 0 exit 0
else else
printf "\e[1;31mAnd we got $FAULTS errors\nSo that's a bummer\e[0;00m\n" printf "\e[1;31mAnd we got $FAULTS errors\nSo that's a bummer\e[0;00m\n"
make fclean > /dev/null make fclean > /dev/null
rm -rf tests/files rm -rf tmp
exit 1 exit 1
fi fi
fi fi
@ -474,126 +474,126 @@ sleep $SLEEP
# Test 21 # Test 21
printf "\e[1;36mTest 21 Running checker with non numeric value\e[0;00m\n" printf "\e[1;36mTest 21 Running checker with non numeric value\e[0;00m\n"
onlychecker 1 "a" onlychecker 1 "a"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 22 # Test 22
printf "\e[1;36mTest 22 Running checker with hidden non numeric value begin\e[0;00m\n" printf "\e[1;36mTest 22 Running checker with hidden non numeric value begin\e[0;00m\n"
onlychecker 1 "a1234" onlychecker 1 "a1234"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 23 # Test 23
printf "\e[1;36mTest 23 Running checker with hidden non numeric value middle\e[0;00m\n" printf "\e[1;36mTest 23 Running checker with hidden non numeric value middle\e[0;00m\n"
onlychecker 1 "12/34" onlychecker 1 "12/34"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 24 # Test 24
printf "\e[1;36mTest 24 Running checker with hidden non numeric value end\e[0;00m\n" printf "\e[1;36mTest 24 Running checker with hidden non numeric value end\e[0;00m\n"
onlychecker 1 "1234-" onlychecker 1 "1234-"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 25 # Test 25
printf "\e[1;36mTest 25 Running checker with duplicate number\e[0;00m\n" printf "\e[1;36mTest 25 Running checker with duplicate number\e[0;00m\n"
onlychecker 1 "1 2 3 4 5 6 7 1" onlychecker 1 "1 2 3 4 5 6 7 1"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 26 # Test 26
printf "\e[1;36mTest 26 Running checker with max int + 1\e[0;00m\n" 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" onlychecker 1 "1 2 3 4 5 6 7 8 9 2147483648"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 27 # Test 27
printf "\e[1;36mTest 27 Running checker with min int - 1\e[0;00m\n" 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" onlychecker 1 "-2147483649 1 2 3 4 5 6 7 8 9"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 28 # Test 28
printf "\e[1;36mTest 28 Running checker without arguments\e[0;00m\n" printf "\e[1;36mTest 28 Running checker without arguments\e[0;00m\n"
onlychecker 0 onlychecker 0
checkoutput tests/files/empty checkoutput tmp/empty
sleep $SLEEP sleep $SLEEP
# Test 29 # Test 29
printf "\e[1;36mTest 29 Running checker with no stdin\e[0;00m\n" printf "\e[1;36mTest 29 Running checker with no stdin\e[0;00m\n"
printf "Please press CTRL+D (maybe twice)\n" printf "Please press CTRL+D (maybe twice)\n"
onlychecker 0 "42" onlychecker 0 "42"
checkoutput tests/files/ok checkoutput tmp/ok
sleep $SLEEP sleep $SLEEP
# Test 30 # Test 30
printf "\e[1;36mTest 30 Running checker with all possible moves\e[0;00m\n" 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" 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" onlychecker 0 "42 21 420 210"
checkoutput tests/files/ko checkoutput tmp/ko
sleep $SLEEP sleep $SLEEP
# Test 31 # Test 31
printf "\e[1;36mTest 31 Running checker with some impossible moves\e[0;00m\n" 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" printf "Please type pa, pb, sa, sb, ss, ra, rb, rr, rra, rrb, rrr and hit CTRL+D (maybe twice)\n"
onlychecker 0 "42" onlychecker 0 "42"
checkoutput tests/files/ok checkoutput tmp/ok
sleep $SLEEP sleep $SLEEP
# Test 32 # Test 32
printf "\e[1;36mTest 32 Running checker invalid stdin\e[0;00m\n" 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" printf "Please type br and press enter Do Not hit CTRL+D\n"
onlychecker 1 "42" onlychecker 1 "42"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 33 # Test 33
printf "\e[1;36mTest 33 Running checker invalid stdin space before\e[0;00m\n" 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" printf "Please type ' sa' and press enter Do Not hit CTRL+D\n"
onlychecker 1 "42" onlychecker 1 "42"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 34 # Test 34
printf "\e[1;36mTest 34 Running checker invalid stdin space after\e[0;00m\n" 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" printf "Please type 'sa ' and press enter Do Not hit CTRL+D\n"
onlychecker 1 "42" onlychecker 1 "42"
checkoutput tests/files/error checkoutput tmp/error
sleep $SLEEP sleep $SLEEP
# Test 35 # 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 "\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" 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" onlychecker 0 "0 9 1 8 2 7 3 6 4 5"
checkoutput tests/files/ko checkoutput tmp/ko
sleep $SLEEP sleep $SLEEP
# Test 36 # 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 "\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" printf "Please type sa, ra, rra and hit CTRL+D (maybe twice)\n"
onlychecker 0 "32 -65 12 83 55 23 54 53 16" onlychecker 0 "32 -65 12 83 55 23 54 53 16"
checkoutput tests/files/ko checkoutput tmp/ko
sleep $SLEEP sleep $SLEEP
# Test 37 # Test 37
printf "\e[1;36mTest 37 Running checker with numbers 1 - 20 in order\e[0;00m\n" 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" 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" onlychecker 0 "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
checkoutput tests/files/ok checkoutput tmp/ok
sleep $SLEEP sleep $SLEEP
# Test 38 # Test 38
printf "\e[1;36mTest 38 Running checker with valid input 0 9 1 8 2\e[0;00m\n" 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" 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" onlychecker 0 "0 9 1 8 2"
checkoutput tests/files/ok checkoutput tmp/ok
sleep $SLEEP sleep $SLEEP
# Test 39 # Test 39
printf "\e[1;36mTest 39 Running checker with valid input a little harder\e[0;00m\n" 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" printf "Please type rra, rra and hit CTRL+D (maybe twice)\n"
onlychecker 0 "12345 23456 34567 45678 56789 67890 -98765 -87654" onlychecker 0 "12345 23456 34567 45678 56789 67890 -98765 -87654"
checkoutput tests/files/ok checkoutput tmp/ok
sleep $SLEEP sleep $SLEEP
# Test 40 # Test 40
@ -616,9 +616,9 @@ then
else else
printf "\e[1;31mwe got $FAULTS errors\nSo that's a bummer\e[0;00m\n" printf "\e[1;31mwe got $FAULTS errors\nSo that's a bummer\e[0;00m\n"
make fclean > /dev/null make fclean > /dev/null
rm -rf tests/files rm -rf tmp
exit 1 exit 1
fi fi
make fclean > /dev/null make fclean > /dev/null
rm -rf tests/files rm -rf tmp
exit 0 exit 0