Tutorial: Moodle VPL -- Testing A Submitted Data-Structure Class using a Test Class

From DftWiki

Jump to: navigation, search

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


Contents

MoodleVPLLogo.png



Moodle VPL Tutorials



This tutorial generates a VPL activity that allows automatic evaluation of a Java Data-Structure class provided by the students. The instructor provides a separate class that tests the students' data structure. The grade is proportional to the number of correct output lines.


Setup


  • Requested files: PythonList2.java (Download)
  • Type of work: Individual work
  • Grade settings: Maximum grade: 100
  • Run: Yes Evaluate: Yes
  • Automatic grade: Yes


Files to Keep When Running

  • vpl_run.sh
  • vpl_evaluate.sh
  • TestPythonList2.java


vpl_run.sh


#! /bin/bash

cat > vpl_execution <<EEOOFF
#! /bin/bash
 
prog1=TestPythonList2
prog2=PythonList2
 
 
javac \${prog1}.java \${prog2}.java  
 
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=TestPythonList2
prog2=PythonList2

# --------------------- 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



# ----------------- 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
Snow White's friends:
Blick
Flick
Glick
Plick
Quee
Snick
Whick
Quee found at Index: 4
Quee found at Index: 4
Queen not found
EOF

# ---------------------- COMPUTE DIFFERENCE  ---------------------
diff -y -w --ignore-all-space --suppress-common-lines 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 "--|>"

   echo ""
   echo "Comment :=>> ---------------"
   echo "Comment :=>> Difference: "
   echo "Comment :=>> ---------------"
   echo "<|--"
   cat diff.out
   echo "--|>"
   
   #--- consolation grade ---  
   noBadLines=\`cat diff.out | wc -l\`
   totalLines=\`cat good.out | wc -l\`
   grade=\$(( (totalLines - noBadLines) * 100 / totalLines))
   echo "Grade :=>> \$grade"
   exit

# --------------------- 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




This concludes this tutorial.