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:
@@ -17,97 +17,75 @@ import interpreteurlir.InterpreteurException;
|
||||
*/
|
||||
public class Identificateur /* extends Variable */
|
||||
implements Comparable<Identificateur> {
|
||||
|
||||
|
||||
/** Longueur maximale d'un identificateur (ne prend pas en compte le $) */
|
||||
public static final int LONGUEUR_MAX = 24;
|
||||
|
||||
/** Nom identificateur */
|
||||
public static final int LONGUEUR_MAX = 25;
|
||||
|
||||
/** Nom identificateur */
|
||||
private String nom;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiation de l'identificateur
|
||||
* @param identificateur
|
||||
*/
|
||||
public Identificateur(String identificateur) {
|
||||
super();
|
||||
if(!isIdentificateur(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur");
|
||||
}
|
||||
|
||||
nom = identificateur;
|
||||
public Identificateur(String identificateur) {
|
||||
super();
|
||||
identificateur = identificateur.trim();
|
||||
if(!isIdentificateur(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat qui vérifie si une chaîne correspond à un identificateur
|
||||
* <ul>
|
||||
* <li>Longueur comprise entre 1 et 24 caractères</li>
|
||||
* <li>N'est pas une chaîne vide</li>
|
||||
* <li>N'est pas null</li>
|
||||
* </ul>
|
||||
* @param aComparer
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isIdentificateur(String aComparer) {
|
||||
return aComparer != null
|
||||
&& aComparer.length() > 0
|
||||
&& !removeDollar(aComparer).isBlank()
|
||||
&& removeDollar(aComparer).length() <= LONGUEUR_MAX
|
||||
&& isAlphanumerique(removeDollar(aComparer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime le caractère $ si il est présent en premier dans la chaîne
|
||||
* @param chaine a modifier
|
||||
* @return la chaîne modifiée
|
||||
*/
|
||||
public static String removeDollar(String chaine) {
|
||||
if(chaine.charAt(0) == '$') return chaine.substring(1);
|
||||
return chaine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat testant si une chaîne est composée de chiffre ou de lettres
|
||||
* @param aTester chaîne a tester
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isAlphanumerique(String aTester) {
|
||||
int index;
|
||||
|
||||
for (index = 0 ;
|
||||
index < aTester.length()
|
||||
&& (isLettre(aTester.charAt(index))
|
||||
|| isChiffre(aTester.charAt(index)));
|
||||
index++)
|
||||
; // Corps vide
|
||||
|
||||
return index >= aTester.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant si un caractère est une lettre
|
||||
* @param aTester caractère a tester
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isLettre(char aTester) {
|
||||
return 'a' <= aTester && aTester <= 'z'
|
||||
|| 'A' <= aTester && aTester <= 'Z';
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant si un caractère est un chiffre
|
||||
* @param aTester caractère a tester
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isChiffre(char aTester) {
|
||||
return '0' <= aTester && aTester <= '9';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
nom = identificateur;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat qui vérifie si une chaîne correspond à un identificateur
|
||||
* <ul>
|
||||
* <li>Longueur comprise entre 1 et 24 caractères</li>
|
||||
* <li>N'est pas une chaîne vide</li>
|
||||
* <li>N'est pas null</li>
|
||||
* </ul>
|
||||
* @param aTester
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isIdentificateur(String aTester) {
|
||||
return aTester != null
|
||||
&& aTester.length() > 0
|
||||
&& !removeDollar(aTester).isBlank()
|
||||
&& removeDollar(aTester).length() <= LONGUEUR_MAX
|
||||
&& isAlphanumerique(removeDollar(aTester));
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprime le caractère $ si il est présent en premier dans la chaîne
|
||||
* @param chaine a modifier
|
||||
* @return la chaîne modifiée
|
||||
*/
|
||||
public static String removeDollar(String chaine) {
|
||||
if(chaine.charAt(0) == '$') return chaine.substring(1);
|
||||
return chaine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat testant si une chaîne est composée de chiffre ou de lettres
|
||||
* @param aTester chaîne a tester
|
||||
* @return true si le prédicat est vérifié
|
||||
* false sinon
|
||||
*/
|
||||
public static boolean isAlphanumerique(String aTester) {
|
||||
int index;
|
||||
for (index = 0 ;
|
||||
index < aTester.length()
|
||||
&& Character.isLetterOrDigit(aTester.charAt(index)) ;
|
||||
index++)
|
||||
; // Corps vide
|
||||
|
||||
return index >= aTester.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la valeur de nom
|
||||
*/
|
||||
public String getNom() {
|
||||
@@ -125,6 +103,4 @@ implements Comparable<Identificateur> {
|
||||
public int compareTo(Identificateur aComparer) {
|
||||
return nom.compareTo(aComparer.nom);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -19,31 +19,30 @@ import interpreteurlir.InterpreteurException;
|
||||
public class IdentificateurChaine extends Identificateur {
|
||||
|
||||
/**
|
||||
* Instantiation d'identificateur de chaîne
|
||||
* @param identificateur a instancier
|
||||
* @throws InterpreteurException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurChaine(String identificateur) {
|
||||
super(identificateur.trim());
|
||||
|
||||
identificateur = identificateur.trim();
|
||||
if(!isIdentificateurChaine(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " de chaine");
|
||||
}
|
||||
* Instantiation d'identificateur de chaîne
|
||||
* @param identificateur a instancier
|
||||
* @throws InterpreteurException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurChaine(String identificateur) {
|
||||
super(identificateur);
|
||||
identificateur = identificateur.trim();
|
||||
if(!isIdentificateurChaine(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " de chaine");
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant la validité de l'identificateur
|
||||
* @param identificateur à tester
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private static boolean isIdentificateurChaine(String identificateur) {
|
||||
}
|
||||
|
||||
return identificateur.length() >= 2
|
||||
&& identificateur.charAt(0) == '$'
|
||||
&& isLettre(identificateur.charAt(1));
|
||||
}
|
||||
/**
|
||||
* Prédicat attestant la validité de l'identificateur
|
||||
* @param identificateur à tester
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private static boolean isIdentificateurChaine(String identificateur) {
|
||||
|
||||
return identificateur.length() >= 2
|
||||
&& identificateur.charAt(0) == '$'
|
||||
&& Character.isLetter(identificateur.charAt(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ package interpreteurlir.donnees;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
|
||||
/**
|
||||
* Identificateur d'entier
|
||||
* Identificateur d'entier utilisé pour instancier des variables du même type.
|
||||
* Un identificateur entier commence par une lettre suivie d'au plus 24
|
||||
* caractère alphanumériques.
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
@@ -18,36 +20,37 @@ import interpreteurlir.InterpreteurException;
|
||||
*/
|
||||
public class IdentificateurEntier extends Identificateur {
|
||||
|
||||
/**
|
||||
* Instantiation d'identificateur d'entier
|
||||
* @param identificateur a instancier
|
||||
* @throws InterpreteurException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurEntier(String identificateur) {
|
||||
super(identificateur);
|
||||
|
||||
if(!isIdentificateurEntier(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " d'entier");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant la validité de l'identificateur
|
||||
*
|
||||
* Un identificateur d'entier est valide si
|
||||
* - Il contient au maximum 24 caractères
|
||||
* - Commence obligatoirement par une lettre (majuscule ou minuscule)
|
||||
* - suivie uniquement de lettres (majuscule ou minuscule) ou de chiffres
|
||||
*
|
||||
* @param identificateur à tester
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private static boolean isIdentificateurEntier(String identificateur) {
|
||||
|
||||
return isLettre(identificateur.charAt(0))
|
||||
&& isAlphanumerique(identificateur.substring(1));
|
||||
/**
|
||||
* Instantiation de cet identificateur d'entier avec le nom spécififié
|
||||
* en argument. Lève une exception si l'identificateur n'est pas
|
||||
* valide.
|
||||
* @param identificateur a instancier
|
||||
* @throws InterpreteurException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurEntier(String identificateur) {
|
||||
super(identificateur);
|
||||
|
||||
if(!isIdentificateurEntier(identificateur)) {
|
||||
throw new InterpreteurException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " d'entier");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant la validité de l'identificateur
|
||||
*
|
||||
* Un identificateur d'entier est valide si
|
||||
* - Il contient au maximum 24 caractères
|
||||
* - Commence obligatoirement par une lettre (majuscule ou minuscule)
|
||||
* - suivie uniquement de lettres (majuscule ou minuscule) ou de chiffres
|
||||
*
|
||||
* @param aTester à tester
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private static boolean isIdentificateurEntier(String aTester) {
|
||||
return aTester.length() <= 25 && Character.isLetter(aTester.charAt(0))
|
||||
&& isAlphanumerique(aTester.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package interpreteurlir.donnees;
|
||||
|
||||
import interpreteurlir.donnees.litteraux.Chaine;
|
||||
import interpreteurlir.donnees.litteraux.Entier;
|
||||
import interpreteurlir.donnees.litteraux.Litteral;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
|
||||
@@ -38,7 +39,7 @@ public class Variable extends Object implements Comparable<Variable> {
|
||||
if (!isVariable(identificateur, valeur)) {
|
||||
throw new InterpreteurException("Identificateur '"
|
||||
+ identificateur.toString()
|
||||
+ "' et type de "
|
||||
+ "' et type de "
|
||||
+ valeur.toString()
|
||||
+ "incompatible.");
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class Variable extends Object implements Comparable<Variable> {
|
||||
|
||||
private static boolean isVariable(Identificateur id, Litteral valeur) {
|
||||
return id instanceof IdentificateurChaine && valeur instanceof Chaine
|
||||
/* || id instanceof IdentificateurEntier && valeur instanceof Entier */;
|
||||
|| id instanceof IdentificateurEntier && valeur instanceof Entier;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ public class Chaine extends Litteral {
|
||||
public static final int LG_MAX_CHAINE = 70;
|
||||
|
||||
/** Erreur chaîne trop longue */
|
||||
private static final String ERREUR_LG_MAX = "Longueur maximale dépassée";
|
||||
private static final String ERREUR_LG_MAX =
|
||||
"Longueur maximale d'une chaîne dépassée";
|
||||
|
||||
/** Erreur constante littéral chaîne invalide */
|
||||
private static final String ERREUR_INVALIDE =
|
||||
@@ -69,7 +70,6 @@ public class Chaine extends Litteral {
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(Litteral autre) {
|
||||
// TODO Auto-generated method stub
|
||||
return this.valeur.toString().compareTo(autre.valeur.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,86 @@
|
||||
*/
|
||||
package interpreteurlir.donnees.litteraux;
|
||||
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
|
||||
/**
|
||||
* BOUCHON
|
||||
* @author
|
||||
*
|
||||
* Constante littérale de type entier
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class Entier extends Litteral {
|
||||
|
||||
private static final int LONG_CH_MAX = 11;
|
||||
|
||||
/** Valeur entière minimale */
|
||||
public static int VALEUR_MIN = Integer.MIN_VALUE;
|
||||
|
||||
/** TODO commenter l'état initial
|
||||
* @param i
|
||||
/** Valeur entière minimale */
|
||||
public static int VALEUR_MAX = Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Initialisation de cet entier avec une valeur passée en argument
|
||||
* @param unEntier
|
||||
* @throws InterpreteurException lorsque entier n'est pas un Entier
|
||||
*/
|
||||
public Entier(int i) {
|
||||
super(Integer.valueOf(i));
|
||||
// TODO Auto-generated constructor stub
|
||||
valeur = i;
|
||||
@SuppressWarnings("boxing")
|
||||
public Entier(int unEntier) {
|
||||
|
||||
if (! isEntier(unEntier)) {
|
||||
throw new InterpreteurException("Erreur. " + unEntier
|
||||
+ " n'est pas un entier. ");
|
||||
}
|
||||
super.valeur = unEntier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisation de cet entier avec une valeur passée en argument
|
||||
* @param uneValeur
|
||||
*/
|
||||
public Entier(String uneValeur) {
|
||||
if (!isEntier(uneValeur)) {
|
||||
throw new InterpreteurException(uneValeur
|
||||
+ " n'est pas un nombre entier. ");
|
||||
}
|
||||
|
||||
valeur = Integer.valueOf(uneValeur);
|
||||
}
|
||||
|
||||
private static boolean isEntier(String uneValeur) {
|
||||
if (uneValeur != null && !uneValeur.isBlank()
|
||||
&& uneValeur.length() <= LONG_CH_MAX
|
||||
&& (isChiffre(uneValeur.charAt(0))
|
||||
|| uneValeur.length() > 1 && (uneValeur.charAt(0) == '-'
|
||||
|| uneValeur.charAt(0) == '+'))) {
|
||||
int i;
|
||||
for (i = 1; i < uneValeur.length() && isChiffre(uneValeur.charAt(i));
|
||||
i++)
|
||||
; /* corps vide */
|
||||
if ((uneValeur.startsWith("+214748364")
|
||||
|| uneValeur.startsWith("214748364"))
|
||||
&& uneValeur.charAt(uneValeur.length() - 1) > '7'
|
||||
|| uneValeur.startsWith("-214748364")
|
||||
&& uneValeur.charAt(uneValeur.length() - 1) > '8'
|
||||
)
|
||||
return false;
|
||||
|
||||
return i >= uneValeur.length();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isChiffre(char caractere) {
|
||||
return '0' <= caractere && caractere <= '9';
|
||||
}
|
||||
|
||||
private static boolean isEntier(int entier) {
|
||||
return VALEUR_MIN <= entier && entier <= VALEUR_MAX;
|
||||
}
|
||||
|
||||
/* non javadoc
|
||||
@@ -28,7 +93,80 @@ public class Entier extends Litteral {
|
||||
public String toString() {
|
||||
return valeur.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Integer getValeur() {
|
||||
return (Integer) super.valeur;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare cet entier à un autre entier
|
||||
* @param autre
|
||||
* @return une valeur < 0 lorsque autre > cet entier
|
||||
* une valeur > 0 lorsque autre < cet entier
|
||||
* une valeur = 0 lorsque autre et cet entier sont égaux
|
||||
*/
|
||||
public int compareTo(Entier autre) {
|
||||
return ((Integer) valeur).compareTo(autre.getValeur());
|
||||
}
|
||||
|
||||
/**
|
||||
* Somme de deux entiers
|
||||
* @param premier Entier
|
||||
* @param second Entier
|
||||
* @return la somme des deux entiers
|
||||
*/
|
||||
public static Entier somme(Entier premier, Entier second) {
|
||||
return new Entier((int) premier.getValeur() + (int) second.getValeur());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Soustraction de deux entiers
|
||||
* @param premier Entier
|
||||
* @param second Entier
|
||||
* @return le résultat de premier auquel on soustrait second
|
||||
*/
|
||||
public static Entier soustrait(Entier premier, Entier second) {
|
||||
return new Entier((int) premier.getValeur() - (int) second.getValeur());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplication de deux entiers
|
||||
* @param premier Entier
|
||||
* @param second Entier
|
||||
* @return le résultat de premier multiplié par second
|
||||
*/
|
||||
public static Entier multiplie(Entier premier, Entier second) {
|
||||
return new Entier((int) premier.getValeur() * (int) second.getValeur());
|
||||
}
|
||||
|
||||
/**
|
||||
* Division de deux entiers
|
||||
* @param premier Entier
|
||||
* @param second Entier
|
||||
* @return le quotient de la division de premier par second
|
||||
* @throws ExecutionException lorsque le diviseur est nul
|
||||
*/
|
||||
public static Entier quotient(Entier premier, Entier second) {
|
||||
if (second.compareTo(new Entier (0)) == 0) {
|
||||
throw new ExecutionException("Erreur. Division par 0. ");
|
||||
}
|
||||
return new Entier((int) premier.getValeur() / (int) second.getValeur());
|
||||
}
|
||||
|
||||
/**
|
||||
* Division de deux entiers
|
||||
* @param premier Entier
|
||||
* @param second Entier
|
||||
* @return le reste de la division de premier par second
|
||||
* @throws ExecutionException lorsque le diviseur est nul
|
||||
*/
|
||||
public static Entier reste(Entier premier, Entier second) {
|
||||
if (second.compareTo(new Entier (0)) == 0) {
|
||||
throw new ExecutionException("Erreur. Division par 0. ");
|
||||
}
|
||||
return new Entier((int) premier.getValeur() % (int) second.getValeur());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
/**
|
||||
* TestEntier.java 13 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package interpreteurlir.donnees.litteraux.tests;
|
||||
|
||||
import interpreteurlir.ExecutionException;
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.litteraux.Entier;
|
||||
|
||||
import static interpreteurlir.donnees.litteraux.Entier.*;
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import static java.lang.Integer.MIN_VALUE;
|
||||
import static java.lang.Integer.MAX_VALUE;
|
||||
|
||||
/**
|
||||
* Tests des méthode de la classe Entier
|
||||
*
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestEntier {
|
||||
|
||||
/** Jeu d'entiers correctement instanciés à partir d'un entier */
|
||||
private final Entier[] ENTIERS_INT = {
|
||||
new Entier(MIN_VALUE),
|
||||
new Entier(MAX_VALUE),
|
||||
new Entier(1),
|
||||
new Entier(-4587),
|
||||
new Entier(-569),
|
||||
new Entier(-3),
|
||||
new Entier(0),
|
||||
new Entier(2),
|
||||
new Entier(78),
|
||||
new Entier(781),
|
||||
new Entier(179892),
|
||||
};
|
||||
|
||||
/** Jeu d'entiers correctement instanciés */
|
||||
private final Entier[] ENTIERS_STRING = {
|
||||
|
||||
new Entier("1"),
|
||||
new Entier("-4587"),
|
||||
new Entier("-569"),
|
||||
new Entier("-3"),
|
||||
new Entier("0"),
|
||||
new Entier("2"),
|
||||
new Entier("78"),
|
||||
new Entier("781"),
|
||||
new Entier("179892"),
|
||||
new Entier("-2147483648"),
|
||||
new Entier("2147483647"),
|
||||
};
|
||||
|
||||
/** Jeu d'integers correspondants */
|
||||
private static final int[] INT_VALIDES = {
|
||||
MIN_VALUE,
|
||||
MAX_VALUE,
|
||||
1,
|
||||
-4587,
|
||||
-569,
|
||||
-3,
|
||||
0,
|
||||
2,
|
||||
78,
|
||||
781,
|
||||
179892,
|
||||
};
|
||||
|
||||
/**
|
||||
* Test unitaire du constructeur Entier(String)
|
||||
*/
|
||||
public static void testEntierString() {
|
||||
final String[] INVALIDES = {
|
||||
null,
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
"a",
|
||||
"michel",
|
||||
"Janis Joplin",
|
||||
"(93)",
|
||||
" 78.3",
|
||||
"2147483648756",
|
||||
"2147483648",
|
||||
"+2147483648",
|
||||
"-2147483649",
|
||||
"-",
|
||||
"+",
|
||||
};
|
||||
|
||||
for (int i = 0; i < INVALIDES.length; i++) {
|
||||
try {
|
||||
new Entier(INVALIDES[i]);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode toString()
|
||||
*/
|
||||
public void testToString() {
|
||||
for (int i = 0; i < INT_VALIDES.length; i ++) {
|
||||
assertTrue(ENTIERS_INT[i].toString()
|
||||
.compareTo(Integer.toString(INT_VALIDES[i])) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode toCompareTo()
|
||||
*/
|
||||
public void testCompareTo() {
|
||||
final Entier REF_MIN = new Entier(MIN_VALUE);
|
||||
final Entier REF_MAX = new Entier(MAX_VALUE);
|
||||
|
||||
for (int i = 2; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(REF_MIN.compareTo(ENTIERS_INT[i]) < 0);
|
||||
assertTrue(REF_MAX.compareTo(ENTIERS_INT[i]) > 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(ENTIERS_INT[i].compareTo(new Entier(INT_VALIDES[i])) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode getValeur()
|
||||
*/
|
||||
@SuppressWarnings("boxing")
|
||||
public void testGetValeur() {
|
||||
final Integer[] ATTENDUS = {
|
||||
MIN_VALUE,
|
||||
MAX_VALUE,
|
||||
1,
|
||||
-4587,
|
||||
-569,
|
||||
-3,
|
||||
0,
|
||||
2,
|
||||
78,
|
||||
781,
|
||||
179892,
|
||||
};
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(ENTIERS_INT[i].getValeur().compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode somme()
|
||||
*/
|
||||
public void testSomme() {
|
||||
final Entier[] ATTENDUS = {
|
||||
new Entier(MIN_VALUE + MIN_VALUE),
|
||||
new Entier(MAX_VALUE + MAX_VALUE),
|
||||
new Entier(1 + 1),
|
||||
new Entier(-9174),
|
||||
new Entier(-1138),
|
||||
new Entier(-6),
|
||||
new Entier(0),
|
||||
new Entier(4),
|
||||
new Entier(156),
|
||||
new Entier(1562),
|
||||
new Entier(359784),
|
||||
};
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(somme(ENTIERS_INT[i], ENTIERS_INT[i])
|
||||
.compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode soustrait()
|
||||
*/
|
||||
public void testSoustrait() {
|
||||
Entier zero = new Entier(0);
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(soustrait(ENTIERS_INT[i], ENTIERS_INT[i])
|
||||
.compareTo(zero) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode multiplie()
|
||||
*/
|
||||
public void testMultiplie() {
|
||||
final Entier[] ATTENDUS = {
|
||||
new Entier(MIN_VALUE * MIN_VALUE),
|
||||
new Entier(MAX_VALUE * MAX_VALUE),
|
||||
new Entier(1 * 1),
|
||||
new Entier(-4587 * (-4587)),
|
||||
new Entier(-569 * (-569)),
|
||||
new Entier(-3 * (-3)),
|
||||
new Entier(0 * 0),
|
||||
new Entier(2 * 2),
|
||||
new Entier(78 * 78),
|
||||
new Entier(781 * 781),
|
||||
new Entier(179892 * 179892),
|
||||
};
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(multiplie(ENTIERS_INT[i], ENTIERS_INT[i])
|
||||
.compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode quotient()
|
||||
*/
|
||||
public void testQuotient() {
|
||||
final Entier DIVISEUR = new Entier(2);
|
||||
|
||||
final Entier[] ATTENDUS = {
|
||||
new Entier(-1073741824),
|
||||
new Entier(1073741823),
|
||||
new Entier(0),
|
||||
new Entier(-2293),
|
||||
new Entier(-284),
|
||||
new Entier(-1),
|
||||
new Entier(0),
|
||||
new Entier(1),
|
||||
new Entier(39),
|
||||
new Entier(390),
|
||||
new Entier(89946)
|
||||
};
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(quotient(ENTIERS_INT[i], DIVISEUR)
|
||||
.compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode quotient()
|
||||
*/
|
||||
public void testQuotientParZero() {
|
||||
final Entier DIVISEUR = new Entier(0);
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
try {
|
||||
quotient(ENTIERS_INT[i], DIVISEUR);
|
||||
echec();
|
||||
} catch (ExecutionException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode quotient()
|
||||
*/
|
||||
public void testReste() {
|
||||
final Entier DIVISEUR = new Entier(2);
|
||||
|
||||
final Entier[] ATTENDUS = {
|
||||
new Entier(0),
|
||||
new Entier(1),
|
||||
new Entier(1),
|
||||
new Entier(-1),
|
||||
new Entier(-1),
|
||||
new Entier(-1),
|
||||
new Entier(0),
|
||||
new Entier(0),
|
||||
new Entier(0),
|
||||
new Entier(1),
|
||||
new Entier(0)
|
||||
};
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
assertTrue(reste(ENTIERS_INT[i], DIVISEUR)
|
||||
.compareTo(ATTENDUS[i]) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test unitaire de la méthode quotient()
|
||||
*/
|
||||
public void testResteParZero() {
|
||||
final Entier DIVISEUR = new Entier(0);
|
||||
|
||||
for (int i = 0; i < ENTIERS_INT.length; i++) {
|
||||
try {
|
||||
reste(ENTIERS_INT[i], DIVISEUR);
|
||||
echec();
|
||||
} catch (ExecutionException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ package interpreteurlir.donnees.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.Identificateur;
|
||||
|
||||
/**
|
||||
@@ -43,9 +44,9 @@ public class TestIdentificateur {
|
||||
null,
|
||||
"",
|
||||
|
||||
// Fait au maximum 24 caractères
|
||||
// Fait au maximum 25 caractères
|
||||
"$jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"$jeSuisUnTresLongIdentific",
|
||||
"$jeSuisUnTresLongIdentifica",
|
||||
|
||||
// Espaces
|
||||
"id 3a",
|
||||
@@ -67,7 +68,7 @@ public class TestIdentificateur {
|
||||
try {
|
||||
new Identificateur(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
} catch (InterpreteurException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package interpreteurlir.donnees.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.IdentificateurChaine;
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,7 @@ import interpreteurlir.donnees.IdentificateurChaine;
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestIdentificateurChaine {
|
||||
/** Jeu d'identificateurs de chaîne correctement instanciés */
|
||||
/** Jeu d'identificateurs de chaîne correctement instanciés */
|
||||
private static IdentificateurChaine[] FIXTURE = {
|
||||
new IdentificateurChaine("$a"),
|
||||
new IdentificateurChaine("$A"),
|
||||
@@ -27,66 +28,67 @@ public class TestIdentificateurChaine {
|
||||
new IdentificateurChaine("$Alpha"),
|
||||
new IdentificateurChaine("$Alpha5"),
|
||||
new IdentificateurChaine("$jeSuisUnTresLongIdentifi")
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires du constructeur IdentificateurEntier(String identificateur)
|
||||
*/
|
||||
public static void testIdentificateurChaineString() {
|
||||
final String[] INVALIDE = {
|
||||
null,
|
||||
"",
|
||||
|
||||
// Commence par une lettre
|
||||
"9alpha",
|
||||
" 5alpha",
|
||||
|
||||
// Fait au maximum 24 caractères
|
||||
"$jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"$jeSuisUnTresLongIdentific",
|
||||
|
||||
// Espaces
|
||||
"id 3a",
|
||||
"$id 3a",
|
||||
" ",
|
||||
"$ ",
|
||||
|
||||
// caractères d'échapements
|
||||
"\t",
|
||||
"\n",
|
||||
"$\t",
|
||||
"$\n",
|
||||
|
||||
// , cas particulier
|
||||
"$",
|
||||
"$1"
|
||||
};
|
||||
|
||||
for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
|
||||
try {
|
||||
new IdentificateurChaine(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
final String[] INVALIDE = {
|
||||
null,
|
||||
"",
|
||||
|
||||
// Commence par une lettre
|
||||
"9alpha",
|
||||
" 5alpha",
|
||||
|
||||
// Fait au maximum 25 caractères
|
||||
"$jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"$jeSuisUnTresLongIdentifica",
|
||||
|
||||
// Espaces
|
||||
"id 3a",
|
||||
"$id 3a",
|
||||
" ",
|
||||
"$ ",
|
||||
|
||||
// caractères d'échapements
|
||||
"\t",
|
||||
"\n",
|
||||
"$\t",
|
||||
"$\n",
|
||||
|
||||
// , cas particulier
|
||||
"$",
|
||||
"$1"
|
||||
};
|
||||
|
||||
for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
|
||||
try {
|
||||
new IdentificateurChaine(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests unitaires de getNom()
|
||||
*/
|
||||
public static void testGetNom() {
|
||||
final String[] NOM_VALIDES = {
|
||||
"$a",
|
||||
"$A",
|
||||
"$alpha",
|
||||
"$Alpha",
|
||||
"$Alpha5",
|
||||
"$jeSuisUnTresLongIdentifi"
|
||||
"$a",
|
||||
"$A",
|
||||
"$alpha",
|
||||
"$Alpha",
|
||||
"$Alpha5",
|
||||
"$jeSuisUnTresLongIdentifi"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
assertEquivalence(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
|
||||
}
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
assertEquivalence(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package interpreteurlir.donnees.tests;
|
||||
|
||||
import static info1.outils.glg.Assertions.*;
|
||||
|
||||
import interpreteurlir.InterpreteurException;
|
||||
import interpreteurlir.donnees.IdentificateurEntier;
|
||||
|
||||
/**
|
||||
@@ -19,65 +20,65 @@ import interpreteurlir.donnees.IdentificateurEntier;
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestIdentificateurEntier {
|
||||
|
||||
/** Jeu d'identificateurs d'entier correctement instanciés */
|
||||
|
||||
/** Jeu d'identificateurs d'entier correctement instanciés */
|
||||
private static IdentificateurEntier[] FIXTURE = {
|
||||
new IdentificateurEntier("a"),
|
||||
new IdentificateurEntier("A"),
|
||||
new IdentificateurEntier("alpha"),
|
||||
new IdentificateurEntier("Alpha"),
|
||||
new IdentificateurEntier("Alpha5"),
|
||||
new IdentificateurEntier("jeSuisUnTresLongIdentifi")
|
||||
};
|
||||
|
||||
new IdentificateurEntier("jeSuisUnTresLongIdentific")
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests unitaires du constructeur IdentificateurEntier(String identificateur)
|
||||
*/
|
||||
public static void testIdentificateurEntierString() {
|
||||
final String[] INVALIDE = {
|
||||
// Commence par une lettre
|
||||
"9alpha",
|
||||
" 5alpha",
|
||||
"$beta",
|
||||
|
||||
// Fait au maximum 24 caractères
|
||||
"jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"jeSuisUnTresLongIdentific",
|
||||
|
||||
// Espaces, caractères d'échapements, cas particulier
|
||||
"id 3a",
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
null
|
||||
};
|
||||
|
||||
for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
|
||||
try {
|
||||
new IdentificateurEntier(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
final String[] INVALIDE = {
|
||||
// Ne commence pas par une lettre
|
||||
"9alpha",
|
||||
" 5alpha",
|
||||
"$beta",
|
||||
|
||||
// Fait plus de 25 caractères
|
||||
"jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"jeSuisUnTresLongIdentifica",
|
||||
|
||||
// Espaces, caractères d'échapements, cas particulier
|
||||
"id 3a",
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
null
|
||||
};
|
||||
|
||||
for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
|
||||
try {
|
||||
new IdentificateurEntier(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (InterpreteurException lancee) {
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests unitaires de getNom()
|
||||
*/
|
||||
public static void testGetNom() {
|
||||
final String[] NOM_VALIDES = {
|
||||
"a",
|
||||
"A",
|
||||
"alpha",
|
||||
"Alpha",
|
||||
"Alpha5",
|
||||
"jeSuisUnTresLongIdentifi"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
assertEquivalence(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
|
||||
}
|
||||
final String[] NOM_VALIDES = {
|
||||
"a",
|
||||
"A",
|
||||
"alpha",
|
||||
"Alpha",
|
||||
"Alpha5",
|
||||
"jeSuisUnTresLongIdentific"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
assertEquivalence(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user