Ejemplo de un VPL en C

De Documentación Campus Virtual de la UEx
Ir a la navegación Ir a la búsqueda

Ejemplo de un VPL C

Vamos a crear un Laboratorio Virtual de Programación en C

Se trata de una práctica que implementa el comando grep en C. 

El uso del comando sería:

grepvpl [-i] patron fichero

Comprobaciones:

  • número correo de parámetros.
  • El fichero debe existir.
  • El parámetro -i implica su ejecución case insensitive.


   Referencia: http://www.science.smith.edu/dftwiki/index.php/Tutorial:_Moodle_VPL_--_Testing_a_C_Program.. 

Configuración

En un principio, como en la creación de todas las actividades de VPL, estas serían las únicas opciones de configuración del laboratorio: Nombre y "Descripción del Laboratorio"
CrearVPLC.PNG

Casos de prueba

Para este laboratorio no se han implementado tests de pruebas, y el fichero vpl_evaluate.cases, y sí se facilita el fichero vpl_evaluate.sh en su defecto.



Opciones de ejecución

En este laboratorio dejaremos que se ejecute el script de C predeterminado y no lo seleccionamos ninguno en concreto. Dejamos las opciones en "Autodetectar". Con el fin de que el alumno pueda comprobar su actividad antes de la entrega definitiva, activamos la opción de Ejecutar, y para que la actividad se evalúe automáticamente, activamos la opción Evaluar, que le dará una calificación al ejercicio
EjecucionVPLC.PNG

Ficheros requeridos

Nuestro fichero se llama grepvpl.c, y como hemos visto en la tabla, la extensión 'c' es la que tienen los ficheros C, y para el que nuestro laboratorio ejecutará el script autodetectado de C.
En este caso, grepvpl.c es el único fichero que se le requiere al alumno, el fichero con su entrega de la actividad. Aquí es donde el alumno debe escribir el código de la práctica.
RequeridoVPLC.PNG

Ajustes avanzados

Ficheros para la ejecución
Se establecen los ficheros necesarios para la ejecución, depurado o evaluación de la entrega. Esto incluye ficheros script, programas de prueba y ficheros de datos.
En este laboratorio C, tenemos dos de los cuatro ficheros opcionales para ejecutar la entrega (vpl_run.sh y vpl_evaluate.sh), y un fichero más file1.txt necesario para ejecutar la práctica
EjecucionC1.PNG EjecucionC2.PNGEjecucionC3.PNG
   
Ficheros de Ejecución
vpl_run.sh
vpl_evaluate.sh
file1.txt

  1. #! /bin/bash

  2. # D. Thiebaut
  3. # Smith College
  4. # vpl_evaluate.sh script looping through several tests, each test with
  5. # its own input file and its own expected output file.  The output of the
  6. # student program is tested against the expected output file.
  7. #


  8. cat > vpl_execution <<EEOOFF
  9. #! /bin/bash
  10.  
  11. # --- program tested (no extension) ---
  12. prog1=grepvpl
  13. gcc -o \${prog1} \${prog1}.c

  14. # --- compile student program ---
  15. #chmod a+x \${prog1}

  16. # --- create test input files ---
  17. cat > data1.txt <<EOF
  18. one file1.txt 
  19. EOF

  20. cat > data1.out <<EOF
  21. one two
  22. one two three
  23. EOF

  24. # ---
  25. cat > data2.txt <<EOF
  26. -i one file1.txt 
  27. EOF

  28. cat > data2.out <<EOF
  29. ONE
  30. one two
  31. one two three
  32. ONE TWO 
  33. ONE TWO THREE 
  34. EOF

  35. # ---
  36. cat > data3.txt <<EOF
  37. -i one file2.txt 
  38. EOF

  39. cat > data3.out <<EOF
  40. grep: file2.txt: No such file or directory
  41. EOF
  42.    
  43. # ---

  44. cat > data4.txt <<EOF
  45. -i eleven file1.txt 
  46. EOF

  47. cat > data4.out <<EOF
  48. EOF

  49. # ---
  50. cat > data5.txt <<EOF
  51. eleven file1.txt 
  52. EOF

  53. cat > data5.out <<EOF
  54. EOF




  55. grade=100

  56. for i in 1  ; do
  57.    echo "Comment :=>>-TEST \$i"

  58.    # ==============================================
  59.    # TEST i
  60.    # ==============================================
  61.    #--- run program, capture output, display to student ---
  62.    command="head -n 1 data\${i}.txt"
  63.    input=\$( \$command )
  64.    ./\${prog1} \${input}  &> user.out
  65.    cp user.out user.out.org

  66.    #--- remove non numbers and non minus---
  67.    #cat user.out | sed 's/[^0-9\ -]*//g' > dummy.out
  68.    #mv dummy.out user.out
  69.  
  70.    #--- remove multiple spaces --- 
  71.    cat user.out | sed 's/  */ /g' > dummy.out
  72.    mv dummy.out user.out

  73.    #--- remove blank lines ---
  74.    cat user.out | sed '/^\s*$/d' > dummy.out
  75.    mv dummy.out user.out

  76.    #--- compute difference --- 
  77.    diff -y -w --ignore-all-space user.out data\${i}.out > diff.out
  78.    #echo "----- diff.out ------"
  79.    #cat diff.out
  80.    #echo "---------------------"
  81.    diff -y -w --ignore-all-space user.out data\${i}.out > diff.out

  82.    
  83.    #--- reject if different ---
  84.    if ((\$? > 0)); then
  85.       echo "Comment :=>>- Your output is incorrect."

  86.       #--- display test file ---
  87.       echo "Comment :=>>- Your program tested with:"
  88.       echo "<|--" 
  89.       cat data\${i}.txt
  90.       echo "--|>"

  91.       echo "Comment :=>> ---------------"
  92.       echo "Comment :=>>- Your output:"
  93.       echo "Comment :=>> ---------------"
  94.       echo "<|--"
  95.       cat user.out.org
  96.       echo "--|>"
  97.       echo ""
  98.       echo "Comment :=>> ---------------"
  99.       echo "Comment :=>>- Expected output (only the numbers): "
  100.       echo "Comment :=>> ---------------"
  101.       echo "<|--"
  102.       cat data\${i}.out
  103.       echo "--|>"
  104.    
  105.       #--- consolation grade ---   
  106.       #grade=\$((grade-5))

  107.       # --------------------- REWARD IF CORRECT OUTPUT -----------------
  108.    else
  109.       #--- good output ---
  110.       echo "Comment :=>>- Congrats, your output is correct."
  111.       echo "Comment :=>> --------------------------------."
  112.       echo "<|--"
  113.       cat user.out.org
  114.       echo "--|>"
  115.       #grade=\$( expr \$grade + 13 )
  116.    fi
  117. done

  118. #echo "Grade :=>> \$grade"

  119. EEOOFF

  120.  
  121. chmod +x vpl_execution

  1. #! /bin/bash
  2. # D. Thiebaut
  3. # Smith College
  4. # vpl_evaluate.sh script looping through several tests, each test with
  5. # its own input file and its own expected output file.  The output of the
  6. # student program is tested against the expected output file.
  7. #


  8. cat > vpl_execution <<EEOOFF
  9. #! /bin/bash
  10.  
  11. # --- program tested (no extension) ---
  12. prog1=grepvpl
  13. gcc -o \${prog1} \${prog1}.c

  14. # for debugging...
  15. #cp 231grep.c grep.py
  16. #prog1=grep.py
  17. #chmod +x grep.py


  18. # --- compile student program ---
  19. #chmod a+x \${prog1}

  20. # --- create test input files ---
  21. cat > data1.txt <<EOF
  22. one file1.txt 
  23. EOF

  24. cat > data1.out <<EOF
  25. one two
  26. one two three
  27. EOF

  28. # ---
  29. cat > data2.txt <<EOF
  30. -i one file1.txt 
  31. EOF

  32. cat > data2.out <<EOF
  33. ONE
  34. one two
  35. one two three
  36. ONE TWO 
  37. ONE TWO THREE 
  38. EOF

  39. # ---
  40. cat > data3.txt <<EOF
  41. -i one file2.txt 
  42. EOF

  43. cat > data3.out <<EOF
  44. grepvpl: file2.txt: el fichero indicado no existe
  45. EOF
  46.    
  47. # ---

  48. cat > data4.txt <<EOF
  49. -i eleven file1.txt 
  50. EOF

  51. cat > data4.out <<EOF
  52. EOF

  53. # ---
  54. cat > data5.txt <<EOF
  55. eleven file1.txt 
  56. EOF

  57. cat > data5.out <<EOF
  58. EOF




  59. grade=100

  60. for i in 1 2 3 4 5 ; do
  61.    echo "Comment :=>>-TEST \$i"

  62.    # =========================================
  63.    # TEST i
  64.    # ==============================================
  65.    #--- run program, capture output, display to student ---
  66.    command="head -n 1 data\${i}.txt"
  67.    input=\$( \$command )
  68.    ./\${prog1} \${input}  &> user.out
  69.    cp user.out user.out.org

  70.    #--- remove non numbers and non minus---
  71.    #cat user.out | sed 's/[^0-9\ -]*//g' > dummy.out
  72.    #mv dummy.out user.out
  73.  
  74.    #--- remove multiple spaces --- 
  75.    cat user.out | sed 's/  */ /g' > dummy.out
  76.    mv dummy.out user.out

  77.    #--- remove blank lines ---
  78.    cat user.out | sed '/^\s*$/d' > dummy.out
  79.    mv dummy.out user.out

  80.    #--- compute difference --- 
  81.    diff -y -w --ignore-all-space user.out data\${i}.out > diff.out
  82.    #echo "----- diff.out ------"
  83.    #cat diff.out
  84.    #echo "---------------------"
  85.    diff -y -w --ignore-all-space user.out data\${i}.out > diff.out

  86.    
  87.    #--- reject if different ---
  88.    if ((\$? > 0)); then
  89.       echo "Comment :=>>- Your output is incorrect."

  90.       #--- display test file ---
  91.       echo "Comment :=>>- Your program tested with:"
  92.       echo "<|--" 
  93.       cat data\${i}.txt
  94.       echo "--|>"

  95.       echo "Comment :=>> ---------------"
  96.       echo "Comment :=>>- Your output:"
  97.       echo "Comment :=>> ---------------"
  98.       echo "<|--"
  99.       cat user.out.org
  100.       echo "--|>"
  101.       echo ""
  102.       echo "Comment :=>> ---------------"
  103.       echo "Comment :=>>- Expected output (only the numbers): "
  104.       echo "Comment :=>> ---------------"
  105.       echo "<|--"
  106.       cat data\${i}.out
  107.       echo "--|>"
  108.    
  109.       #--- consolation grade ---   
  110.       #grade=\$((grade-5))

  111.       # --------------------- REWARD IF CORRECT OUTPUT -----------------
  112.    else
  113.       #--- good output ---
  114.       echo "Comment :=>>- Congrats, your output is correct."
  115.       echo "Comment :=>> --------------------------------."
  116.       echo "<|--"
  117.       cat user.out.org
  118.       echo "--|>"
  119.       #grade=\$( expr \$grade + 13 )
  120.    fi
  121. done

  122. echo "Grade :=>> \$grade"

  123. EEOOFF

  124.  
  125. chmod +x vpl_execution

  1. ONE
  2. one two
  3. one two three
  4. ONE TWO 
  5. three
  6. ONE TWO THREE 
  7. four five
  8. three
  9. FOUR FIVE

Límites máximos de recursos de ejecución
Aquí establecemos los límites máximos para el tiempo de ejecución, la memoria usada, el tamaño de los ficheros generados durante la ejecución y el número de procesos simultáneos. Para nuestro ejemplo, no hemos definido límites.
Ficheros a mantener mientras se ejecuta
En esta opción marcamos los ficheros que deben permanecer durante la fase de ejecución
MantenerC.PNG
Variaciones
No se han configurado variaciones para esta actividad.
Comprobación de servidores de ejecución
En este enlace podemos comprobar el estado de los servidores de ejecución usados por esta actividad.
Servidores de ejecución locales
No se han suministrado urls de servidores de ejecución locales para esta actividad.

Probar actividad

Ejecutar
Si queremos, podemos ver si todo funciona bien editando el fichero de entrega y ejecutándolo para probar.
0.00
(0 votos)