Commit be274a9d authored by Guillaume Huard's avatar Guillaume Huard
Browse files

Démo de la doc dans ce dépôt

parent 43d228c5
#+OPTIONS: num:nil
#+OPTIONS: toc:nil
#+OPTIONS: html-postamble:nil
#+OPTIONS: html-preamble:nil
#+LANGUAGE: fr
#+EXPORT_EXCLUDE_TAGS: noexport
#+PROPERTY: header-args :eval never :mkdirp yes :exports none
Démo des activités 'Basic system programming' fondée sur l'exemple présenté dans
la documentation.
#+BEGIN_SRC txt :tangle Demo/vpl_id.txt
23944
#+END_SRC
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases
my $cases = {};
#+END_SRC
** Exercice 'Hello world !'
Écrire un programme en bash qui affiche ='Hello world !'=.
#+BEGIN_SRC shell :tangle Demo/cf/hello_world.sh
echo "Hello world !"
#+END_SRC
#+BEGIN_SRC shell :tangle Demo_wrong/cf/hello_world.sh
echo "Salut monde !"
#+END_SRC
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases :output append :noweb yes
my $solution = q{#include <stdio.h>
int main() {
printf("Hello world !\n");
return 0;
}
};
$cases->{"hello_world.sh"} = {
execute => 'bash -- $NAME $@',
solution => {
content => $solution,
filename => "solution.c",
compile => 'gcc -o $NAME $FILES'
},
tests => {
test_1 => { show => 1 }
}
};
#+END_SRC
** Exercice 'cut'
Écrire un programme en java qui prend deux entiers en arguments et affiche le texte lu sur son
entrée standard en le traitant de la même manière que la commande ="cut -d' ' -f$1-$2"=.
#+BEGIN_SRC java :tangle Demo/cf/ExerciceCut.java
import java.util.Scanner;
class ExerciceCut {
public static void handle(String line, int from, int to) {
String [] fields = line.split(" ");
for (int i=from; (i<fields.length) && (i<to); i++)
System.out.print(fields[i]+" ");
if ((to < fields.length) && (from <= to))
System.out.println(fields[to]);
}
public static void main(String [] args) {
int from = Integer.parseInt(args[0]);
int to = Integer.parseInt(args[1]);
from--;
to--;
Scanner s = new Scanner(System.in);
while (s.hasNextLine()) {
String line = s.nextLine();
handle(line, from, to);
}
}
}
#+END_SRC
#+BEGIN_SRC java :tangle Demo_wrong/cf/ExerciceCut.java
import java.util.Scanner;
class ExerciceCut {
public static void main(String [] args) {
Scanner s = new Scanner(System.in);
while (s.hasNextLine()) {
String line = s.nextLine();
System.out.println(line);
}
}
}
#+END_SRC
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases :output append :noweb yes
my $input = q{texte fourni en entrée
à notre programme que nous desirons
tester
};
my $solution2=q{#!/bin/bash
cut -d' ' -s -f$1-$2
};
$cases->{"ExerciceCut"} = {
files => [ "ExerciceCut.java" ],
compile => 'javac $FILES',
execute => 'java $NAME $@',
tests => {
test_1 => {
input => $input,
args => [ 2, 3 ],
solution => $solution2,
match => [ 'output', 'code' ],
cleanup_level => 0
}
}
};
#+END_SRC
** Exercice 'limites'
Écrire un programme qui s'exécute en moins de 2 secondes et ne crée pas de fichier de plus de 1024
octets.
#+BEGIN_SRC shell :tangle Demo/cf/limites.sh
#!/bin/bash
echo "Hello world !"
#+END_SRC
#+BEGIN_SRC shell :tangle Demo_wrong/cf/limites.sh
#!/bin/bash
while /usr/bin/true
do
echo "Hello world !"
done
sleep 5
#+END_SRC
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases :output append :noweb yes
$cases->{"limites.sh"} = {
code => 0, signal => 0,
tests => {
test_1 => { timeout => 2 },
test_2 => { output_limit => 1 },
test_3 => { output_limit => 1, timeout => 2 }
}
};
#+END_SRC
** Exercice 'créer toto'
Ecrire un programme qui crée un fichier dont le nom lui est donné en argument et lui donne les
droits en exécution.
#+BEGIN_SRC shell :tangle Demo/cf/creer_toto.sh
#!/bin/bash
touch $1
chmod +x $1
#+END_SRC
#+BEGIN_SRC shell :tangle Demo_wrong/cf/creer_toto.sh
#!/bin/bash
touch toto.sh
chmod +x toto.sh
#+END_SRC
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases :output append :noweb yes
my $validator = q{#!/bin/bash
[ -f $1 -a -x $1 ]
};
my $setup = q{#!/bin/bash
[ -f $1 ] && rm $1
exit 0
};
$cases->{"creer_toto.sh"} = {
validator => $validator,
setup => $setup,
tests => {
test_1 => { args => [ "toto.sh" ], weight => 2 },
test_2 => { args => [ "tata.sh" ] }
}
};
#+END_SRC
** Epilogue :noexport:
#+BEGIN_SRC perl :tangle Demo/ef/vpl_evaluate.cases :output append
$cases;
#+END_SRC
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment