Created
January 5, 2019 00:42
-
-
Save dbyr/0c7c21d95f421b426d35f63d635d726d to your computer and use it in GitHub Desktop.
Revisions
-
David Byrne created this gist
Jan 5, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ #!/bin/bash # this script will run input/output tests for java programs USAGE="Usage: javatest.sh <progpath> <inputs_folder_path> <expected_outputs_folder_path> The names of the input files is expected to be the same as the name of the corresponding expected output files." if [[ $# != 3 ]]; then echo "$USAGE" exit fi PROGRAM=$1 INPUTS=$2 EXPECTED=$3 passed=0 total=$(ls $INPUTS | wc -l) failed_tests="" for file in $(ls $INPUTS); do inputfile="$INPUTS/$file" expectedfile="$EXPECTED/$file" echo "Running test '$file'" output=$(java $PROGRAM $(cat $inputfile)) retcode=$? if [[ $retcode != 0 ]]; then echo "Program returned code $retcode" continue fi if [[ $output == $(cat $expectedfile) ]]; then passed=$((passed+1)) else failed_tests="${failed_tests}Test $file failed.\nGot '$output'\nExpected '$(cat $expectedfile)'\n\n" fi done echo echo echo -e "$failed_tests" echo "$passed of $total tests passed."