Identificateur V1.0

This commit is contained in:
Tchi
2021-05-08 18:01:08 +02:00
parent 2d5320d879
commit 39c056a7b3
7 changed files with 313 additions and 140 deletions
-7
View File
@@ -1,7 +0,0 @@
# ignore les fichiers non nécessaire TexStudio
*.synctex.gz
*.aux
*.log
*.out
*.toc
+110 -6
View File
@@ -7,16 +7,120 @@
package donnees; package donnees;
/** /**
* @author Lucàs VABRE * @author Nicolas Caminade
* @author Heïa DEXTER * @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 * @param identificateur
*/ */
public Identificateur() { public Identificateur(String identificateur) {
// super(); 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());
}
} }
+15 -34
View File
@@ -7,28 +7,28 @@
package donnees; package donnees;
/** /**
* Identificateur de chaine * Identificateur de chaîne
* @author Lucàs VABRE * @author Nicolas Caminade
* @author Heïa DEXTER * @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/ */
public class IdentificateurChaine extends Identificateur { 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 * @param identificateur a instancier
* @throws IllegalAccessException si l'identificateur est invalide * @throws IllegalAccessException si l'identificateur est invalide
*/ */
public IdentificateurChaine(String identificateur) { public IdentificateurChaine(String identificateur) {
super(); super(identificateur);
if(!isIdentificateurChaine(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 * @return true si l'identificateur est bien un identificateur d'entier
* false sinon * false sinon
*/ */
private boolean isIdentificateurChaine(String identificateur) { private static 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 + "]";
}
/** return identificateur.length() >= 2
* @return la valeur de nom && identificateur.charAt(0) == '$'
*/ && isLettre(identificateur.charAt(1));
public String getNom() {
return nom;
} }
} }
+12 -54
View File
@@ -8,27 +8,27 @@ package donnees;
/** /**
* Identificateur d'entier * Identificateur d'entier
* @author Lucàs VABRE * @author Nicolas Caminade
* @author Heïa DEXTER * @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/ */
public class IdentificateurEntier extends Identificateur { public class IdentificateurEntier extends Identificateur {
/** Nom identificateur */
private String nom;
/** /**
* Instantiation d'identificateur d'entier * Instantiation d'identificateur d'entier
* @param identificateur a instancier * @param identificateur a instancier
* @throws IllegalAccessException si l'identificateur est invalide * @throws IllegalAccessException si l'identificateur est invalide
*/ */
public IdentificateurEntier(String identificateur) { public IdentificateurEntier(String identificateur) {
super(); super(identificateur);
if(!isIdentificateurEntier(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 * @return true si l'identificateur est bien un identificateur d'entier
* false sinon * false sinon
*/ */
private boolean isIdentificateurEntier(String identificateur) { private static 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;
}
/** return isLettre(identificateur.charAt(0))
* Prédicat attestant si un caractère est une lettre && isAlphanumerique(identificateur.substring(1));
* @param aTester caractère a tester
* @return
*/
private 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
*/
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;
}
} }
+89
View File
@@ -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);
}
}
}
+53 -24
View File
@@ -13,15 +13,21 @@ import donnees.IdentificateurChaine;
/** /**
* Tests unitaires de la classe donnees.IdentificateurEntier * Tests unitaires de la classe donnees.IdentificateurEntier
* @author Lucàs VABRE * @author Nicolas Caminade
* @author Heïa DEXTER * @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/ */
public class TestIdentificateurChaine { public class TestIdentificateurChaine {
/** Jeu d'identificateurs de chaine correctement instanciés */ /** Jeu d'identificateurs de chaîne correctement instanciés */
private static IdentificateurChaine[] FIXTURE = { private static IdentificateurChaine[] FIXTURE = {
new IdentificateurChaine("$a"),
new IdentificateurChaine("$A"),
new IdentificateurChaine("$alpha"), new IdentificateurChaine("$alpha"),
new IdentificateurChaine("$beta"), new IdentificateurChaine("$Alpha"),
new IdentificateurChaine("$gamma") new IdentificateurChaine("$Alpha5"),
new IdentificateurChaine("$jeSuisUnTresLongIdentifi")
}; };
/** /**
@@ -29,15 +35,32 @@ public class TestIdentificateurChaine {
*/ */
public static void testIdentificateurChaineString() { public static void testIdentificateurChaineString() {
final String[] INVALIDE = { final String[] INVALIDE = {
"9alpha", null,
"-beta", "",
"GAMMA",
"id 3a", // Commence par une lettre
"", "9alpha",
" ", " 5alpha",
"\t",
"\n", // Fait au maximum 24 caractères
null "$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++) { for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
@@ -45,7 +68,7 @@ public class TestIdentificateurChaine {
new IdentificateurChaine(INVALIDE[noJeu]); new IdentificateurChaine(INVALIDE[noJeu]);
echec(); echec();
} catch (IllegalArgumentException lancee) { } catch (IllegalArgumentException lancee) {
// test Ok // test OK
} }
} }
} }
@@ -54,11 +77,14 @@ public class TestIdentificateurChaine {
* Tests unitaires de getNom() * Tests unitaires de getNom()
*/ */
public static void testGetNom() { public static void testGetNom() {
final String[] NOM_VALIDES = { final String[] NOM_VALIDES = {
"$alpha", "$a",
"$beta", "$A",
"$gamma" "$alpha",
}; "$Alpha",
"$Alpha5",
"$jeSuisUnTresLongIdentifi"
};
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) { for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
assertEquivalent(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom()); assertEquivalent(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
@@ -70,13 +96,16 @@ public class TestIdentificateurChaine {
*/ */
public static void testToString() { public static void testToString() {
final String[] CHAINES_VALIDES = { final String[] CHAINES_VALIDES = {
"$alpha", "Identificateur [nom=$a]",
"$beta", "Identificateur [nom=$A]",
"$gamma" "Identificateur [nom=$alpha]",
"Identificateur [nom=$Alpha]",
"Identificateur [nom=$Alpha5]",
"Identificateur [nom=$jeSuisUnTresLongIdentifi]"
}; };
for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) { for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
assertEquivalent("IdentificateurChaine [nom=" + CHAINES_VALIDES[noJeu] + "]", assertEquivalent(CHAINES_VALIDES[noJeu],
FIXTURE[noJeu].toString()); FIXTURE[noJeu].toString());
} }
} }
+34 -15
View File
@@ -12,16 +12,22 @@ import donnees.IdentificateurEntier;
/** /**
* Tests unitaires de la classe donnees.IdentificateurEntier * Tests unitaires de la classe donnees.IdentificateurEntier
* @author Lucàs VABRE * @author Nicolas Caminade
* @author Heïa DEXTER * @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/ */
public class TestIdentificateurEntier { public class TestIdentificateurEntier {
/** Jeu d'identificateurs d'entier correctement instanciés */ /** Jeu d'identificateurs d'entier correctement instanciés */
private static IdentificateurEntier[] FIXTURE = { private static IdentificateurEntier[] FIXTURE = {
new IdentificateurEntier("a"),
new IdentificateurEntier("A"),
new IdentificateurEntier("alpha"), new IdentificateurEntier("alpha"),
new IdentificateurEntier("beta"), new IdentificateurEntier("Alpha"),
new IdentificateurEntier("gamma") new IdentificateurEntier("Alpha5"),
new IdentificateurEntier("jeSuisUnTresLongIdentifi")
}; };
/** /**
@@ -29,12 +35,19 @@ public class TestIdentificateurEntier {
*/ */
public static void testIdentificateurEntierString() { public static void testIdentificateurEntierString() {
final String[] INVALIDE = { final String[] INVALIDE = {
// Commence par une lettre
"9alpha", "9alpha",
" 5alpha",
"$beta", "$beta",
"GAMMA",
// Fait au maximum 24 caractères
"jeSuisUnTresLongIdentificateur", // 30 char
"jeSuisUnTresLongIdentific",
// Espaces, caractères d'échapements, cas particulier
"id 3a", "id 3a",
" ",
"", "",
" ",
"\t", "\t",
"\n", "\n",
null null
@@ -45,7 +58,7 @@ public class TestIdentificateurEntier {
new IdentificateurEntier(INVALIDE[noJeu]); new IdentificateurEntier(INVALIDE[noJeu]);
echec(); echec();
} catch (IllegalArgumentException lancee) { } catch (IllegalArgumentException lancee) {
// test Ok // test OK
} }
} }
} }
@@ -55,9 +68,12 @@ public class TestIdentificateurEntier {
*/ */
public static void testGetNom() { public static void testGetNom() {
final String[] NOM_VALIDES = { final String[] NOM_VALIDES = {
"alpha", "a",
"beta", "A",
"gamma" "alpha",
"Alpha",
"Alpha5",
"jeSuisUnTresLongIdentifi"
}; };
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) { for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
@@ -70,14 +86,17 @@ public class TestIdentificateurEntier {
*/ */
public static void testToString() { public static void testToString() {
final String[] CHAINES_VALIDES = { final String[] CHAINES_VALIDES = {
"alpha", "Identificateur [nom=a]",
"beta", "Identificateur [nom=A]",
"gamma" "Identificateur [nom=alpha]",
"Identificateur [nom=Alpha]",
"Identificateur [nom=Alpha5]",
"Identificateur [nom=jeSuisUnTresLongIdentifi]"
}; };
for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) { for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
assertEquivalent("IdentificateurEntier [nom=" + CHAINES_VALIDES[noJeu] + "]", assertEquivalent(CHAINES_VALIDES[noJeu],
FIXTURE[noJeu].toString()); FIXTURE[noJeu].toString());
} }
} }
} }