mirror of
https://github.com/LucasVbr/interpreteur-lir.git
synced 2026-07-09 15:08:05 +00:00
Prototype 2.0
This commit is contained in:
@@ -6,6 +6,7 @@ package interpreteurlir.motscles;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
/**
|
||||
* Une commande (générale) n'a aucun comportement.
|
||||
@@ -20,6 +21,9 @@ import interpreteurlir.InterpreteurException;
|
||||
*/
|
||||
public class Commande {
|
||||
|
||||
/** référence du programme global */
|
||||
protected static Programme programmeGlobal;
|
||||
|
||||
/** référence du contexte possiblement manié directement par la commande */
|
||||
protected Contexte contexte;
|
||||
|
||||
@@ -52,6 +56,27 @@ public class Commande {
|
||||
// pas de comportement pour une Commande générale
|
||||
return false; // pas de feedback
|
||||
}
|
||||
|
||||
/**
|
||||
* Référence le programme pour accéder et modifier le programme chargé.
|
||||
* Le référencement vaut pour toutes les commandes/instructions
|
||||
* et est possible une unique fois.
|
||||
* @param aReferencer référence du programme global
|
||||
* @return <ul><li>true si le programme a pu être référencé</li>
|
||||
* <li>true si aReferencer == programme déjà référencer</li>
|
||||
* <li>false si aReferencer est null</li>
|
||||
* <li>false si un programme est déjà référencer</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static boolean referencerProgramme(Programme aReferencer) {
|
||||
if (aReferencer != null
|
||||
&& ( programmeGlobal == null
|
||||
|| aReferencer == programmeGlobal)) {
|
||||
programmeGlobal = aReferencer;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ import interpreteurlir.InterpreteurException;
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class CommandeDebut extends Commande {
|
||||
|
||||
// TODO adapter la classe aux programmes
|
||||
|
||||
/**
|
||||
* Initialise une commande debut qui est sans arguments
|
||||
@@ -50,6 +48,7 @@ public class CommandeDebut extends Commande {
|
||||
@Override
|
||||
public boolean executer() {
|
||||
contexte.raz();
|
||||
programmeGlobal.raz();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* CommandeEfface.java 16 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
|
||||
/**
|
||||
* Instruction permettant d'effacer une, plusieurs, ou l'intégralité des lignes
|
||||
* de code d'un programme écrit dans l'interpréteur LIR.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class CommandeEfface extends Commande {
|
||||
|
||||
/** Erreur nombre incorrect d'arguments */
|
||||
private static final String ERREUR_NB_ARGS =
|
||||
"nombre d'arguments incorrect. Syntaxe attendue ==> <debut>:<fin>";
|
||||
|
||||
/** Plage de suppression des lignes de code */
|
||||
private Etiquette[] plageSuppression;
|
||||
|
||||
/**
|
||||
* Initialise cette InstructionEfface à partir des arguments et du
|
||||
* contexte passés en paramètres. Modifie le programme global référencé
|
||||
* par l'analyseur.
|
||||
* @param arguments lignes à effacer (tout le programme si vide)
|
||||
* @param contexte
|
||||
*/
|
||||
public CommandeEfface(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
plageSuppression = analyserArguments(arguments);
|
||||
}
|
||||
|
||||
/*
|
||||
* Non - javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#executer()
|
||||
*/
|
||||
@Override
|
||||
public boolean executer() {
|
||||
programmeGlobal.effacer(plageSuppression[0], plageSuppression[1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Découpe la chaîne argument en une plage de deux étiquettes
|
||||
* @param aDecouper chaîne à analyser
|
||||
* @return la plage de lignes de code à supprimer sous forme de tableau
|
||||
* d'étiquettes.
|
||||
*/
|
||||
private static Etiquette[] analyserArguments(String aDecouper) {
|
||||
String[] valeurs = aDecouper.split(":");
|
||||
if (valeurs.length != 2)
|
||||
throw new InterpreteurException(ERREUR_NB_ARGS);
|
||||
|
||||
Etiquette[] aRenvoyer = {
|
||||
new Etiquette(valeurs[0]),
|
||||
new Etiquette(valeurs[1])
|
||||
};
|
||||
|
||||
return aRenvoyer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* CommandeLance.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
|
||||
/**
|
||||
* Démarre l'exécution d'un programme à partir de son plus petit numéro
|
||||
* d'étiquette.
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class CommandeLance extends Commande {
|
||||
|
||||
private Etiquette debutLancer;
|
||||
|
||||
/**
|
||||
* Initialise la commande lance avec ses arguments et le contexte
|
||||
* @param arguments
|
||||
* @param contexte
|
||||
* @throws InterpreteurException en cas d'erreur de syntaxe à
|
||||
* la création d'une étiquette
|
||||
*/
|
||||
public CommandeLance(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
if (arguments.isBlank()) {
|
||||
debutLancer = null;
|
||||
} else {
|
||||
debutLancer = new Etiquette(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécution de la commande :
|
||||
* <ul><li>Lance le programme à partir de l'étiquette la plus
|
||||
* petite s'il n'y a pas d'argument</li>
|
||||
* <li>Lance le programme à partir de l'étiquette passée
|
||||
* en paramètre</li>
|
||||
* </ul>
|
||||
* @return true car un feedback est affiché
|
||||
* @throws RuntimeException si un programme n'est pas référencé
|
||||
* dans la classe {@link Commande}
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR = "erreur exécution";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR);
|
||||
}
|
||||
|
||||
if (debutLancer == null) {
|
||||
programmeGlobal.lancer();
|
||||
} else {
|
||||
programmeGlobal.lancer(debutLancer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* CommandeListe.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import static interpreteurlir.programmes.Etiquette.*;
|
||||
|
||||
/**
|
||||
* Commande liste affiche les lignes de codes du programme,
|
||||
* soit dans leur intégralité, soit dans un intervalle donné
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class CommandeListe extends Commande {
|
||||
|
||||
private Etiquette debut;
|
||||
|
||||
private Etiquette fin;
|
||||
|
||||
/**
|
||||
* Initialise la commande liste avec ses arguments et le contexte
|
||||
*
|
||||
* @param arguments
|
||||
* @param contexte
|
||||
* @throws InterpreteurException en cas d'erreur de syntaxe lors
|
||||
* de l'instanciation des étiquettes
|
||||
*/
|
||||
public CommandeListe(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
final int ARGS_DEBUT = 0;
|
||||
final int ARGS_FIN = 1;
|
||||
|
||||
final String ERREUR_INTERVALLE = "usage <etiquette debut>:"
|
||||
+ "<etiquette fin> avec "
|
||||
+ "<etiquette debut> < "
|
||||
+ "<etiquette fin> ";
|
||||
|
||||
if (arguments.isBlank()) {
|
||||
debut = new Etiquette(VALEUR_ETIQUETTE_MIN);
|
||||
fin = new Etiquette(VALEUR_ETIQUETTE_MAX);
|
||||
} else {
|
||||
String[] decoupage = arguments.split(":");
|
||||
|
||||
if (decoupage.length < 2) {
|
||||
throw new InterpreteurException(ERREUR_INTERVALLE);
|
||||
}
|
||||
|
||||
debut = new Etiquette(decoupage[ARGS_DEBUT]);
|
||||
fin = new Etiquette(decoupage[ARGS_FIN]);
|
||||
|
||||
if (debut.compareTo(fin) > 0) {
|
||||
throw new InterpreteurException(ERREUR_INTERVALLE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Exécution de la commande :
|
||||
* <ul><li>Affiche les lignes de code du programme entre l'étiquette
|
||||
* de début et celle de fin passées en argument</li>
|
||||
* <li>Affiche l'intégralité des lignes de code du programme</li>
|
||||
* </ul>
|
||||
* @return true car un feedback est affiché
|
||||
* @throws RuntimeException si un programme n'est pas référencé
|
||||
* dans la classe {@link Commande}
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR = "erreur exécution";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR);
|
||||
}
|
||||
if (debut != null || fin != null) {
|
||||
System.out.print(programmeGlobal.listeBornee(debut, fin));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* InstructionAffiche.java 13 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.expressions.ExpressionChaine;
|
||||
|
||||
/**
|
||||
* Affiche sur la sortie standard une expression passée en argument. Cette
|
||||
* expression ne doit pas contenir d'affectation. Si aucune expression n'est
|
||||
* passée en argument, effectue un retour à la ligne.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class InstructionAffiche extends Instruction {
|
||||
|
||||
/** Erreur d'affectation illegale */
|
||||
private static final String AFFECTATION_ILLEGALE = "affectation illegale";
|
||||
|
||||
/**
|
||||
* Initialise cette InstructionAffiche à partir de son contexte global
|
||||
* d'exécution et de l'expression passée en argument. Lève une exception
|
||||
* si cette expression contient une affectation.
|
||||
* @param arguments contenant l'expression dont le résultat doit être
|
||||
* affiché.
|
||||
* @param contexte global de la session d'interpreteurlir
|
||||
* @throws InterpreteurException si la chaîne arguments contient un signe
|
||||
* égal en dehors d'un littéral de chaîne de caractères.
|
||||
*/
|
||||
public InstructionAffiche(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
if (ExpressionChaine.indexOperateur(arguments, '=') >= 0)
|
||||
throw new InterpreteurException(AFFECTATION_ILLEGALE);
|
||||
|
||||
aExecuter = arguments.isBlank()
|
||||
? null
|
||||
: Expression.determinerTypeExpression(arguments.trim());
|
||||
}
|
||||
|
||||
/*
|
||||
* Non - javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#executer()
|
||||
*/
|
||||
@Override
|
||||
public boolean executer() {
|
||||
if (aExecuter == null) {
|
||||
System.out.println();
|
||||
} else {
|
||||
System.out.print(aExecuter.calculer().getValeur());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Non - javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "affiche" + (aExecuter == null ? ""
|
||||
: " " + aExecuter.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* InstructionEntre.java 13 mai 2021
|
||||
* IUT Rodez info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.*;
|
||||
import interpreteurlir.donnees.litteraux.Chaine;
|
||||
import interpreteurlir.donnees.litteraux.Entier;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Instruction qui attend que l'utilisateur
|
||||
* entre une valeur sur l'entrée standard du type de l'identificateur argument
|
||||
* cette valeur sera affectée dans une variable ayant cet
|
||||
* identificateur dans le contexte.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class InstructionEntre extends Instruction {
|
||||
|
||||
/**
|
||||
* Identificateur à affecter à partir de la valeur
|
||||
* saisie à l'execution de cette instruction
|
||||
*/
|
||||
private Identificateur id;
|
||||
|
||||
/**
|
||||
* Initialise une instruction entre avec un
|
||||
* identificateur chaine ou entier en argument
|
||||
* @param arguments représentation texte de l'indentificateur
|
||||
* @param contexte contexte pour l'enregistrement de la valeur
|
||||
* saisie à l'execution
|
||||
* @throws InterpreteurException si argument n'est pas
|
||||
* un identificateur valide
|
||||
* @throws NullPointerException si contexte ou argument est null
|
||||
*/
|
||||
public InstructionEntre(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
final String ERREUR_ARG = "Entre attend un identificateur en argument";
|
||||
|
||||
if (arguments.isBlank()) {
|
||||
throw new InterpreteurException(ERREUR_ARG);
|
||||
}
|
||||
|
||||
if (arguments.indexOf("$") >= 0) {
|
||||
id = new IdentificateurChaine(arguments.trim());
|
||||
} else {
|
||||
id = new IdentificateurEntier(arguments.trim());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution de l'instruction :
|
||||
* L'utilisateur saisi une valeur sur l'entrée standard qui sera affectée
|
||||
* à une variable dans le contexte ayant comme identificateur celui
|
||||
* de l'instruction si le type est compatible
|
||||
* @return false car aucun feedback affiché directement
|
||||
* @throws ExecutionException si la valeur saisie n'est pas compatible
|
||||
* avec le type de l'identificateur de l'instruction
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String MESSAGE_ERREUR_TYPE = "Le type saisi ne correspond"
|
||||
+ " pas au type demandé";
|
||||
Scanner entree = new Scanner(System.in);
|
||||
|
||||
String valeurSaisie = entree.nextLine();
|
||||
|
||||
try {
|
||||
if (id instanceof IdentificateurEntier) {
|
||||
contexte.ajouterVariable(id, new Entier(valeurSaisie.trim()));
|
||||
} else {
|
||||
contexte.ajouterVariable(id, new Chaine("\""
|
||||
+ valeurSaisie + "\""));
|
||||
}
|
||||
} catch (InterpreteurException lancee) {
|
||||
throw new ExecutionException(MESSAGE_ERREUR_TYPE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* non javadoc
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "entre " + id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* InstructionProcedure.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
|
||||
/**
|
||||
* Instruction qui transfère l'exécution au numéro d'étiquette spécifié
|
||||
* et reprendra en séquence lorsque la procédure sera terminée
|
||||
* (instruction retour)
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class InstructionProcedure extends Instruction {
|
||||
|
||||
/** Etiquette désignant le début de la procedure à exécuter */
|
||||
private Etiquette debutProcedure;
|
||||
|
||||
/**
|
||||
* Initialise une procédure avec une étiquette en argument.
|
||||
* @param arguments Représentation texte d'une étiquette
|
||||
* @param contexte Contexte de la session de l'interpreteur LIR
|
||||
* @throws InterpreteurException Si un arguments ne corresponds
|
||||
* pas a une étiquette valide
|
||||
* @throws NullPointerException Si contexte ou argument est null
|
||||
*/
|
||||
public InstructionProcedure(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
final String ERREUR_ARG = "procedure attend une étiquette en argument";
|
||||
|
||||
if(arguments.isBlank()) {
|
||||
throw new InterpreteurException(ERREUR_ARG);
|
||||
}
|
||||
|
||||
debutProcedure = new Etiquette(arguments);
|
||||
}
|
||||
|
||||
/* non javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "procedure " + debutProcedure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution de l'instruction :
|
||||
* Appel d'une procedure située à l'étiquette de l'instruction.
|
||||
* L'appel s'empile sur le contexte appellant pour ce qui est du
|
||||
* compteur ordinal.
|
||||
* @return false car aucun feedback affiché directement
|
||||
* @throws RuntimeException si un programme n'est pas référencé en membre
|
||||
* de classe de Commande.
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR_REFERENCEMENT = "Le programme doit être référencé "
|
||||
+ "dans la classe commande";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR_REFERENCEMENT);
|
||||
}
|
||||
|
||||
programmeGlobal.appelProcedure(debutProcedure);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* InstructionRetour.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
|
||||
/**
|
||||
* Instruction qui transfère l'exécution au numéro d'étiquette
|
||||
* appelant (continue en séquence après l'instruction procedure qui à généré
|
||||
* l'appel).
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class InstructionRetour extends Instruction {
|
||||
|
||||
/**
|
||||
* Initialise une procedure qui est sans argument
|
||||
* @param arguments Argument de retour soit une chaine blanche ou vide
|
||||
* @param contexte Contexte de la session de l'interpreteur LIR
|
||||
* @throws InterpreteurException Si arguments n'est pas une chaîne blanche
|
||||
* ou vide.
|
||||
* @throws NullPointerException Si contexte ou argument est null
|
||||
*/
|
||||
public InstructionRetour(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
final String ERREUR_ARG = "L'instruction retour n'a pas d'arguments";
|
||||
|
||||
if (!arguments.isBlank()) {
|
||||
throw new InterpreteurException(ERREUR_ARG);
|
||||
}
|
||||
}
|
||||
|
||||
/* non javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "retour";
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution de l'instruction :
|
||||
* Retour d'une procédure en séquence après l'instruction procédure
|
||||
* appelante.
|
||||
* @return false car aucun feedback affiché directement
|
||||
* @throws RuntimeException si un programme n'est pas référencé en membre
|
||||
* de classe de Commande.
|
||||
* @throws ExecutionException Lorsque retour est exécuté alors qu'aucune
|
||||
* Instruction procedure n'a été exécutée avant.
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR_REFERENCEMENT = "Le programme doit être référencé "
|
||||
+ "dans la classe commande";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR_REFERENCEMENT);
|
||||
}
|
||||
|
||||
programmeGlobal.retourProcedure();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* InstructionStop.java 16 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
/**
|
||||
* Instruction stop servant à marquer la fin d'un programme de l'interpréteur
|
||||
* LIR. Aucune ligne de code portant une étiquette supérieure ne sera donc lue.
|
||||
* L'usage de cette instruction en ligne de commande directe n'a aucun effet.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class InstructionStop extends Instruction {
|
||||
|
||||
/** Message d'erreur si instruction passée avec des arguments */
|
||||
private static final String ERREUR_ARGUMENTS =
|
||||
"l'instruction stop n'accepte pas d'arguments";
|
||||
/**
|
||||
* Initialise cette instruction stop à partir des arguments, du contexte
|
||||
* et du programme passés en paramètres. Cette instruction ne modifie que
|
||||
* le programme. Si arguments n'est pas vide, une exception sera levée.
|
||||
* @param arguments doit être vide
|
||||
* @param contexte global de la session de l'interpréteur
|
||||
* @throws InterpreteurException si arguments non vide
|
||||
*/
|
||||
public InstructionStop(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
if (!arguments.isBlank())
|
||||
throw new InterpreteurException(ERREUR_ARGUMENTS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Non - javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#executer()
|
||||
*/
|
||||
@Override
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR_REFERENCEMENT = "Le programme doit être référencé "
|
||||
+ "dans la classe commande";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR_REFERENCEMENT);
|
||||
}
|
||||
|
||||
programmeGlobal.stop();
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Non - javadoc
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "stop";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* InstructionVaen.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
|
||||
/**
|
||||
* Instruction qui transfère l'execution au numéro étiquette spécifié.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class InstructionVaen extends Instruction {
|
||||
|
||||
/** Etiquette à laquelle le programme doit se rendre */
|
||||
private Etiquette etiquette;
|
||||
|
||||
/**
|
||||
* Initialise un saut de ligne avec une étiquette en argument.
|
||||
* @param arguments Etiquette à laquelle le programme doit se rendre
|
||||
* @param contexte Contexte de la session de l'interpreteur LIR
|
||||
*/
|
||||
public InstructionVaen(String arguments, Contexte contexte) {
|
||||
super(arguments, contexte);
|
||||
|
||||
final String ERREUR_ARG = "vaen attend une étiquette en argument";
|
||||
|
||||
if (arguments.isBlank()) {
|
||||
throw new InterpreteurException(ERREUR_ARG);
|
||||
}
|
||||
|
||||
this.etiquette = new Etiquette(arguments);
|
||||
}
|
||||
|
||||
/* non javadoc -
|
||||
* @see interpreteurlir.motscles.instructions.Instruction#toString()
|
||||
* */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "vaen " + etiquette;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execution de l'instruction :
|
||||
* Realise un saut a l'étiquette spécifiée.
|
||||
* L'appel s'empile sur le contexte appellant pour ce qui est du
|
||||
* compteur ordinal.
|
||||
* @return false car aucun feedback affiché directement
|
||||
* @throws RuntimeException si un programme n'est pas référencé en membre
|
||||
* de classe de Commande.
|
||||
*/
|
||||
public boolean executer() {
|
||||
|
||||
final String ERREUR = "erreur exécution";
|
||||
|
||||
if (programmeGlobal == null) {
|
||||
throw new RuntimeException(ERREUR);
|
||||
}
|
||||
|
||||
programmeGlobal.vaen(etiquette);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,7 +23,8 @@ import interpreteurlir.expressions.ExpressionChaine;
|
||||
public class InstructionVar extends Instruction {
|
||||
|
||||
/**
|
||||
* TODO comment initial state of the object
|
||||
* Initialise une instruction var à partir de arguments.
|
||||
* Le contexte sera modifié à l'exécution dde l'instruction.
|
||||
* @param arguments expression à exécuter
|
||||
* @param contexte global de l'interpréteur
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* TestInstructionAffiche.java 13 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.motscles.instructions.InstructionAffiche;
|
||||
|
||||
|
||||
/**
|
||||
* Tests unitaires de l'instruction affiche, avec et sans arguments.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestInstructionAffiche {
|
||||
|
||||
/** Contexte d'execution pour jeux de tests */
|
||||
private static final Contexte CONTEXTE_GBL = new Contexte();
|
||||
|
||||
/** Jeu données valides pour test de InstructionAffiche */
|
||||
private static final InstructionAffiche[] FIXTURE = {
|
||||
new InstructionAffiche("", CONTEXTE_GBL),
|
||||
new InstructionAffiche(" ", CONTEXTE_GBL),
|
||||
new InstructionAffiche("\"Hello World !!!\"", CONTEXTE_GBL),
|
||||
new InstructionAffiche("3 + 3", CONTEXTE_GBL),
|
||||
new InstructionAffiche("marcel", CONTEXTE_GBL),
|
||||
new InstructionAffiche("marcel + -3", CONTEXTE_GBL),
|
||||
new InstructionAffiche("$fraysse", CONTEXTE_GBL),
|
||||
new InstructionAffiche("$sanchis + \"coucou\"", CONTEXTE_GBL),
|
||||
new InstructionAffiche("\"300000000000000000 ça passe\"", CONTEXTE_GBL)
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires de
|
||||
* {@link InstructionAffiche#InstructionAffiche(String, Contexte)}
|
||||
*/
|
||||
public static void testInstructionAffiche() {
|
||||
|
||||
final String[] INVALIDES = {
|
||||
"a = b + c",
|
||||
"3 +",
|
||||
"une chaine de plus de soixtante quinze caractères ne devrait pas"
|
||||
+ "pouvoir s'afficher parce qu'elle est trop longue !",
|
||||
"30000000000000000000000",
|
||||
"12aveyron",
|
||||
"$aveyron + 12"
|
||||
};
|
||||
|
||||
Expression.referencerContexte(CONTEXTE_GBL);
|
||||
System.out.println("Exécution du test de InstructionAffiche(String"
|
||||
+ ", Contexte)");
|
||||
for (String argInvalide : INVALIDES) {
|
||||
try {
|
||||
new InstructionAffiche(argInvalide, CONTEXTE_GBL);
|
||||
echec();
|
||||
} catch (InterpreteurException | ExecutionException lancee) {
|
||||
// Empty body
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionAffiche#executer()}
|
||||
*/
|
||||
public static void testExecuter() {
|
||||
|
||||
System.out.println("Exécution du test de executer()\nTEST VISUEL SUR "
|
||||
+ "CONSOLE :");
|
||||
|
||||
Expression.referencerContexte(CONTEXTE_GBL);
|
||||
for (InstructionAffiche aLancer : FIXTURE)
|
||||
aLancer.executer();
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionAffiche#toString()}
|
||||
*/
|
||||
public static void testToString() {
|
||||
|
||||
final String[] ATTENDUS = {
|
||||
"affiche",
|
||||
"affiche",
|
||||
"affiche \"Hello World !!!\"",
|
||||
"affiche 3 + 3",
|
||||
"affiche marcel",
|
||||
"affiche marcel + -3",
|
||||
"affiche $fraysse",
|
||||
"affiche $sanchis + \"coucou\"",
|
||||
"affiche \"300000000000000000 ça passe\""
|
||||
};
|
||||
|
||||
System.out.println("Exécution du test de toString()");
|
||||
for (int i = 0 ; i < FIXTURE.length ; i++) {
|
||||
assertTrue(FIXTURE[i].toString().compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* TestInstructionEntre.java 13 mai 2021
|
||||
* IUT Rodez info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import interpreteurlir.motscles.instructions.InstructionEntre;
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.litteraux.Entier;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
/**
|
||||
* Test unitaire de {@link InstructionEntre}
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestInstructionEntre {
|
||||
|
||||
/**
|
||||
* Contexte pour les tests
|
||||
*/
|
||||
private final Contexte CONTEXTE_GLB = new Contexte();
|
||||
|
||||
/**
|
||||
* Jeux de données de instructionEntre valides
|
||||
*/
|
||||
private InstructionEntre[] fixture = {
|
||||
new InstructionEntre("$chaine ", CONTEXTE_GLB),
|
||||
new InstructionEntre(" $toto", CONTEXTE_GLB),
|
||||
new InstructionEntre("\t entier ", CONTEXTE_GLB),
|
||||
new InstructionEntre("resultat", CONTEXTE_GLB),
|
||||
};
|
||||
|
||||
/**
|
||||
* Test unitaire de
|
||||
* {@link InstructionEntre#InstructionEntre(String, Contexte)}
|
||||
*/
|
||||
public void testInstructionEntreStringContexte() {
|
||||
|
||||
System.out.println("\tExécution du test de "
|
||||
+ "InstructionEntre#InstructionEntre(String, Contexte)");
|
||||
|
||||
final Contexte CONTEXTE = new Contexte();
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
"",
|
||||
"$hhjdkeliyehozrbnjkm236khl749k",
|
||||
"$chaine = $toto + \"\"",
|
||||
"entier/2",
|
||||
"45"
|
||||
};
|
||||
|
||||
|
||||
for (String arg : ARGS_INVALIDES) {
|
||||
|
||||
try {
|
||||
new InstructionEntre(arg, CONTEXTE);
|
||||
echec();
|
||||
|
||||
} catch (InterpreteurException lancee) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
new InstructionEntre("$chaine ", CONTEXTE);
|
||||
new InstructionEntre(" $toto", CONTEXTE);
|
||||
new InstructionEntre("\t entier ", CONTEXTE);
|
||||
new InstructionEntre("resultat", CONTEXTE);
|
||||
} catch (InterpreteurException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de {@link InstructionEntre#toString()}
|
||||
*/
|
||||
public void testToString() {
|
||||
|
||||
final String[] TEXTE_ATTENDU = {
|
||||
"entre $chaine", "entre $toto", "entre entier", "entre resultat"
|
||||
};
|
||||
|
||||
System.out.println("\tExécution du test de "
|
||||
+ "InstructionEntre#toString()");
|
||||
|
||||
for (int numTest = 0 ; numTest < TEXTE_ATTENDU.length ; numTest++) {
|
||||
assertEquivalence(TEXTE_ATTENDU[numTest],
|
||||
fixture[numTest].toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de {@link InstructionEntre#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
System.out.println("Execution du test de InstructionEntre#executer()");
|
||||
|
||||
for (InstructionEntre entre : fixture) {
|
||||
|
||||
System.out.println("? " + entre);
|
||||
try {
|
||||
assertFalse(entre.executer());
|
||||
System.out.println("ok");
|
||||
} catch (ExecutionException lancee) {
|
||||
System.err.println("nok : " + lancee.getMessage());
|
||||
}
|
||||
}
|
||||
System.out.println("Contexte : \n" + CONTEXTE_GLB);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* TestInstructionProcedure.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.instructions.InstructionProcedure;
|
||||
import interpreteurlir.motscles.instructions.InstructionVar;
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.IdentificateurEntier;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.programmes.*;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import info1.outils.glg.TestException;
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionProcedure}
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class TestInstructionProcedure {
|
||||
|
||||
/** Contexte global pour les tests */
|
||||
private final Contexte CONTEXTE = new Contexte();
|
||||
|
||||
/** Jeu de donnée d'InstructionProcedure valides */
|
||||
private final InstructionProcedure[] FIXTURE = {
|
||||
new InstructionProcedure(" 1 ", CONTEXTE),
|
||||
new InstructionProcedure(" 10", CONTEXTE),
|
||||
new InstructionProcedure("5 ", CONTEXTE),
|
||||
new InstructionProcedure("1549", CONTEXTE),
|
||||
new InstructionProcedure("99999", CONTEXTE)
|
||||
};
|
||||
|
||||
/** Programme utilisé dans les tests */
|
||||
private final Programme PROG_REFERENCE = new Programme();
|
||||
|
||||
/**
|
||||
* Tests unitaires de
|
||||
* {@link InstructionProcedure#InstructionProcedure(String, Contexte)}
|
||||
*/
|
||||
public void testInstructionProcedureStringContexte() {
|
||||
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionProcedure"
|
||||
+ "#InstructionProcedure(String, Contexte)");
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
/* Sans arguments */
|
||||
"",
|
||||
"\t",
|
||||
" ",
|
||||
"\n",
|
||||
|
||||
/* Arguments invalides */
|
||||
"LETTRE",
|
||||
"6messages",
|
||||
"-5",
|
||||
"100000"
|
||||
};
|
||||
|
||||
for (int i = 0 ; i < ARGS_INVALIDES.length ; i++) {
|
||||
try {
|
||||
new InstructionProcedure(ARGS_INVALIDES[i], CONTEXTE);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new InstructionProcedure(" 1 ", CONTEXTE);
|
||||
new InstructionProcedure(" 10", CONTEXTE);
|
||||
new InstructionProcedure("5 ", CONTEXTE);
|
||||
new InstructionProcedure("1549", CONTEXTE);
|
||||
new InstructionProcedure("99999", CONTEXTE);
|
||||
} catch (InterpreteurException e) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionProcedure#toString()}
|
||||
*/
|
||||
public void testToString() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionProcedure#toString()");
|
||||
|
||||
final String[] FORMAT_ATTENDU = {
|
||||
"procedure 1",
|
||||
"procedure 10",
|
||||
"procedure 5",
|
||||
"procedure 1549",
|
||||
"procedure 99999",
|
||||
};
|
||||
|
||||
for (int i = 0 ; i < FORMAT_ATTENDU.length ; i++) {
|
||||
assertEquivalence(FORMAT_ATTENDU[i], FIXTURE[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionProcedure#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionProcedure#executer()");
|
||||
|
||||
for(InstructionProcedure instruction : FIXTURE) {
|
||||
try {
|
||||
instruction.executer();
|
||||
echec();
|
||||
} catch (RuntimeException e) {
|
||||
if (e instanceof TestException) {
|
||||
echec();
|
||||
}
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
Commande.referencerProgramme(PROG_REFERENCE);
|
||||
Expression.referencerContexte(CONTEXTE);
|
||||
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(3),
|
||||
new InstructionVar("test=5", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(4), FIXTURE[1]);
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(5),
|
||||
new InstructionVar("test=-1", CONTEXTE));
|
||||
|
||||
PROG_REFERENCE.lancer();
|
||||
assertEquivalence(CONTEXTE.lireValeurVariable(
|
||||
new IdentificateurEntier("test")).getValeur(), 5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* TestInstructionRetour.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.instructions.InstructionProcedure;
|
||||
import interpreteurlir.motscles.instructions.InstructionRetour;
|
||||
import interpreteurlir.motscles.instructions.InstructionVar;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.IdentificateurEntier;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import info1.outils.glg.TestException;
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionRetour}
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class TestInstructionRetour {
|
||||
|
||||
/** Contexte global pour les tests */
|
||||
private final Contexte CONTEXTE = new Contexte();
|
||||
|
||||
/** Programme utilisé dans les tests */
|
||||
private final Programme PROG_REFERENCE = new Programme();
|
||||
|
||||
/** Jeu de donnée d'InstructionRetour valides */
|
||||
private final InstructionRetour[] FIXTURE = {
|
||||
new InstructionRetour("", CONTEXTE),
|
||||
new InstructionRetour(" ", CONTEXTE),
|
||||
new InstructionRetour("\t", CONTEXTE),
|
||||
new InstructionRetour("\t ", CONTEXTE)
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires de
|
||||
* {@link InstructionRetour#InstructionRetour(String, Contexte)}
|
||||
*/
|
||||
public void testInstructionRetourStringContexte() {
|
||||
System.out.println("\t Exécution du test de "
|
||||
+ "InstructionRetour#InstructionRetour(String, Contexte)");
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
" a ",
|
||||
"bonjour bonsoir",
|
||||
"513",
|
||||
"@!?/",
|
||||
"^p65Na@"
|
||||
};
|
||||
|
||||
for (int i = 0 ; i < ARGS_INVALIDES.length ; i++) {
|
||||
try {
|
||||
new InstructionRetour(ARGS_INVALIDES[i], CONTEXTE);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
new InstructionRetour("", CONTEXTE);
|
||||
new InstructionRetour(" ", CONTEXTE);
|
||||
new InstructionRetour("\t", CONTEXTE);
|
||||
new InstructionRetour("\t ", CONTEXTE);
|
||||
} catch (InterpreteurException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionRetour#toString()}
|
||||
*/
|
||||
public void testToString() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionRetour#toString()");
|
||||
|
||||
for (int i = 0 ; i < FIXTURE.length ; i++) {
|
||||
assertEquivalence("retour", FIXTURE[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionRetour#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionRetour#executer()");
|
||||
|
||||
for(InstructionRetour instruction : FIXTURE) {
|
||||
try {
|
||||
instruction.executer();
|
||||
echec();
|
||||
} catch (RuntimeException e) {
|
||||
if (e instanceof TestException) {
|
||||
echec();
|
||||
}
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
Commande.referencerProgramme(PROG_REFERENCE);
|
||||
Expression.referencerContexte(CONTEXTE);
|
||||
|
||||
/* Test retour procedure invalide */
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(1), FIXTURE[0]);
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(4),
|
||||
new InstructionProcedure("1", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(10), FIXTURE[1]);
|
||||
|
||||
try {
|
||||
PROG_REFERENCE.lancer(new Etiquette(2));
|
||||
echec();
|
||||
} catch (ExecutionException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
|
||||
PROG_REFERENCE.raz();
|
||||
|
||||
/* Tests retour procedure valide */
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(1),
|
||||
new InstructionVar("test=5", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(2), FIXTURE[0]);
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(3),
|
||||
new InstructionVar("test=-1", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(4),
|
||||
new InstructionProcedure("1", CONTEXTE));
|
||||
|
||||
PROG_REFERENCE.lancer(new Etiquette(3));
|
||||
assertEquivalence(CONTEXTE.lireValeurVariable(
|
||||
new IdentificateurEntier("test")).getValeur(), 5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* TestInstructionStop.java 16 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.instructions.InstructionAffiche;
|
||||
import interpreteurlir.motscles.instructions.InstructionStop;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
/**
|
||||
* Tests unitaires de l'instruction stop de l'interpréteur LIR.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestInstructionStop {
|
||||
|
||||
/** Contexte d'exécution nécessaire à instanciation */
|
||||
private static final Contexte CONTEXTE_TESTS = new Contexte();
|
||||
|
||||
/** Instruction stop valide */
|
||||
public static final InstructionStop[] FIXTURE = {
|
||||
new InstructionStop("", CONTEXTE_TESTS),
|
||||
new InstructionStop("\t", CONTEXTE_TESTS),
|
||||
new InstructionStop(" ", CONTEXTE_TESTS)
|
||||
};
|
||||
/** Tests du constructeur */
|
||||
public static void testInstructionStop() {
|
||||
|
||||
final String[] INVALIDES = {
|
||||
"coucou",
|
||||
" Bonjour",
|
||||
null,
|
||||
"entier = 2 + 3"
|
||||
};
|
||||
|
||||
System.out.println("Exécution du test de InstructionStop"
|
||||
+ "(String, Contexte)");
|
||||
for (String aTester : INVALIDES) {
|
||||
try {
|
||||
new InstructionStop(aTester, CONTEXTE_TESTS);
|
||||
echec();
|
||||
} catch (InterpreteurException | NullPointerException e) {
|
||||
// Empty block
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Test de executer() */
|
||||
public static void testExecuter() {
|
||||
Programme pgmTest = new Programme();
|
||||
System.out.println("Exécution du test de executer()\ntestVisuel\n");
|
||||
Commande.referencerProgramme(pgmTest);
|
||||
Expression.referencerContexte(CONTEXTE_TESTS);
|
||||
pgmTest.ajouterLigne(new Etiquette(10),
|
||||
new InstructionAffiche("Bonjour", CONTEXTE_TESTS));
|
||||
pgmTest.ajouterLigne(new Etiquette(20),
|
||||
new InstructionAffiche("Comment", CONTEXTE_TESTS));
|
||||
pgmTest.ajouterLigne(new Etiquette(30),
|
||||
new InstructionAffiche("Allez", CONTEXTE_TESTS));
|
||||
pgmTest.ajouterLigne(new Etiquette(40),
|
||||
new InstructionAffiche("Vous", CONTEXTE_TESTS));
|
||||
pgmTest.ajouterLigne(new Etiquette(45),
|
||||
new InstructionStop("", CONTEXTE_TESTS));
|
||||
pgmTest.ajouterLigne(new Etiquette(50),
|
||||
new InstructionAffiche("foobar", CONTEXTE_TESTS));
|
||||
System.out.println(pgmTest);
|
||||
System.out.println("lancement du programme : ne doit pas "
|
||||
+ "afficher foobar");
|
||||
pgmTest.lancer();
|
||||
}
|
||||
|
||||
/** Tests de toString() */
|
||||
public static void testToString() {
|
||||
|
||||
final String ATTENDUE = "stop";
|
||||
System.out.println("Exécution du test de toString()");
|
||||
for (InstructionStop valide : FIXTURE)
|
||||
assertTrue(valide.toString().compareTo(ATTENDUE) == 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* TestInstructionVaen.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.instructions.tests;
|
||||
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.instructions.InstructionAffiche;
|
||||
import interpreteurlir.motscles.instructions.InstructionVaen;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import info1.outils.glg.TestException;
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionVaen}
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*
|
||||
*/
|
||||
public class TestInstructionVaen {
|
||||
|
||||
/** Contexte global pour les tests */
|
||||
private final Contexte CONTEXTE = new Contexte();
|
||||
|
||||
/** Programme utilisé dans les tests */
|
||||
private final Programme PROG_REFERENCE = new Programme();
|
||||
|
||||
/** Jeu de donnée d'InstructionRetour valides */
|
||||
private final InstructionVaen[] FIXTURE = {
|
||||
new InstructionVaen("10", CONTEXTE),
|
||||
new InstructionVaen("9", CONTEXTE),
|
||||
new InstructionVaen("20", CONTEXTE),
|
||||
new InstructionVaen("70", CONTEXTE),
|
||||
new InstructionVaen("40", CONTEXTE),
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires de
|
||||
* {@link InstructionVaen#InstructionVaen(String, Contexte)}
|
||||
*/
|
||||
public void testInstructionVaenStringContexte() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionVaen#InstructionVaen(String, Contexte)");
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
"greuuuuuu",
|
||||
" motus 5800",
|
||||
"100000",
|
||||
"-4",
|
||||
"$$$$£££"
|
||||
};
|
||||
|
||||
Expression.referencerContexte(CONTEXTE);
|
||||
|
||||
/* Cas invalides */
|
||||
for (int i = 0; i < ARGS_INVALIDES.length; i++) {
|
||||
try {
|
||||
new InstructionVaen(ARGS_INVALIDES[i], CONTEXTE);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
/* Cas Valides */
|
||||
try {
|
||||
new InstructionVaen("10", CONTEXTE);
|
||||
new InstructionVaen("9", CONTEXTE);
|
||||
new InstructionVaen("20", CONTEXTE);
|
||||
new InstructionVaen("70", CONTEXTE);
|
||||
new InstructionVaen("40", CONTEXTE);
|
||||
} catch (InterpreteurException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionVaen#toString()}
|
||||
*/
|
||||
public void testToString() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionVaen#toString()");
|
||||
|
||||
final String[] FORMAT_ATTENDU = {
|
||||
"vaen 10",
|
||||
"vaen 9",
|
||||
"vaen 20",
|
||||
"vaen 70",
|
||||
"vaen 40"
|
||||
};
|
||||
|
||||
for (int i = 0 ; i < FORMAT_ATTENDU.length ; i++) {
|
||||
assertEquivalence(FORMAT_ATTENDU[i], FIXTURE[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link InstructionVaen#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
System.out.println("\tExecution du test de "
|
||||
+ "InstructionVaen#executer()");
|
||||
|
||||
/* Cas invalide : où le programme global est vide */
|
||||
for(InstructionVaen instruction : FIXTURE) {
|
||||
try {
|
||||
instruction.executer();
|
||||
echec();
|
||||
} catch (RuntimeException e) {
|
||||
if (e instanceof TestException) {
|
||||
echec();
|
||||
}
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
/* Cas valide */
|
||||
Commande.referencerProgramme(PROG_REFERENCE);
|
||||
Expression.referencerContexte(CONTEXTE);
|
||||
|
||||
System.out.println("Test visuel : Ne doit pas afficher "
|
||||
+ "les étiquettes (25, 31, 40 )");
|
||||
/* 1,10,13 -> 78, 89 (saute 25, 31, 40) */
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(1),
|
||||
new InstructionAffiche("\"1 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(10),
|
||||
new InstructionAffiche("\"10 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(13),
|
||||
new InstructionAffiche("\"13 \"", CONTEXTE));
|
||||
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(25),
|
||||
new InstructionAffiche("\"25 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(31),
|
||||
new InstructionAffiche("\"31 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(40),
|
||||
new InstructionAffiche("\"40 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(78),
|
||||
new InstructionAffiche("\"78 \"", CONTEXTE));
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(89),
|
||||
new InstructionAffiche("\"89 \"", CONTEXTE));
|
||||
|
||||
PROG_REFERENCE.ajouterLigne(new Etiquette(14),
|
||||
new InstructionVaen("78", CONTEXTE));
|
||||
|
||||
PROG_REFERENCE.lancer();
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@ public class TestInstructionVar {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO comment method responsibilities
|
||||
* Lancement des tests
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -7,7 +7,9 @@ package interpreteurlir.motscles.tests;
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link interpreteurlir.motscles.Commande}
|
||||
@@ -26,6 +28,26 @@ public class TestCommande {
|
||||
new Commande("$chaine = \"toto\" + $tata", new Contexte())
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link Commande#referencerProgramme(Programme)}
|
||||
*/
|
||||
public void testReferencerProgramme() {
|
||||
|
||||
Programme reference = new Programme();
|
||||
Programme[] programmes = {
|
||||
null, reference, reference, new Programme()
|
||||
};
|
||||
|
||||
boolean[] resultatAttendu = { false, true, true, false };
|
||||
|
||||
System.out.println("\tExécution du test de "
|
||||
+ "Commande#referencerProgramme(Programme)");
|
||||
for (int numTest = 0 ; numTest < programmes.length ; numTest++) {
|
||||
assertTrue( Commande.referencerProgramme(programmes[numTest])
|
||||
== resultatAttendu[numTest]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unitaires de {@link Commande#Commande(String, Contexte)}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* TestCommandeEfface.java 16 mai 2021
|
||||
* IUT info1 2020-2021, pas de copyright, aucun droit
|
||||
*/
|
||||
package interpreteurlir.motscles.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.CommandeEfface;
|
||||
import interpreteurlir.motscles.instructions.InstructionAffiche;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
/**
|
||||
* Tests unitaires de la commande d'effacement de lignes de codes pour
|
||||
* l'interpréteur LIR.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heïa Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestCommandeEfface {
|
||||
|
||||
/** Contexte pour tests */
|
||||
public static final Contexte CONTEXTE_TESTS = new Contexte();
|
||||
|
||||
/** Programme global pour tests */
|
||||
public static final Programme PGM_TESTS = new Programme();
|
||||
|
||||
/** Jeu de test valide */
|
||||
public static final CommandeEfface[] FIXTURE = {
|
||||
new CommandeEfface("1:99999", CONTEXTE_TESTS),
|
||||
new CommandeEfface(" 1 : 99999 ", CONTEXTE_TESTS),
|
||||
new CommandeEfface("99999 :1 ", CONTEXTE_TESTS),
|
||||
new CommandeEfface("1 : 1", CONTEXTE_TESTS),
|
||||
new CommandeEfface(" 250: 150 ", CONTEXTE_TESTS)
|
||||
};
|
||||
|
||||
/** Test du constructeur */
|
||||
public static void testCommandeEfface() {
|
||||
|
||||
final String[] INVALIDES = {
|
||||
"",
|
||||
"23 : ",
|
||||
" : 15",
|
||||
"coucou",
|
||||
"50 : coucou",
|
||||
"12.4: 24",
|
||||
"-14 : 90",
|
||||
"\'a\' : 99"
|
||||
};
|
||||
|
||||
System.out.println("Exécution du test de CommandeEfface"
|
||||
+ "(String, Contexte)");
|
||||
for (String aTester : INVALIDES) {
|
||||
try {
|
||||
new CommandeEfface(aTester, CONTEXTE_TESTS);
|
||||
echec();
|
||||
} catch (InterpreteurException e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Test de executer() */
|
||||
public static void testExecuter() {
|
||||
|
||||
System.out.println("Exécution du test d'executer()\nTest visuel :");
|
||||
Commande.referencerProgramme(PGM_TESTS);
|
||||
PGM_TESTS.ajouterLigne(new Etiquette(10),
|
||||
new InstructionAffiche("Bonjour", CONTEXTE_TESTS));
|
||||
PGM_TESTS.ajouterLigne(new Etiquette(20),
|
||||
new InstructionAffiche("Comment", CONTEXTE_TESTS));
|
||||
PGM_TESTS.ajouterLigne(new Etiquette(30),
|
||||
new InstructionAffiche("Allez", CONTEXTE_TESTS));
|
||||
PGM_TESTS.ajouterLigne(new Etiquette(40),
|
||||
new InstructionAffiche("Vous", CONTEXTE_TESTS));
|
||||
PGM_TESTS.ajouterLigne(new Etiquette(50),
|
||||
new InstructionAffiche("foobar", CONTEXTE_TESTS));
|
||||
System.out.println(PGM_TESTS);
|
||||
|
||||
CommandeEfface effacement = new CommandeEfface("20:30", CONTEXTE_TESTS);
|
||||
effacement.executer();
|
||||
|
||||
System.out.println(PGM_TESTS);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* TestCommandeLance.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.tests;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.motscles.CommandeLance;
|
||||
import interpreteurlir.motscles.instructions.Instruction;
|
||||
import interpreteurlir.motscles.instructions.InstructionVar;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import info1.outils.glg.TestException;
|
||||
|
||||
/**
|
||||
* Tests unitaires de la classe CommandeLance
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestCommandeLance {
|
||||
|
||||
private Contexte contexteTest = new Contexte();
|
||||
private Programme programmeTest = new Programme();
|
||||
|
||||
private final CommandeLance[] FIXTURE = {
|
||||
new CommandeLance("", contexteTest),
|
||||
new CommandeLance("10", contexteTest),
|
||||
new CommandeLance("9", contexteTest),
|
||||
new CommandeLance("20", contexteTest),
|
||||
new CommandeLance("70", contexteTest),
|
||||
new CommandeLance("40", contexteTest),
|
||||
};
|
||||
|
||||
private final String[] ARGS_VALIDES = {
|
||||
"",
|
||||
"10",
|
||||
"9",
|
||||
"20",
|
||||
"70",
|
||||
"40"
|
||||
};
|
||||
|
||||
private final Etiquette[] JEU_ETIQUETTES = {
|
||||
new Etiquette(1),
|
||||
new Etiquette(10),
|
||||
new Etiquette(13),
|
||||
new Etiquette(25),
|
||||
new Etiquette(31),
|
||||
new Etiquette(40),
|
||||
new Etiquette(78),
|
||||
new Etiquette(89)
|
||||
};
|
||||
|
||||
private final Instruction[] JEU_INSTRUCTIONS = {
|
||||
new InstructionVar("$res = \"1 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"10 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"13 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"25 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"31 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"40 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"78 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"89 \"", contexteTest)
|
||||
};
|
||||
|
||||
private void ecrireProgrammeTest() {
|
||||
for (int i = 0 ; i < JEU_ETIQUETTES.length ; i++) {
|
||||
programmeTest.ajouterLigne(JEU_ETIQUETTES[i],
|
||||
JEU_INSTRUCTIONS[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test unitaire de
|
||||
* {@link CommandeLance#CommandeLance(String, interpreteurlir.Contexte)}
|
||||
*/
|
||||
public void testCommandeLance() {
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
"greuuuuuu",
|
||||
" motus 5800",
|
||||
"100000",
|
||||
"-4",
|
||||
"$$$$£££"
|
||||
};
|
||||
|
||||
Expression.referencerContexte(contexteTest);
|
||||
|
||||
for (int i = 0; i < ARGS_INVALIDES.length; i++) {
|
||||
try {
|
||||
new CommandeLance(ARGS_INVALIDES[i], contexteTest);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < ARGS_VALIDES.length ; i++) {
|
||||
try {
|
||||
contexteTest.raz();
|
||||
new CommandeLance(ARGS_VALIDES[i], contexteTest);
|
||||
} catch (InterpreteurException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de {@link CommandeLance#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
|
||||
//ecrireProgrammeTest();
|
||||
Expression.referencerContexte(contexteTest);
|
||||
|
||||
for (int i = 0 ; i < FIXTURE.length ; i++) {
|
||||
try {
|
||||
FIXTURE[i].executer();
|
||||
echec();
|
||||
} catch (RuntimeException lancee) {
|
||||
if (lancee instanceof TestException) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tests valides faits en intégration
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* TestCommandeListe.java 15 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.motscles.tests;
|
||||
|
||||
import interpreteurlir.Contexte;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.expressions.Expression;
|
||||
import interpreteurlir.motscles.Commande;
|
||||
import interpreteurlir.motscles.CommandeListe;
|
||||
import interpreteurlir.motscles.instructions.Instruction;
|
||||
import interpreteurlir.motscles.instructions.InstructionVar;
|
||||
import interpreteurlir.programmes.Etiquette;
|
||||
import interpreteurlir.programmes.Programme;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import info1.outils.glg.TestException;
|
||||
|
||||
/**
|
||||
* Tests unitaires de la classe Commande liste
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestCommandeListe {
|
||||
|
||||
private Programme programmeTest = new Programme();
|
||||
private Contexte contexteTest = new Contexte();
|
||||
|
||||
private final CommandeListe[] FIXTURE = {
|
||||
new CommandeListe("1:89", contexteTest),
|
||||
new CommandeListe("13:30", contexteTest),
|
||||
new CommandeListe("17:54", contexteTest),
|
||||
new CommandeListe("40:108", contexteTest),
|
||||
};
|
||||
|
||||
private final String[] ARGS_VALIDES = {
|
||||
"1:90",
|
||||
"5:45",
|
||||
"40:56"
|
||||
};
|
||||
|
||||
private final Etiquette[] JEU_ETIQUETTES = {
|
||||
new Etiquette(1),
|
||||
new Etiquette(10),
|
||||
new Etiquette(13),
|
||||
new Etiquette(25),
|
||||
new Etiquette(31),
|
||||
new Etiquette(40),
|
||||
new Etiquette(78),
|
||||
new Etiquette(89)
|
||||
};
|
||||
|
||||
private final Instruction[] JEU_INSTRUCTIONS = {
|
||||
new InstructionVar("$res = \"1 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"10 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"13 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"25 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"31 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"40 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"78 \"", contexteTest),
|
||||
new InstructionVar("$res = $res + \"89 \"", contexteTest)
|
||||
};
|
||||
|
||||
private void ecrireProgrammeTest() {
|
||||
for (int i = 0 ; i < JEU_ETIQUETTES.length ; i++) {
|
||||
programmeTest.ajouterLigne(JEU_ETIQUETTES[i],
|
||||
JEU_INSTRUCTIONS[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de
|
||||
* {@link CommandeListe#CommandeListe(String, interpreteurlir.Contexte)}
|
||||
*/
|
||||
public void testCommandeListe() {
|
||||
|
||||
final String[] ARGS_INVALIDES = {
|
||||
"agreu",
|
||||
"0:0",
|
||||
"-4:9",
|
||||
"45:-8",
|
||||
"78:12",
|
||||
"1:",
|
||||
":4",
|
||||
"1:100000"
|
||||
};
|
||||
|
||||
for (int i = 0; i < ARGS_INVALIDES.length; i++) {
|
||||
try {
|
||||
new CommandeListe(ARGS_INVALIDES[i], contexteTest);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < ARGS_VALIDES.length ; i++) {
|
||||
try {
|
||||
new CommandeListe(ARGS_VALIDES[i], contexteTest);
|
||||
} catch (InterpreteurException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de {@link CommandeListe#executer()}
|
||||
*/
|
||||
public void testExecuter() {
|
||||
|
||||
for (int i = 0 ; i < FIXTURE.length ; i++) {
|
||||
try {
|
||||
FIXTURE[i].executer();
|
||||
echec();
|
||||
} catch (RuntimeException lancee) {
|
||||
if (lancee instanceof TestException) {
|
||||
echec();
|
||||
}
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
ecrireProgrammeTest();
|
||||
Commande.referencerProgramme(programmeTest);
|
||||
Expression.referencerContexte(contexteTest);
|
||||
|
||||
for (int i = 0 ; i < FIXTURE.length ; i++) {
|
||||
try {
|
||||
FIXTURE[i].executer();
|
||||
} catch (RuntimeException lancee) {
|
||||
echec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user