Difference between revisions of "VPL Module for C"

From dftwiki3
Jump to: navigation, search
(Created page with "~~~~ ---- <bluebox> This is a rough tutorial, put together quickly to help out Ariana Maksimović who was trying to setup a VPL module for C#. I'm assuming that you are famil...")
 
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
----
 
----
 
<bluebox>
 
<bluebox>
This is a rough tutorial, put together quickly to help out Ariana Maksimović who was trying to setup a VPL module for C#.  I'm assuming that you are familiar with the VPL interface and understand how vpl_run.sh and vpl_evaluate.sh work.
+
This is a rough tutorial, put together quickly to help out somebody who was trying to setup a VPL module for C#.  I'm assuming that you are familiar with the VPL interface and understand how vpl_run.sh and vpl_evaluate.sh work.
 
</bluebox>
 
</bluebox>
 
<br />
 
<br />
Line 13: Line 13:
 
   
 
   
 
<br />
 
<br />
=Create a simple solution program: this is the target for the students=
+
 
 +
 
 +
=Requested File=
 +
<br />
 +
Go to the Requested Files menu in the VPL Administration and create the file '''hw20.cs''' as the name of the file students will submit.
 
<br />
 
<br />
 +
=Create a simple solution program: hw20sol.cs=
 +
<br />
 +
We assume that the students will submit a file called '''hw20.cs''', and we add '''hw20sol.cs''' as a solution program in the VPL '''Execution Files''' section.
 
::<source lang="C#">
 
::<source lang="C#">
 +
// hw20sol.cs
 
// A Hello World! program in C#.  
 
// A Hello World! program in C#.  
 
using System;
 
using System;
Line 35: Line 43:
 
</source>
 
</source>
 
<br />
 
<br />
 +
 
=Create a vpl_run.sh Script=
 
=Create a vpl_run.sh Script=
 
<br />
 
<br />
Line 130: Line 139:
 
#--- compute difference.  Count number of lines that are  ---  
 
#--- compute difference.  Count number of lines that are  ---  
 
#--- different                                            ---
 
#--- different                                            ---
diff -y -w --ignore-all-space user.out expectedOutput\${i} > diff.out
+
diff -y -w --ignore-all-space user.out expectedOutput > diff.out
 
    
 
    
 
#--- reject if different ---
 
#--- reject if different ---
Line 144: Line 153:
  
 
       #--- accumulate percentages obtained at different tests ---   
 
       #--- accumulate percentages obtained at different tests ---   
       computeMatching expectedOutput\${i} user.out
+
       computeMatching expectedOutput user.out
 
       percent=\$?
 
       percent=\$?
 
else
 
else
Line 169: Line 178:
 
</source>
 
</source>
 
<br />
 
<br />
 +
 
=vpl_evaluate.sh=
 
=vpl_evaluate.sh=
 
<br />
 
<br />
Line 177: Line 187:
  
 
</source>
 
</source>
 +
<br />
 +
=Testing=
 +
<br />
 +
Go to the '''Test Activity''' section of the VPL Administration, and then click on '''Edit'''.
 +
In the hw20.cs area, enter the same program as the solution program:
 +
<br />
 +
::<source lang="C#">
 +
using System;
 +
namespace HelloWorld
 +
{
 +
    class Hello
 +
    {
 +
        static void Main()
 +
        {
 +
            Console.WriteLine("Hello World!");
 +
        }
 +
    }
 +
}
 +
 +
</source>
 +
<br />
 +
* Save
 +
* Run
 +
* You should be able to see the console window open and the "Hello world!" message.  Modify the output of the hw20.cs program to make it different from what is expected, and verify that VPL reports the difference.
 +
<br />
 +
<br /><br /><br /><br /><br /><br /><br /><br />
 +
[[Category:VPL]]

Latest revision as of 08:55, 12 April 2018

D. Thiebaut (talk) 09:47, 12 April 2018 (EDT)


This is a rough tutorial, put together quickly to help out somebody who was trying to setup a VPL module for C#. I'm assuming that you are familiar with the VPL interface and understand how vpl_run.sh and vpl_evaluate.sh work.


Setup


Install the mono C# compiler on your jail server. These commands should work:

sudo apt-get install mono-complete
sudo apt-get install monodevelop



Requested File


Go to the Requested Files menu in the VPL Administration and create the file hw20.cs as the name of the file students will submit.

Create a simple solution program: hw20sol.cs


We assume that the students will submit a file called hw20.cs, and we add hw20sol.cs as a solution program in the VPL Execution Files section.

// hw20sol.cs
// A Hello World! program in C#. 
using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");
            Console.WriteLine("Hello World!");

            // Keep the console window open in debug mode.
            //Console.WriteLine("Press any key to exit.");
            //Console.ReadKey();
        }
    }
}


Create a vpl_run.sh Script


#! /bin/bash
# D. Thiebaut
# Smith College
# vpl_run.sh script
# runs the student program and compare the output to the solution
# program and displays some information about the lines that do not
# match
# set -x

#--- figure out how to filter the outputs --- 
keepOnlyNumbers=false
removeMultipleSpaces=true
removeBlankLines=true
keepLastLines=0    # set to 0 if not needed 

# --- program tested (no extension) --- 
prog1=hw20

# create vpl_execution which will be run on the jail server
# 
cat > vpl_execution <<EEOOFF
#! /bin/bash

# --- program tested (no extension) ---
prog1=$prog1


# ---------------------------------------------------------------
# scale( percentGood )
# transforms inGrade into outGrade
# ---------------------------------------------------------------
function scale {
    percent=\$1
    inGrade=(   95 90 85 80 75 70 65 60 55 50 0 )
    #            A A- B+ B  B- C+ C  C- D+ D  F
    outGrade=( 100 92 90 88 86 84 80 76 72 68 50 )
    #outGrade=( 100 93 87 83 80 77 73 80 67 60 50 )
 
    # get length of an array
    arraylength=\${#inGrade[@]}

    # loop through all the grades
    for (( i=0; i<\${arraylength}; i++ ));
    do
        if (( \$percent > \${inGrade[\$i]} )) ; then 
    return \${outGrade[\$i]}
        fi
    done
    return 50
}

# ---------------------------------------------------------------
# computeMatching( solution, student )
# returns the percentage of matching lines
# ---------------------------------------------------------------
function computeMatching {
    noLinesToMatch=\`cat \$1 | wc -l\`
    noGoodLines=\`grep -Fxf \$2 \$1 | wc -l\`
    percentGood=\$(( \$noGoodLines * 100 / \$noLinesToMatch ))
    return \$percentGood
}

# ---------------------------------------------------------------
# runProgram.  Stop if program crashes
# ---------------------------------------------------------------
function run {
    mcs \${1}.cs &&  mono \${1}.exe  &> user.out  
    
    errCode=\$?
     if [ \$errCode -ne 0 ]; then 
         echo "Error! Unfortunately, your program crashed."
         cat user.out
         exit 0
     fi
}
 

#-----------------------------------------------------------------
#--- run studentprogram, capture output, keep  original output ---
#-----------------------------------------------------------------
run \${prog1}      # output will &> user.out

#-----------------------------------------------------------------
#--- generate output for solution program and treat it same as ---
#--- output of user.                                           ---
#-----------------------------------------------------------------

mcs \${prog1}sol.cs  
mono \${prog1}sol.exe > expectedOutput 

#--- compute difference.  Count number of lines that are  --- 
#--- different                                            ---
diff -y -w --ignore-all-space user.out expectedOutput > diff.out
   
#--- reject if different ---
if ((\$? > 0)); then
      echo "Your output is incorrect."

      echo "Output from your program:"
      cat user.out
      echo ""
      echo "Expected output: "
      cat expectedOutput
      echo ""

      #--- accumulate percentages obtained at different tests ---   
      computeMatching expectedOutput user.out
      percent=\$?
else
      # --------------------- REWARD IF CORRECT OUTPUT -----------------

      #--- good output ---
      echo "Congrats, the output of your program is correct!"
      cat user.out
      percent=100
fi


scale \$percent
grade=\$?
echo ""
echo  \${grade}


EEOOFF

chmod +x vpl_execution


vpl_evaluate.sh


#! /bin/bash
cp vpl_run.sh vpl_evaluate2.sh
./vpl_evaluate2.sh


Testing


Go to the Test Activity section of the VPL Administration, and then click on Edit. In the hw20.cs area, enter the same program as the solution program:

using System;
namespace HelloWorld
{
    class Hello 
    {
        static void Main() 
        {
            Console.WriteLine("Hello World!");
        }
    }
}


  • Save
  • Run
  • You should be able to see the console window open and the "Hello world!" message. Modify the output of the hw20.cs program to make it different from what is expected, and verify that VPL reports the difference.