Skip to content

Instantly share code, notes, and snippets.

@adamjezek98
Last active November 5, 2018 22:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamjezek98/73ec47fe6410e1ba80ed898bde1c4307 to your computer and use it in GitHub Desktop.
Save adamjezek98/73ec47fe6410e1ba80ed898bde1c4307 to your computer and use it in GitHub Desktop.
#/bin/bash
DIR=$1
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[1;34m'
ORANGE='\033[1;33m'
NC='\033[0m' # No Color
rm -f "$DIR"/main.exe
gcc -Wall -pedantic $DIR/main.c -o $DIR/main.exe
if [ ! -f $DIR/main.exe ]; then
echo "Compilled file does not exists!"
exit
fi
oldTIMEFORMAT=TIMEFORMAT
TIMEFORMAT="%R"
echo -e "=====${BLUE}TESTING $DIR${NC}====="
for testInput in $DIR/testdata/*_in.txt; do
testFile=${testInput/$DIR\/testdata\//}
echo -e -n ">>>${ORANGE}Test ${testFile/_in.txt/}${NC} - "
time ($DIR/main.exe < $testInput > $DIR/out.txt) 2>runtime
runtime=" ${BLUE}($(cat runtime) s)${NC}"
DIFF=$(diff ${testInput/in/out} $DIR/out.txt)
if [ "$DIFF" == '' ]; then
echo -e " ${GREEN}OK${NC} $runtime"
else
echo -e "${RED}FAILED${NC}$runtime"
echo -e "===============${BLUE}DIFF${NC}================"
echo $DIFF
echo -e "===============${BLUE}INPUT${NC}==============="
cat $testInput
echo -e "==============${BLUE}OUTPUT${NC}==============="
cat $DIR/out.txt
echo -e "==========${BLUE}EXPECTED OUTPUT${NC}=========="
cat ${testInput/in/out}
echo "===================================="
fi
done
TIMEFORMAT=oldTIMEFORMAT
rm runtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment