mirror of
https://github.com/LucasVbr/interpreteur-lir.git
synced 2026-05-13 17:21:52 +00:00
Identificateur V1.0
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
# ignore les fichiers non nécessaire TexStudio
|
||||
*.synctex.gz
|
||||
*.aux
|
||||
*.log
|
||||
*.out
|
||||
*.toc
|
||||
|
||||
@@ -7,16 +7,120 @@
|
||||
package donnees;
|
||||
|
||||
/**
|
||||
* @author Lucàs VABRE
|
||||
* @author Heïa DEXTER
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class Identificateur /* extends Variable */ {
|
||||
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 */
|
||||
private String nom;
|
||||
|
||||
/**
|
||||
* Instanciation de l'identificateur
|
||||
* Instantiation de l'identificateur
|
||||
* @param identificateur
|
||||
*/
|
||||
public Identificateur() {
|
||||
// super();
|
||||
public Identificateur(String identificateur) {
|
||||
super();
|
||||
if(!isIdentificateur(identificateur)) {
|
||||
throw new IllegalArgumentException(identificateur
|
||||
+ " n'est pas un identificateur");
|
||||
}
|
||||
|
||||
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 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';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la valeur de nom
|
||||
*/
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
/* non javadoc - @see java.lang.Object#toString() */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Identificateur [nom=" + nom + "]";
|
||||
}
|
||||
|
||||
/* non javadoc - @see java.lang.String#Comparable() */
|
||||
@Override
|
||||
public int compareTo(Identificateur aComparer) {
|
||||
return nom.compareTo(aComparer.getNom());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,28 +7,28 @@
|
||||
package donnees;
|
||||
|
||||
/**
|
||||
* Identificateur de chaine
|
||||
* @author Lucàs VABRE
|
||||
* @author Heïa DEXTER
|
||||
* Identificateur de chaîne
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class IdentificateurChaine extends Identificateur {
|
||||
|
||||
/** Nom identificateur */
|
||||
private String nom;
|
||||
|
||||
/**
|
||||
* Instantiation d'identificateur de chaine
|
||||
* Instantiation d'identificateur de chaîne
|
||||
* @param identificateur a instancier
|
||||
* @throws IllegalAccessException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurChaine(String identificateur) {
|
||||
super();
|
||||
super(identificateur);
|
||||
|
||||
if(!isIdentificateurChaine(identificateur)) {
|
||||
throw new IllegalArgumentException(identificateur + " n'est pas un identificateur de chaine");
|
||||
throw new IllegalArgumentException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " de chaine");
|
||||
}
|
||||
|
||||
this.nom = identificateur;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,29 +37,10 @@ public class IdentificateurChaine extends Identificateur {
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private boolean isIdentificateurChaine(String identificateur) {
|
||||
boolean testOk = identificateur != null
|
||||
&& identificateur.length() > 0
|
||||
&& identificateur.charAt(0) == '$';
|
||||
|
||||
for (int i = 1 ; testOk && i < identificateur.length() ; i++) {
|
||||
testOk = 'a' <= identificateur.charAt(i)
|
||||
&& identificateur.charAt(i) <= 'z' ;
|
||||
}
|
||||
|
||||
return testOk;
|
||||
}
|
||||
|
||||
/* non javadoc - @see java.lang.Object#toString() */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IdentificateurChaine [nom=" + nom + "]";
|
||||
}
|
||||
private static boolean isIdentificateurChaine(String identificateur) {
|
||||
|
||||
/**
|
||||
* @return la valeur de nom
|
||||
*/
|
||||
public String getNom() {
|
||||
return nom;
|
||||
return identificateur.length() >= 2
|
||||
&& identificateur.charAt(0) == '$'
|
||||
&& isLettre(identificateur.charAt(1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,27 +8,27 @@ package donnees;
|
||||
|
||||
/**
|
||||
* Identificateur d'entier
|
||||
* @author Lucàs VABRE
|
||||
* @author Heïa DEXTER
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class IdentificateurEntier extends Identificateur {
|
||||
|
||||
/** Nom identificateur */
|
||||
private String nom;
|
||||
|
||||
/**
|
||||
* Instantiation d'identificateur d'entier
|
||||
* @param identificateur a instancier
|
||||
* @throws IllegalAccessException si l'identificateur est invalide
|
||||
*/
|
||||
public IdentificateurEntier(String identificateur) {
|
||||
super();
|
||||
super(identificateur);
|
||||
|
||||
if(!isIdentificateurEntier(identificateur)) {
|
||||
throw new IllegalArgumentException(identificateur + " n'est pas un identificateur d'entier");
|
||||
throw new IllegalArgumentException(identificateur
|
||||
+ " n'est pas un identificateur"
|
||||
+ " d'entier");
|
||||
}
|
||||
|
||||
this.nom = identificateur;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,51 +43,9 @@ public class IdentificateurEntier extends Identificateur {
|
||||
* @return true si l'identificateur est bien un identificateur d'entier
|
||||
* false sinon
|
||||
*/
|
||||
private boolean isIdentificateurEntier(String identificateur) {
|
||||
final int LONGUEUR_MAX = 24;
|
||||
|
||||
boolean testOk = identificateur != null
|
||||
&& 0 < identificateur.length()
|
||||
&& identificateur.length() <= LONGUEUR_MAX
|
||||
&& isLettre(identificateur.charAt(0));
|
||||
|
||||
for (int i = 1 ; testOk && i < identificateur.length() ; i++) {
|
||||
testOk = isLettre(identificateur.charAt(i))
|
||||
|| isChiffre(identificateur.charAt(i));
|
||||
}
|
||||
|
||||
return testOk;
|
||||
}
|
||||
private static boolean isIdentificateurEntier(String identificateur) {
|
||||
|
||||
/**
|
||||
* Prédicat attestant si un caractère est une lettre
|
||||
* @param aTester caractère a tester
|
||||
* @return
|
||||
*/
|
||||
private static boolean isLettre(char aTester) {
|
||||
return 'a' <= aTester && aTester <= 'z'
|
||||
|| 'A' <= aTester && aTester <= 'Z';
|
||||
return isLettre(identificateur.charAt(0))
|
||||
&& isAlphanumerique(identificateur.substring(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prédicat attestant si un caractère est un chiffre
|
||||
* @param aTester caractère a tester
|
||||
*/
|
||||
private static boolean isChiffre(char aTester) {
|
||||
return '0' <= aTester && aTester <= '9';
|
||||
}
|
||||
|
||||
/* non javadoc - @see java.lang.Object#toString() */
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IdentificateurEntier [nom=" + nom + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return la valeur de nom
|
||||
*/
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* TestIdentificateur.java 8 mai 2021
|
||||
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
|
||||
*/
|
||||
package donnees.tests;
|
||||
|
||||
import static outils.glg.Assertions.*;
|
||||
|
||||
import donnees.Identificateur;
|
||||
|
||||
/**
|
||||
* Test de la classe donnees.Identificateur
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestIdentificateur {
|
||||
|
||||
/** Jeu d'identificateurs correctement instanciés */
|
||||
public static final Identificateur[] FIXTURE = {
|
||||
new Identificateur("b"),
|
||||
new Identificateur("A"),
|
||||
new Identificateur("zalpha"),
|
||||
new Identificateur("Alpha"),
|
||||
new Identificateur("Alpha5"),
|
||||
new Identificateur("jeSuisUnTresLongIdentifi"),
|
||||
new Identificateur("$b"),
|
||||
new Identificateur("z"),
|
||||
new Identificateur("$zalpha"),
|
||||
new Identificateur("$Alpha"),
|
||||
new Identificateur("$Alpha5"),
|
||||
new Identificateur("$jeSuisUnTresLongIdentifi")
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Test de Identificateur(String identificateur)
|
||||
*/
|
||||
public static void testIdentificateurString() {
|
||||
final String[] INVALIDE = {
|
||||
null,
|
||||
"",
|
||||
|
||||
// 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
|
||||
"$"
|
||||
};
|
||||
|
||||
for(int noJeu = 0 ; noJeu < INVALIDE.length ; noJeu++) {
|
||||
try {
|
||||
new Identificateur(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
// Test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test de compareTo(Identificateur aComparer)
|
||||
*/
|
||||
public static void testCompareTo() {
|
||||
final Identificateur REF_MIN = new Identificateur("$AAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
final Identificateur REF_MAX = new Identificateur("zzzzzzzzzzzzzzzzzzzzzzzz");
|
||||
|
||||
for(int noJeu = 0; noJeu < FIXTURE.length; noJeu++) {
|
||||
assertTrue(FIXTURE[noJeu].compareTo(REF_MIN) >= 0);
|
||||
assertTrue(FIXTURE[noJeu].compareTo(REF_MAX) <= 0);
|
||||
assertTrue(FIXTURE[noJeu].compareTo(FIXTURE[noJeu]) == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,21 @@ import donnees.IdentificateurChaine;
|
||||
|
||||
/**
|
||||
* Tests unitaires de la classe donnees.IdentificateurEntier
|
||||
* @author Lucàs VABRE
|
||||
* @author Heïa DEXTER
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestIdentificateurChaine {
|
||||
/** Jeu d'identificateurs de chaine correctement instanciés */
|
||||
/** Jeu d'identificateurs de chaîne correctement instanciés */
|
||||
private static IdentificateurChaine[] FIXTURE = {
|
||||
new IdentificateurChaine("$a"),
|
||||
new IdentificateurChaine("$A"),
|
||||
new IdentificateurChaine("$alpha"),
|
||||
new IdentificateurChaine("$beta"),
|
||||
new IdentificateurChaine("$gamma")
|
||||
new IdentificateurChaine("$Alpha"),
|
||||
new IdentificateurChaine("$Alpha5"),
|
||||
new IdentificateurChaine("$jeSuisUnTresLongIdentifi")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -29,15 +35,32 @@ public class TestIdentificateurChaine {
|
||||
*/
|
||||
public static void testIdentificateurChaineString() {
|
||||
final String[] INVALIDE = {
|
||||
"9alpha",
|
||||
"-beta",
|
||||
"GAMMA",
|
||||
"id 3a",
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
null
|
||||
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++) {
|
||||
@@ -45,7 +68,7 @@ public class TestIdentificateurChaine {
|
||||
new IdentificateurChaine(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
// test Ok
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,11 +77,14 @@ public class TestIdentificateurChaine {
|
||||
* Tests unitaires de getNom()
|
||||
*/
|
||||
public static void testGetNom() {
|
||||
final String[] NOM_VALIDES = {
|
||||
"$alpha",
|
||||
"$beta",
|
||||
"$gamma"
|
||||
};
|
||||
final String[] NOM_VALIDES = {
|
||||
"$a",
|
||||
"$A",
|
||||
"$alpha",
|
||||
"$Alpha",
|
||||
"$Alpha5",
|
||||
"$jeSuisUnTresLongIdentifi"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
assertEquivalent(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
|
||||
@@ -70,13 +96,16 @@ public class TestIdentificateurChaine {
|
||||
*/
|
||||
public static void testToString() {
|
||||
final String[] CHAINES_VALIDES = {
|
||||
"$alpha",
|
||||
"$beta",
|
||||
"$gamma"
|
||||
"Identificateur [nom=$a]",
|
||||
"Identificateur [nom=$A]",
|
||||
"Identificateur [nom=$alpha]",
|
||||
"Identificateur [nom=$Alpha]",
|
||||
"Identificateur [nom=$Alpha5]",
|
||||
"Identificateur [nom=$jeSuisUnTresLongIdentifi]"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
|
||||
assertEquivalent("IdentificateurChaine [nom=" + CHAINES_VALIDES[noJeu] + "]",
|
||||
assertEquivalent(CHAINES_VALIDES[noJeu],
|
||||
FIXTURE[noJeu].toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,22 @@ import donnees.IdentificateurEntier;
|
||||
|
||||
/**
|
||||
* Tests unitaires de la classe donnees.IdentificateurEntier
|
||||
* @author Lucàs VABRE
|
||||
* @author Heïa DEXTER
|
||||
* @author Nicolas Caminade
|
||||
* @author Sylvan Courtiol
|
||||
* @author Pierre Debas
|
||||
* @author Heia Dexter
|
||||
* @author Lucas Vabre
|
||||
*/
|
||||
public class TestIdentificateurEntier {
|
||||
|
||||
/** Jeu d'identificateurs d'entier correctement instanciés */
|
||||
private static IdentificateurEntier[] FIXTURE = {
|
||||
new IdentificateurEntier("a"),
|
||||
new IdentificateurEntier("A"),
|
||||
new IdentificateurEntier("alpha"),
|
||||
new IdentificateurEntier("beta"),
|
||||
new IdentificateurEntier("gamma")
|
||||
new IdentificateurEntier("Alpha"),
|
||||
new IdentificateurEntier("Alpha5"),
|
||||
new IdentificateurEntier("jeSuisUnTresLongIdentifi")
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -29,12 +35,19 @@ public class TestIdentificateurEntier {
|
||||
*/
|
||||
public static void testIdentificateurEntierString() {
|
||||
final String[] INVALIDE = {
|
||||
// Commence par une lettre
|
||||
"9alpha",
|
||||
" 5alpha",
|
||||
"$beta",
|
||||
"GAMMA",
|
||||
|
||||
// Fait au maximum 24 caractères
|
||||
"jeSuisUnTresLongIdentificateur", // 30 char
|
||||
"jeSuisUnTresLongIdentific",
|
||||
|
||||
// Espaces, caractères d'échapements, cas particulier
|
||||
"id 3a",
|
||||
" ",
|
||||
"",
|
||||
" ",
|
||||
"\t",
|
||||
"\n",
|
||||
null
|
||||
@@ -45,7 +58,7 @@ public class TestIdentificateurEntier {
|
||||
new IdentificateurEntier(INVALIDE[noJeu]);
|
||||
echec();
|
||||
} catch (IllegalArgumentException lancee) {
|
||||
// test Ok
|
||||
// test OK
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,9 +68,12 @@ public class TestIdentificateurEntier {
|
||||
*/
|
||||
public static void testGetNom() {
|
||||
final String[] NOM_VALIDES = {
|
||||
"alpha",
|
||||
"beta",
|
||||
"gamma"
|
||||
"a",
|
||||
"A",
|
||||
"alpha",
|
||||
"Alpha",
|
||||
"Alpha5",
|
||||
"jeSuisUnTresLongIdentifi"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
|
||||
@@ -70,14 +86,17 @@ public class TestIdentificateurEntier {
|
||||
*/
|
||||
public static void testToString() {
|
||||
final String[] CHAINES_VALIDES = {
|
||||
"alpha",
|
||||
"beta",
|
||||
"gamma"
|
||||
"Identificateur [nom=a]",
|
||||
"Identificateur [nom=A]",
|
||||
"Identificateur [nom=alpha]",
|
||||
"Identificateur [nom=Alpha]",
|
||||
"Identificateur [nom=Alpha5]",
|
||||
"Identificateur [nom=jeSuisUnTresLongIdentifi]"
|
||||
};
|
||||
|
||||
for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
|
||||
assertEquivalent("IdentificateurEntier [nom=" + CHAINES_VALIDES[noJeu] + "]",
|
||||
FIXTURE[noJeu].toString());
|
||||
assertEquivalent(CHAINES_VALIDES[noJeu],
|
||||
FIXTURE[noJeu].toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user