This commit is contained in:
Houtworm 2023-03-07 07:26:11 +01:00
parent 4efb5bb06c
commit c407e65992

205
test.sh
View File

@ -1,12 +1,12 @@
# **************************************************************************** # # **************************************************************************** #
# # # #
# .--. _ # # .--. _ #
# test.sh |o_o || | # # test.sh :+: :+: :+: #
# |:_/ || |_ _ ___ __ # # |:_/ || |_ _ ___ __ #
# By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / # # By: houtworm <codam@houtworm.net> // \ \ __| | | \ \/ / #
# (| | )|_| |_| |> < # # (| | )|_| |_| |> < #
# Created: 2023/02/20 12:46:17 by houtworm /'\_ _/`\__|\__,_/_/\_\ # # Created: 2023/02/20 12:46:17 by houtworm /'\_ _/`\__|\__,_/_/\_\ #
# Updated: 2023/03/07 05:33:23 by houtworm \___)=(___/ # # Updated: 2023/03/07 07:19:30 by houtworm ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -126,6 +126,35 @@ pushswap()
fi 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() checker()
{ {
./push_swap $2 | $CHECKER $2 > tmp/output 2>&1 ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
@ -150,6 +179,35 @@ onlychecker()
fi 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() checkersilent()
{ {
./push_swap $2 | $CHECKER $2 > tmp/output 2>&1 ./push_swap $2 | $CHECKER $2 > tmp/output 2>&1
@ -261,6 +319,14 @@ COUNT4=0
SLEEP=1 SLEEP=1
FAULTS=0 FAULTS=0
CHECKF=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 mkdir -p tmp
touch tmp/empty touch tmp/empty
echo "Error" > tmp/error echo "Error" > tmp/error
@ -346,66 +412,110 @@ sleep $SLEEP
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind 1 "a"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "a1234"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "12/34"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "1234-"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "1 2 3 4 5 6 7 1"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "1 2 3 4 5 6 7 8 9 2147483648"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "-2147483649 1 2 3 4 5 6 7 8 9"
fi
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 tmp/empty checkoutput tmp/empty
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind
fi
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 tmp/empty checkoutput tmp/empty
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "42"
fi
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 tmp/empty 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 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 tmp/ok checkoutput tmp/ok
if [ $VALGRIND -eq 1 ]
then
pushswapvalgrind "2 1 0"
fi
count 2 3 3 3 3 "2 1 0" count 2 3 3 3 3 "2 1 0"
sleep $SLEEP sleep $SLEEP
@ -413,6 +523,10 @@ sleep $SLEEP
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 tmp/ok 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" count 7 8 9 10 12 "1 5 2 4 3"
sleep $SLEEP sleep $SLEEP
@ -475,48 +589,80 @@ sleep $SLEEP
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "a"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "a1234"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "12/34"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "1324-"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "1 2 3 4 5 6 7 1"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "1 2 3 4 5 6 7 8 9 2147483648"
fi
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 tmp/error checkoutput tmp/error
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind "-2147483649 1 2 3 4 5 6 7 8 9"
fi
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 tmp/empty checkoutput tmp/empty
if [ $VALGRIND -eq 1 ]
then
onlycheckervalgrind
fi
sleep $SLEEP sleep $SLEEP
# Test 29 # Test 29
@ -524,6 +670,11 @@ 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 tmp/ok checkoutput tmp/ok
if [ $VALGRIND -eq 1 ]
then
printf "Please press CTRL+D (maybe twice)\n"
onlycheckervalgrind "42"
fi
sleep $SLEEP sleep $SLEEP
# Test 30 # Test 30
@ -531,6 +682,11 @@ 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 tmp/ko 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 sleep $SLEEP
# Test 31 # Test 31
@ -538,6 +694,11 @@ 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 tmp/ok 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 sleep $SLEEP
# Test 32 # Test 32
@ -545,6 +706,11 @@ 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 tmp/error 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 sleep $SLEEP
# Test 33 # Test 33
@ -552,6 +718,11 @@ 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 tmp/error 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 sleep $SLEEP
# Test 34 # Test 34
@ -559,6 +730,11 @@ 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 tmp/error 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 sleep $SLEEP
# Test 35 # Test 35
@ -566,6 +742,11 @@ printf "\e[1;36mTest 35 Running checker with wrong stdin 0 9 1 8 2 7 3 6 4 5\e[0
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 tmp/ko 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 sleep $SLEEP
# Test 36 # Test 36
@ -573,6 +754,11 @@ printf "\e[1;36mTest 36 Running checker with wrong stdin 32 -65 12 83 55 23 54 5
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 tmp/ko 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 sleep $SLEEP
# Test 37 # Test 37
@ -580,6 +766,11 @@ 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 tmp/ok 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 sleep $SLEEP
# Test 38 # Test 38
@ -587,6 +778,11 @@ 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 tmp/ok 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 sleep $SLEEP
# Test 39 # Test 39
@ -594,6 +790,11 @@ printf "\e[1;36mTest 39 Running checker with valid input a little harder\e[0;00m
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 tmp/ok 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 sleep $SLEEP
# Test 40 # Test 40