Tutorial: Moodle VPL -- Testing Two Java Classes

From DftWiki

Jump to: navigation, search

--D. Thiebaut (talk) 12:14, 19 September 2014 (EDT)


Contents

MoodleVPLLogo.png



Moodle VPL Tutorials



This VPL activity allows the automatic evaluation of 2 Java programs submitted by students. The first one is an implementation of a list. The second uses the list for some simple computation. The VPL evaluation checks that one of the student programs does not contain a particular pattern, in this case the use of [ ] brackets, indicating that one class uses the private member array of the other. Depending on the various stages of success, the module assigns different grades to the submitted programs.


Setup


  • Hw 2: Pascal Triangle with a Python-Like list
  • Due date: Thursday, September 25, 2014, 11:55 PM
  • Requested files: PythonList.java, PascalList.java (Download)
  • Type of work: Individual work
  • Grade settings: Maximum grade: 100
  • Run: Yes Evaluate: Yes
  • Automatic grade: Yes


Requested Files


  • PythonList.java
  • PascalList.java


Execution Files


vpl_run.sh


#! /bin/bash

cat > vpl_execution <<EEOOFF
#! /bin/bash
 
prog1=PascalList
prog2=PythonList
grade=0
 
javac \${prog1}.java \${prog2}.java  &> /dev/null
 
if ((\$? > 0)); then
     echo "Error compiling your program"
     exit
fi
 
java \${prog1}
 
EEOOFF

 
chmod +x vpl_execution


vpl_evaluate.sh


#! /bin/bash

cat > vpl_execution <<EEOOFF
#! /bin/bash

# ---------- PROGRAMS TESTED (WITHOUT EXTENSION) ---------
prog1=PascalList
prog2=PythonList

# --------------------- STARTING GRADE -------------------
grade=0

# ----------------- COMPILE STUDENT PROG  ----------------
javac \${prog1}.java \${prog2}.java  &> /dev/null

#--- if error, assign a minimal grade ---
if ((\$? > 0)); then
     echo "Comment :=>> Your program has compiler Errors."
     echo "Comment :=>> Please try to fix them."
     echo "Grade :=>> 10"
     exit
fi

# ----------- Remove comments from the code ---------------------

cat \$prog1.java | sed 's://.*$::g' | sed '/\/\*\*/,/\*\// {s/.*\*\/.*//p; d}' > _\$prog1.java


# ----------- TEST THE CODE FOR PARTICULAR PATTERNS -------------
grep '\[*\]' _\${prog1}.java | grep -v main  &> grepLines.out

if [ -s grepLines.out ] ; then
    echo "Comment :=>> Your \$prog1 program cannot directly access the array in \$prog2."
    echo "Comment :=>> ------------"
    echo "Comment :=>> Problem Area"
    echo "Comment :=>> ------------"
    echo "<|--"
    cat grepLines.out
    echo "--|>"
    echo "Grade :=>> 20"
    exit
fi

# ----------------- RUN PROGRAM & CAPTURE OUTPUT -----------------
java \${prog1} &> user.out

# ----------------- REMOVE BLANK LINES IN OUTPUT -----------------
cat user.out | sed '/^\s*$/d' > dummy.out
mv dummy.out user.out

# -----------------    CREATE EXPECTED OUTPUT  -------------------
cat > good.out <<EOF
1
7
21
35
35
21
7
1
EOF

# ---------------------- COMPUTE DIFFERENCE  ---------------------
diff -y -w --ignore-all-space user.out good.out > diff.out

# ----------------------- REJECT IF DIFFERENT --------------------
if ((\$? > 0)); then
   echo "Comment :=>> Your output is incorrect."
   echo "Comment :=>> ---------------"
   echo "Comment :=>> Your output:"
   echo "Comment :=>> ---------------"
   echo "<|--"
   cat user.out
   echo "--|>"
   echo ""
   echo "Comment :=>> ---------------"
   echo "Comment :=>> Expected output: "
   echo "Comment :=>> ---------------"
   echo "<|--"
   cat good.out
   echo "--|>"
   
   #--- consolation grade ---  
   grade=\$((grade+10))

# --------------------- REWARD IF CORRECT OUTPUT -----------------
else
   #--- good output ---
   echo "Comment :=>> Congrats, your output is correct."
   echo "Comment :=>> --------------------------------."
   echo "<|--"
   cat user.out
   echo "--|>"
   grade=\$((grade+100))
fi


echo "Grade :=>> \$grade"

EEOOFF


chmod +x vpl_execution


Run


VPL 2javaClassesRun.png


Evaluate


No Errors


VPL 2javaClassesEvaluate1.png


Program Accesses Array of Other Class without Using Method


VPL 2javaClassesEvaluate2.png


Program Outputs Wrong Answer


VPL 2javaClassesEvaluate3.png