forked from UACS210Spring2018/PA2-HashMap-Start
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade.sh
executable file
·135 lines (123 loc) · 3.89 KB
/
grade.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/sh
#
# This grade.sh is specifically for PA2. It calls the PA2main
# with the commands MAX, DEPARTURES, and LIMIT #, where
# the number passed to LIMIT varies.
#
# grade.sh is a shell script that runs the given main class
# on all of the inputs (*.csv files) in the given input directory.
# Does all this by copying the src/*.java files into TestingTemp/
# and running the tests in TestingTemp/.
#
# usage examples:
# ./grade.sh JavaHelloWorld PublicTestCases
# ./grade.sh PA1Main MyTestCases
#
# FIXME: This is not available yet.
# It is also possible to run the script on an individual file:
# ./grade.sh JavaHelloWorld PublicTestCases file1.csv CMD
#
# The assumption is that each main is operating on a given file.
# The input files in the specified input directory will be
# given to the program. Here are the operations performed:
#
# javac JavaHelloWorld.java
# java JavaHelloWorld PublicTestCases/file1.csv MAX
# java JavaHelloWorld PublicTestCases/file1.csv DEPARTURES
# java JavaHelloWorld PublicTestCases/file1.csv LIMIT 1
# java JavaHelloWorld PublicTestCases/file1.csv LIMIT 2
# java JavaHelloWorld PublicTestCases/file1.csv LIMIT 3
# java JavaHelloWorld PublicTestCases/file2.csv MAX
# java JavaHelloWorld PublicTestCases/file2.csv DEPARTURES
# java JavaHelloWorld PublicTestCases/file2.csv LIMIT 1
# java JavaHelloWorld PublicTestCases/file2.csv LIMIT 2
# java JavaHelloWorld PublicTestCases/file2.csv LIMIT 3
# ...
#
# Another assumption is that all of the source files are in the
# default package and are in the src/ subdirectory.
#
#***************************
# Parameter $1 will be the PA2 command
# If the PA2 command is LIMIT, then will grab
# parameter $2 for number to limit things to.
# Global variables $infile, $inputdir,
# and $TESTS_PASSED are read and modified.
runCmdNDiff() {
base_in=$(basename $infile .csv)
# runs current test and captures output
# and also finds the expected output
if [ "$1" = "LIMIT" ]
then
java $main $infile LIMIT $2 > out
expected_file="../$inputdir/cmdLIMIT_$2-$base_in.out"
else
java $main $infile $1 > out
expected_file="../$inputdir/cmd$1-$base_in.out"
fi
#checks if there is a difference between "user output" and "test output"
if diff -B -w out $expected_file > diffout
then
echo "Passed $main test $infile"
echo ""
TESTS_PASSED=$((TESTS_PASSED+1))
else
echo "Failed $main test $infile"
echo "*********** OUTPUT: Actual output followed by expected."
cat diffout
echo "*******************************"
echo ""
fi
rm diffout
}
# Check we need at least 2.
if [ $# -gt 1 ]
then
# naming command-line parameters to script
main=$1
inputdir=$2
# copying over all the source files into TestingTemp/
# and then moving into that directory.
cp src/*.java TestingTemp/
cd TestingTemp/
# compiling the driver and any local files it imports
echo ""
echo "==== compiling $main ===="
javac $main.java
if [ $? -ne 0 ]
then
echo "******************************************"
echo "grade.sh ERROR: java compilation failed."
exit 1
fi
#gets the total number of tests from the PublicTest directory
TOTAL_CSV=$(ls ../$inputdir/*.csv | wc -l)
# FIXME: 5 is a magic number!!
TOTAL_TESTS=$(($TOTAL_CSV * 5))
TESTS_PASSED=0
echo ""
# if compilation worked then run it on each file in the given directory
for infile in `ls -v ../$inputdir/*.csv`
do
runCmdNDiff "MAX"
runCmdNDiff "DEPARTURES"
runCmdNDiff "LIMIT" 1
runCmdNDiff "LIMIT" 2
runCmdNDiff "LIMIT" 3
done
echo "**** Passed $TESTS_PASSED / $TOTAL_TESTS tests for $main ****"
echo ""
#if all passed exit with status 0
#if not exit with status 1
if [ "$TOTAL_TESTS" -ne "$TESTS_PASSED" ]
then
exit 1
else
exit 0
fi
# Not enough parameters given to script.
else
echo
echo "usage: ./grade.sh PA2Main PublicTestCases"
fi
echo