Prototype + programme de démo + exécutable

This commit is contained in:
SylvanCourtiol
2021-05-24 19:01:55 +02:00
parent 54814e838f
commit db09baf5c4
69 changed files with 2805 additions and 1060 deletions
+13 -15
View File
@@ -1,5 +1,5 @@
/*
* Identificateur.java , 08/05/2021
* Identificateur.java , 8 mai 2021
* IUT Rodez 2020-2021, info1
* pas de copyright, aucun droits
*/
@@ -9,31 +9,31 @@ package interpreteurlir.donnees;
import interpreteurlir.InterpreteurException;
/**
* Identificateur d'une variable.
* @author Nicolas Caminade
* @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/
public class Identificateur /* extends Variable */
implements Comparable<Identificateur> {
public abstract class Identificateur implements Comparable<Identificateur> {
/** Longueur maximale d'un identificateur (ne prend pas en compte le $) */
public static final int LONGUEUR_MAX = 25;
/** Nom identificateur */
/** Nom de cet identificateur */
private String nom;
/**
* Instantiation de l'identificateur
* @param identificateur
* @param identificateur nom de l'identificateur
*/
public Identificateur(String identificateur) {
super();
identificateur = identificateur.trim();
if(!isIdentificateur(identificateur)) {
throw new InterpreteurException(identificateur
+ " n'est pas un identificateur");
+ " produit un résultat inattendu");
}
nom = identificateur;
@@ -46,7 +46,7 @@ implements Comparable<Identificateur> {
* <li>N'est pas une chaîne vide</li>
* <li>N'est pas null</li>
* </ul>
* @param aTester
* @param aTester chaîne à tester
* @return true si le prédicat est vérifié
* false sinon
*/
@@ -77,17 +77,15 @@ implements Comparable<Identificateur> {
public static boolean isAlphanumerique(String aTester) {
int index;
for (index = 0 ;
index < aTester.length()
&& Character.isLetterOrDigit(aTester.charAt(index)) ;
index++)
; // Corps vide
index < aTester.length()
&& Character.isLetterOrDigit(aTester.charAt(index)) ;
index++)
; /* empty body */
return index >= aTester.length();
return index >= aTester.length();
}
/**
* @return la valeur de nom
*/
/** @return la valeur de nom */
public String getNom() {
return nom;
}
@@ -39,7 +39,7 @@ public class IdentificateurChaine extends Identificateur {
* @return true si l'identificateur est bien un identificateur d'entier
* false sinon
*/
private static boolean isIdentificateurChaine(String identificateur) {
public static boolean isIdentificateurChaine(String identificateur) {
return identificateur.length() >= 2
&& identificateur.charAt(0) == '$'
@@ -21,10 +21,10 @@ import interpreteurlir.InterpreteurException;
public class IdentificateurEntier extends Identificateur {
/**
* Instantiation de cet identificateur d'entier avec le nom spécififié
* Instantiation de cet identificateur d'entier avec le nom spécifié
* en argument. Lève une exception si l'identificateur n'est pas
* valide.
* @param identificateur a instancier
* @param identificateur à instancier
* @throws InterpreteurException si l'identificateur est invalide
*/
public IdentificateurEntier(String identificateur) {
@@ -49,7 +49,7 @@ public class IdentificateurEntier extends Identificateur {
* @return true si l'identificateur est bien un identificateur d'entier
* false sinon
*/
private static boolean isIdentificateurEntier(String aTester) {
public static boolean isIdentificateurEntier(String aTester) {
return aTester.length() <= 25 && Character.isLetter(aTester.charAt(0))
&& isAlphanumerique(aTester.substring(1));
}
+5 -1
View File
@@ -65,7 +65,7 @@ public class Variable extends Object implements Comparable<Variable> {
/**
* Modifie la valeur de cette variable
* @param nouvelleValeur
* @param nouvelleValeur valeur à affecter à cette variable
*/
public void setValeur(Litteral nouvelleValeur) {
if (isVariable(identificateur, nouvelleValeur)) {
@@ -86,6 +86,10 @@ public class Variable extends Object implements Comparable<Variable> {
return identificateur.toString() + " = " + valeur.toString();
}
/*
* non javadoc
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Variable aComparer) {
return identificateur.compareTo(aComparer.identificateur);
}
@@ -0,0 +1,48 @@
/**
* Booleen.java 21 mai 2021
* IUT Rodez info1 2020-2021, pas de copyright, aucun droit
*/
package interpreteurlir.donnees.litteraux;
import interpreteurlir.InterpreteurException;
/**
* Constante littérale de type booléen
*
* @author Nicolas Caminade
* @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/
public class Booleen extends Litteral {
/**
* Initialise ce booléen
* @param unBooleen valeur du booléen à construire
* @throws InterpreteurException si la condition n'est pas un
*
*/
public Booleen(Boolean unBooleen) {
super();
valeur = unBooleen;
}
/* non javadoc
* @see interpreteurlir.donnees.litteraux.Litteral#getValeur()
*/
@Override
public Boolean getValeur() {
return (Boolean) super.valeur;
}
/* non javadoc
* @deprecated
* @see Litteral#compareTo(Litteral)
*/
@Override
public int compareTo(Litteral autre) {
return (Boolean)this.valeur == (Boolean)autre.valeur ? 0 : 1; // égalité
}
}
@@ -21,11 +21,11 @@ public class Chaine extends Litteral {
/** Erreur chaîne trop longue */
private static final String ERREUR_LG_MAX =
"Longueur maximale d'une chaîne dépassée";
"longueur maximale d'une chaîne dépassée";
/** Erreur constante littéral chaîne invalide */
private static final String ERREUR_INVALIDE =
"syntaxe incorrecte pour une constante de type chaîne : ";
" n'est pas une constante de type chaîne";
/**
* initialise cette chaîne avec une valeur par défaut.
@@ -35,22 +35,33 @@ public class Chaine extends Litteral {
}
/**
* Initialise une chaîne avec la séquence de caractères passée en argument.
* @param uneValeur
* Initialise une chaîne avec la séquence
* de caractères passée en argument.
* @param uneValeur valeur de la chaine à construire (entre guillemets)
*/
public Chaine(String uneValeur) {
uneValeur = uneValeur.trim();
if (!uneValeur.startsWith("\"") || !uneValeur.endsWith("\"")) {
throw new InterpreteurException(ERREUR_INVALIDE
+ uneValeur);
}
uneValeur = uneValeur.substring(1, uneValeur.length() - 1);
if (uneValeur.length() > LG_MAX_CHAINE)
throw new InterpreteurException(ERREUR_LG_MAX);
valeur = uneValeur;
if (!isChaine(uneValeur)) {
throw new InterpreteurException(uneValeur + ERREUR_INVALIDE);
}
uneValeur = uneValeur.substring(1, uneValeur.length() - 1);
if (uneValeur.length() > LG_MAX_CHAINE)
throw new InterpreteurException(ERREUR_LG_MAX);
valeur = uneValeur;
}
/**
* Prédicat de validité d'une constante littérale de type chaîne.
* @param uneValeur valeur aTester
* @return true si uneValeur est une chaîne sinon false
*/
public static boolean isChaine(String uneValeur) {
uneValeur = uneValeur.trim();
return uneValeur.length() >= 2
&& uneValeur.startsWith("\"") && uneValeur.endsWith("\"");
}
/**
@@ -61,16 +72,15 @@ public class Chaine extends Litteral {
* @return une nouvelle Chaîne.
*/
public static Chaine concatener(Chaine a, Chaine b) {
return new Chaine("\"" + a.valeur + b.valeur + "\"");
return new Chaine("\"" + a.valeur + b.valeur + "\"");
}
/* non javadoc
* @see interpreteurlir.donnees.litteraux.Litteral#compareTo(interpreteurlir.donnees.litteraux.Litteral)
* @see Litteral#compareTo(Litteral)
*/
@Override
public int compareTo(Litteral autre) {
return this.valeur.toString().compareTo(autre.valeur.toString());
return valeur.toString().compareTo(autre.valeur.toString());
}
/* non javadoc
@@ -17,73 +17,46 @@ import interpreteurlir.InterpreteurException;
* @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;
/** 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
* @param unEntier valeur de l'entier à construire
*/
@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
* @param uneValeur chaîne contenant l'entier à construire
*/
public Entier(String uneValeur) {
if (!isEntier(uneValeur)) {
throw new InterpreteurException(uneValeur
+ " n'est pas un nombre entier. ");
+ " 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();
/**
* Prédicat de validité d'une chaîne en tant que nombre entier signé
* @param uneValeur la chaîne à tester
* @return true si uneValeur est un entier sinon false
*/
public static boolean isEntier(String uneValeur) {
if (uneValeur == null) {
return false;
}
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;
try {
Integer.valueOf(uneValeur.trim());
} catch (NumberFormatException lancee) {
return false;
}
return true;
}
/* non javadoc
@@ -101,10 +74,10 @@ public class Entier extends Litteral {
/**
* 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
* @param autre entier avec lequel this est comparé
* @return une {@code valeur < 0} lorsque {@code autre > cet entier}
* une {@code valeur > 0} lorsque {@code autre < cet entier}
* une {@code valeur = 0} lorsque autre et cet entier sont égaux
*/
public int compareTo(Entier autre) {
return ((Integer) valeur).compareTo(autre.getValeur());
@@ -151,7 +124,7 @@ public class Entier extends Litteral {
*/
public static Entier quotient(Entier premier, Entier second) {
if (second.compareTo(new Entier (0)) == 0) {
throw new ExecutionException("Erreur. Division par 0. ");
throw new ExecutionException("division par 0");
}
return new Entier((int) premier.getValeur() / (int) second.getValeur());
}
@@ -165,8 +138,16 @@ public class Entier extends Litteral {
*/
public static Entier reste(Entier premier, Entier second) {
if (second.compareTo(new Entier (0)) == 0) {
throw new ExecutionException("Erreur. Division par 0. ");
throw new ExecutionException("division par 0");
}
return new Entier((int) premier.getValeur() % (int) second.getValeur());
}
/* non javadoc
* @see Litteral#compareTo(Litteral)
*/
@Override
public int compareTo(Litteral autre) {
return ((Integer)valeur).compareTo((Integer)autre.valeur);
}
}
@@ -13,7 +13,7 @@ package interpreteurlir.donnees.litteraux;
* @author Heïa Dexter
* @author Lucas Vabre
*/
public class Litteral implements Comparable<Litteral> {
public abstract class Litteral implements Comparable<Litteral> {
/** valeur de ce littéral */
protected Object valeur;
@@ -27,9 +27,9 @@ public class Litteral implements Comparable<Litteral> {
/**
* Initialise cette valeur avec un objet argument.
* @param valeur
* @param valeur valeur du littéral à construire
*/
public Litteral(Object valeur) { // TODO public >>> protected
public Litteral(Object valeur) {
super();
this.valeur = valeur;
}
@@ -53,11 +53,5 @@ public class Litteral implements Comparable<Litteral> {
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(Litteral autre) {
if (autre.valeur.getClass() == this.valeur.getClass())
return 0;
return this.valeur.hashCode() - autre.valeur.hashCode();
}
public abstract int compareTo(Litteral autre);
}
@@ -0,0 +1,50 @@
/**
* TestBooleen.java 21 mai 2021
* IUT Rodez info1 2020-2021, pas de copyright, aucun droit
*/
package interpreteurlir.donnees.litteraux.tests;
import interpreteurlir.donnees.litteraux.Booleen;
import static info1.outils.glg.Assertions.*;
/**
* Tests unitaires des méthodes de la classe Booleen
*
* @author Nicolas Caminade
* @author Sylvan Courtiol
* @author Pierre Debas
* @author Heia Dexter
* @author Lucas Vabre
*/
public class TestBooleen {
private static final Booleen[] FIXTURE = {
new Booleen(false),
new Booleen(true),
new Booleen(1<2),
new Booleen(1>=2),
new Booleen("bob".equals("bob")),
new Booleen(Character.isDigit('a')),
new Booleen(!Double.isNaN(1/0.0)),
};
/**
* Tests unitaire de {@link Booleen#getValeur()}
*/
public void testGetValeur() {
final Boolean[] ATTENDUS = {
false,
true,
true,
false,
true,
false,
true
};
System.out.println("\tExécution du test de getValeur");
for (int i = 0 ; i < ATTENDUS.length ; i++) {
assertTrue(ATTENDUS[i].compareTo(FIXTURE[i].getValeur())
== 0);
}
}
}
@@ -10,7 +10,8 @@ import interpreteurlir.donnees.litteraux.Chaine;
import static info1.outils.glg.Assertions.*;
/**
* Tests unitaires de Chaine
* Tests unitaires de la classe Chaine
*
* @author Nicolas Caminade
* @author Sylvan Courtiol
* @author Pierre Debas
@@ -18,134 +19,118 @@ import static info1.outils.glg.Assertions.*;
* @author Lucas Vabre
*/
public class TestChaine {
/** test de Chaine(String) */
public static void testChaine() {
final String[] VALIDE = {
"\"arztyehjklmpoijhghnbghjklmpoiuytrf" +
"ghjnklmpoiuytrezaqsdfghnjklmpjbfrtyu\"",
"\"\"","\"coucou \"",
"\"" + 42 + "\""
};
final String INVALIDE =
"arztyehjklmpoijhghnbghjklmpoiuytrf" +
"yeryghjnklmpoiuytrezaqsdfghnjklmpjbfrtyu";
System.out.println("test de Chaine(String)");
for (String aTester : VALIDE)
new Chaine(aTester);
try {
new Chaine(INVALIDE);
throw new RuntimeException("Instanciation interdite");
} catch (InterpreteurException lancee) {
System.out.println("Revoi d'exception OK\nfin du test");
}
}
/** test de compareTo */
public static void testCompareTo() {
final Chaine[][] EGALITES = {
{new Chaine("\"coucou\""), new Chaine("\"coucou\"")},
{new Chaine("\" \""), new Chaine("\" \"")},
{new Chaine("\"\""), new Chaine()}
};
final Chaine[][] DIFFERENCES = {
{new Chaine("\"coucou\""), new Chaine("\"camomille\"")},
{new Chaine("\"tarentule\""), new Chaine("\"coucou\"")},
{new Chaine("\"coucou\""), new Chaine("\" \"")},
{new Chaine("\"coucou\""), new Chaine()},
{new Chaine("\" \""), new Chaine()}
};
System.out.println("test de compareTo(Chaine)\nAvec égalités");
for (Chaine[] couple : EGALITES) {
try {
assert couple[0].compareTo(couple[1]) == 0;
} catch (AssertionError lancee) {
System.err.println("Echec du test");
}
}
System.out.println("Avec des inégalités");
for (Chaine[] couple : DIFFERENCES) {
try {
assert couple[0].compareTo(couple[1]) > 0;
} catch (AssertionError lancee) {
System.err.println("Echec du test");
}
}
System.out.println("fin du test");
}
/** test de toString */
public static void testToString() {
final Chaine[] A_AFFICHER = {
new Chaine(), new Chaine("\" \""),
new Chaine("\"coucou\""),
new Chaine("\" coucou \""),
new Chaine("\"coucou monsieur\"")
};
final String[] AFFICHAGE_GUILLEMETS = {
"\"\"", "\" \"", "\"coucou\"", "\" coucou \"",
"\"coucou monsieur\""
};
System.out.println("test de toString");
for (int i = 0 ; i < A_AFFICHER.length ; i++) {
try {
assert A_AFFICHER[i].toString().equals(AFFICHAGE_GUILLEMETS[i]);
} catch (AssertionError lancee) {
System.err.println("Echec du test a l'indice " + i);
}
}
System.out.println("==>test terminé\n");
}
/**
* Tests unitaires de concaténer
*/
public void testConcatener() {
final Chaine[] ATTENDU = {
new Chaine(),
new Chaine("\"Bonjour le monde ! \""),
new Chaine("\" \""),
new Chaine("\"3,1415\""),
};
final Chaine[][] A_CONCATENER = {
{new Chaine(), new Chaine("\"\"")},
{new Chaine("\"Bonjour \""), new Chaine("\"le monde ! \"")},
{new Chaine("\"\""), new Chaine("\" \"")},
{new Chaine("\"3,\""), new Chaine("\"1415\"")},
};
System.out.println("\tExécution du test de concaténer");
for (int numTest = 0 ; numTest < ATTENDU.length ; numTest++ ) {
assertTrue(ATTENDU[numTest].compareTo(Chaine.concatener(
A_CONCATENER[numTest][0], A_CONCATENER[numTest][1]))
== 0);
}
}
/**
* Lancement des tests
* @param args non utilisés
*/
public static void main(String[] args) {
testChaine();
testCompareTo();
testToString();
}
}
/** Test unitaire de {@link Chaine#Chaine(String)} */
public static void testChaine() {
final String[] VALIDE = {
"\"arztyehjklmpoijhghnbghjklmpoiuytrf" +
"ghjnklmpoiuytrezaqsdfghnjklmpjbfrtyu\"",
"\"\"",
"\"coucou \"",
"\"" + 42 + "\""
};
final String INVALIDE =
"arztyehjklmpoijhghnbghjklmpoiuytrf" +
"yeryghjnklmpoiuytrezaqsdfghnjklmpjbfrtyu";
System.out.println("\tExécution du test de Chaine(String)");
for(String aTester : VALIDE) {
try {
new Chaine(aTester);
} catch (InterpreteurException lancee) {
echec();
}
}
try {
new Chaine(INVALIDE);
echec();
} catch (InterpreteurException lancee) {
// Test OK
}
}
/** Test unitaire de {@link Chaine#compareTo(Litteral)} */
public static void testCompareTo() {
final Chaine[][] EGALITES = {
{ new Chaine("\"coucou\""), new Chaine("\"coucou\"") },
{ new Chaine("\" \""), new Chaine("\" \"") },
{ new Chaine("\"\""), new Chaine() }
};
final Chaine[][] DIFFERENCES = {
{ new Chaine("\"coucou\""), new Chaine("\"camomille\"") },
{ new Chaine("\"tarentule\""), new Chaine("\"coucou\"") },
{ new Chaine("\"coucou\""), new Chaine("\" \"") },
{ new Chaine("\"coucou\""), new Chaine() },
{ new Chaine("\" \""), new Chaine() }
};
System.out.println("\tExécution du test de compareTo(Chaine)\n"
+ "\tAvec égalités");
for (Chaine[] couple : EGALITES) {
assertEquivalence(couple[0].compareTo(couple[1]), 0);
}
System.out.println("\tAvec des inégalités");
for (Chaine[] couple : DIFFERENCES) {
assertTrue(couple[0].compareTo(couple[1]) > 0);
}
}
/** Test unitaire de {@link Chaine#toString()} */
public static void testToString() {
final Chaine[] A_AFFICHER = {
new Chaine(),
new Chaine("\" \""),
new Chaine("\"coucou\""),
new Chaine("\" coucou \""),
new Chaine("\"coucou monsieur\"")
};
final String[] AFFICHAGE_GUILLEMETS = {
"\"\"",
"\" \"",
"\"coucou\"",
"\" coucou \"",
"\"coucou monsieur\""
};
System.out.println("\tExécution du test de toString");
for (int i = 0 ; i < A_AFFICHER.length ; i++) {
assertTrue(AFFICHAGE_GUILLEMETS[i]
.equals(A_AFFICHER[i].toString()));
}
}
/**
* Tests unitaires de concaténer
*/
public static void testConcatener() {
final Chaine[] ATTENDU = {
new Chaine(),
new Chaine("\"Bonjour le monde ! \""),
new Chaine("\" \""),
new Chaine("\"3,1415\""),
};
final Chaine[][] A_CONCATENER = {
{ new Chaine(), new Chaine("\"\"") },
{ new Chaine("\"Bonjour \""), new Chaine("\"le monde ! \"") },
{ new Chaine("\"\""), new Chaine("\" \"") },
{ new Chaine("\"3,\""), new Chaine("\"1415\"") },
};
System.out.println("\tExécution du test de concaténer");
for (int numTest = 0 ; numTest < ATTENDU.length ; numTest++ ) {
assertTrue(ATTENDU[numTest].compareTo(
Chaine.concatener(A_CONCATENER[numTest][0],
A_CONCATENER[numTest][1])) == 0);
}
}
}
@@ -40,22 +40,6 @@ public class TestEntier {
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,
@@ -94,6 +78,7 @@ public class TestEntier {
"+",
};
System.out.println("\tExécution du test de Entier(String)");
for (int i = 0; i < INVALIDES.length; i++) {
try {
new Entier(INVALIDES[i]);
@@ -108,6 +93,7 @@ public class TestEntier {
* Test unitaire de la méthode toString()
*/
public void testToString() {
System.out.println("\tExécution du test de Entier(String)");
for (int i = 0; i < INT_VALIDES.length; i ++) {
assertTrue(ENTIERS_INT[i].toString()
.compareTo(Integer.toString(INT_VALIDES[i])) == 0);
@@ -115,12 +101,12 @@ public class TestEntier {
}
/**
* Test unitaire de la méthode toCompareTo()
* Test unitaire de la méthode compareTo()
*/
public void testCompareTo() {
final Entier REF_MIN = new Entier(MIN_VALUE);
final Entier REF_MAX = new Entier(MAX_VALUE);
System.out.println("\tExécution du test de compareTo()");
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);
@@ -149,14 +135,14 @@ public class TestEntier {
781,
179892,
};
System.out.println("\tExécution du test de getValeur()");
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()
* Test unitaire de la méthode somme(Entier, Entier)
*/
public void testSomme() {
final Entier[] ATTENDUS = {
@@ -172,7 +158,7 @@ public class TestEntier {
new Entier(1562),
new Entier(359784),
};
System.out.println("\tExécution du test de somme(Entier, Entier)");
for (int i = 0; i < ENTIERS_INT.length; i++) {
assertTrue(somme(ENTIERS_INT[i], ENTIERS_INT[i])
.compareTo(ATTENDUS[i]) == 0);
@@ -184,7 +170,7 @@ public class TestEntier {
*/
public void testSoustrait() {
Entier zero = new Entier(0);
System.out.println("\tExécution du test de soustrait(Entier, Entier)");
for (int i = 0; i < ENTIERS_INT.length; i++) {
assertTrue(soustrait(ENTIERS_INT[i], ENTIERS_INT[i])
.compareTo(zero) == 0);
@@ -208,7 +194,7 @@ public class TestEntier {
new Entier(781 * 781),
new Entier(179892 * 179892),
};
System.out.println("\tExécution du test de multiplie(Entier, Entier)");
for (int i = 0; i < ENTIERS_INT.length; i++) {
assertTrue(multiplie(ENTIERS_INT[i], ENTIERS_INT[i])
.compareTo(ATTENDUS[i]) == 0);
@@ -234,7 +220,7 @@ public class TestEntier {
new Entier(390),
new Entier(89946)
};
System.out.println("\tExécution du test de quotient(Entier, Entier)");
for (int i = 0; i < ENTIERS_INT.length; i++) {
assertTrue(quotient(ENTIERS_INT[i], DIVISEUR)
.compareTo(ATTENDUS[i]) == 0);
@@ -246,7 +232,8 @@ public class TestEntier {
*/
public void testQuotientParZero() {
final Entier DIVISEUR = new Entier(0);
System.out.println("\tExécution du test de "
+ "quotient(Entier, Entier) par 0");
for (int i = 0; i < ENTIERS_INT.length; i++) {
try {
quotient(ENTIERS_INT[i], DIVISEUR);
@@ -276,7 +263,7 @@ public class TestEntier {
new Entier(1),
new Entier(0)
};
System.out.println("\tExécution du test de reste(Entier, Entier)");
for (int i = 0; i < ENTIERS_INT.length; i++) {
assertTrue(reste(ENTIERS_INT[i], DIVISEUR)
.compareTo(ATTENDUS[i]) == 0);
@@ -288,7 +275,8 @@ public class TestEntier {
*/
public void testResteParZero() {
final Entier DIVISEUR = new Entier(0);
System.out.println("\tExécution du test de "
+ "reste(Entier, Entier) par 0");
for (int i = 0; i < ENTIERS_INT.length; i++) {
try {
reste(ENTIERS_INT[i], DIVISEUR);
@@ -1,171 +1,172 @@
/**
* TestLitteraux.java 7 mai 2021
* IUT info1 2020-2021, pas de copyright, aucun droit
*/
package interpreteurlir.donnees.litteraux.tests;
import interpreteurlir.donnees.litteraux.Litteral;
/**
* Test unitaires des constantes littérales de l'interpréteurlir
* @author Nicolas Caminade
* @author Sylvan Courtiol
* @author Pierre Debas
* @author Heïa Dexter
* @author Lucas Vabre
*/
public class TestLitteraux {
/** Jeux de littéraux pour test. */
private static final Litteral[] VALIDES = {
/* Caractères */
new Litteral('a'),
new Litteral('!'),
new Litteral('\"'),
new Litteral('1'),
new Litteral('\t'),
/* Chaînes */
new Litteral("ceci est une chaine"),
new Litteral("bonjour"),
new Litteral(" bonjour "),
new Litteral(""),
new Litteral(" "),
/* Entier */
new Litteral(123),
new Litteral(-123),
new Litteral(0),
new Litteral(Integer.MAX_VALUE),
/* Double */
new Litteral(14.258),
new Litteral(-14.128),
new Litteral(0.0),
new Litteral(Double.NaN),
new Litteral(Double.NEGATIVE_INFINITY),
new Litteral(Double.MAX_VALUE),
new Litteral(Double.MIN_VALUE),
new Litteral(Double.MIN_NORMAL),
/* Boolean */
new Litteral(true),
new Litteral(false),
new Litteral(3 >= 4),
new Litteral(true),
new Litteral(true),
new Litteral(true)
};
/** test de getValeur */
public static void testGetValeur() {
final Object[] VALEURS_ATTENDUES = {
'a', '!', '\"', '1', '\t' ,"ceci est une chaîne", "bonjour",
" bonjour ", "", " ", 123, -123, 0, 2147483647, 14.258, -14.128,
0.0, Double.NaN, Double.NEGATIVE_INFINITY, Double.MAX_VALUE,
Double.MIN_VALUE, Double.MIN_NORMAL, true, false, false, true, true,
true
};
System.out.println("test de getValeur\n");
for (int i = 0 ; i < VALIDES.length ; i++) {
try {
assert (VALIDES[i].getValeur().equals(VALEURS_ATTENDUES[i]));
} catch (AssertionError lancee) {
System.err.println("Echec du test a l'indice " + i);
}
}
System.out.println("==>test terminé\n");
}
/** test de toString */
public static void testToString() {
final String[] STRING_ATTENDUE = {
"a", "!", "\"", "1", "\t", "ceci est une chaîne", "bonjour",
" bonjour ", "", " ", "123", "-123", "0", "2147483647", "14.258",
"-14.128", "0.0", "NaN", "-Infinity", "1.7976931348623157E308",
"4.9E-324", "2.2250738585072014E-308", "true", "false", "false",
"true", "true", "true"
};
System.out.println("test de toString\n");
for (int i = 0 ; i < VALIDES.length ; i++ ) {
try {
assert (VALIDES[i].toString().equals(STRING_ATTENDUE[i]));
} catch (AssertionError lancee) {
System.err.println("Echec du test a l'indice " + i);
}
}
System.out.println("==>test terminé\n");
}
/** test de compareTo */
public static void testCompareTo() {
final Litteral[] MEMES_TYPES = {
new Litteral('a'),
new Litteral('!'),
new Litteral('\"'),
new Litteral('Z'),
new Litteral('s'),
new Litteral("bonjour"),
new Litteral("bonjour"),
new Litteral("arar"),
new Litteral("zarar za "),
new Litteral("CAFE_BABE"),
new Litteral(123),
new Litteral(123),
new Litteral(0),
new Litteral(-123),
new Litteral(Double.MAX_VALUE),
new Litteral(Double.NaN),
new Litteral(12.3),
new Litteral(Double.NaN),
new Litteral(45.7),
new Litteral(-12.6),
new Litteral(0.0),
new Litteral(Double.MIN_NORMAL),
new Litteral(false),
new Litteral(false),
new Litteral(true),
new Litteral(true),
new Litteral(true),
new Litteral(true)
};
System.out.println("test de compareTo\nAvec des types identiques");
for (int i = 0 ; i < VALIDES.length ; i++ ) {
try {
assert (VALIDES[i].compareTo(MEMES_TYPES[i]) == 0);
} catch (AssertionError lancee) {
System.err.println("Echec du test a l'indice " + i);
}
}
System.out.println("Avec des types différents");
for (int i = 0 ; i < VALIDES.length ; i++ ) {
try {
assert (VALIDES[i].compareTo(MEMES_TYPES[MEMES_TYPES.length
- (i + 1)]) != 0);
} catch (AssertionError lancee) {
System.err.println("Echec du test a l'indice " + i);
}
}
System.out.println("==>test terminé\n");
}
/**
* Lancement des test
* @param args non utilisé
*/
public static void main(String[] args) {
testGetValeur();
testToString();
testCompareTo();
}
}
// Classe testée passé en abstract
///**
// * TestLitteraux.java 7 mai 2021
// * IUT info1 2020-2021, pas de copyright, aucun droit
// */
//package interpreteurlir.donnees.litteraux.tests;
//
//import interpreteurlir.donnees.litteraux.Litteral;
//
///**
// * Test unitaires des constantes littérales de l'interpréteurlir
// * @author Nicolas Caminade
// * @author Sylvan Courtiol
// * @author Pierre Debas
// * @author Heïa Dexter
// * @author Lucas Vabre
// */
//public class TestLitteraux {
//
// /** Jeux de littéraux pour test. */
// private static final Litteral[] VALIDES = {
// /* Caractères */
// new Litteral('a'),
// new Litteral('!'),
// new Litteral('\"'),
// new Litteral('1'),
// new Litteral('\t'),
// /* Chaînes */
// new Litteral("ceci est une chaine"),
// new Litteral("bonjour"),
// new Litteral(" bonjour "),
// new Litteral(""),
// new Litteral(" "),
// /* Entier */
// new Litteral(123),
// new Litteral(-123),
// new Litteral(0),
// new Litteral(Integer.MAX_VALUE),
// /* Double */
// new Litteral(14.258),
// new Litteral(-14.128),
// new Litteral(0.0),
// new Litteral(Double.NaN),
// new Litteral(Double.NEGATIVE_INFINITY),
// new Litteral(Double.MAX_VALUE),
// new Litteral(Double.MIN_VALUE),
// new Litteral(Double.MIN_NORMAL),
// /* Boolean */
// new Litteral(true),
// new Litteral(false),
// new Litteral(3 >= 4),
// new Litteral(true),
// new Litteral(true),
// new Litteral(true)
// };
//
// /** test de getValeur */
// public static void testGetValeur() {
//
// final Object[] VALEURS_ATTENDUES = {
// 'a', '!', '\"', '1', '\t' ,"ceci est une chaîne", "bonjour",
// " bonjour ", "", " ", 123, -123, 0, 2147483647, 14.258, -14.128,
// 0.0, Double.NaN, Double.NEGATIVE_INFINITY, Double.MAX_VALUE,
// Double.MIN_VALUE, Double.MIN_NORMAL, true, false, false, true, true,
// true
// };
//
// System.out.println("test de getValeur\n");
//
// for (int i = 0 ; i < VALIDES.length ; i++) {
//
// try {
// assert (VALIDES[i].getValeur().equals(VALEURS_ATTENDUES[i]));
// } catch (AssertionError lancee) {
// System.err.println("Echec du test a l'indice " + i);
// }
// }
// System.out.println("==>test terminé\n");
// }
//
// /** test de toString */
// public static void testToString() {
//
// final String[] STRING_ATTENDUE = {
// "a", "!", "\"", "1", "\t", "ceci est une chaîne", "bonjour",
// " bonjour ", "", " ", "123", "-123", "0", "2147483647", "14.258",
// "-14.128", "0.0", "NaN", "-Infinity", "1.7976931348623157E308",
// "4.9E-324", "2.2250738585072014E-308", "true", "false", "false",
// "true", "true", "true"
// };
//
// System.out.println("test de toString\n");
//
// for (int i = 0 ; i < VALIDES.length ; i++ ) {
//
// try {
// assert (VALIDES[i].toString().equals(STRING_ATTENDUE[i]));
// } catch (AssertionError lancee) {
// System.err.println("Echec du test a l'indice " + i);
// }
// }
// System.out.println("==>test terminé\n");
// }
//
// /** test de compareTo */
// public static void testCompareTo() {
//
// final Litteral[] MEMES_TYPES = {
// new Litteral('a'),
// new Litteral('!'),
// new Litteral('\"'),
// new Litteral('Z'),
// new Litteral('s'),
// new Litteral("bonjour"),
// new Litteral("bonjour"),
// new Litteral("arar"),
// new Litteral("zarar za "),
// new Litteral("CAFE_BABE"),
// new Litteral(123),
// new Litteral(123),
// new Litteral(0),
// new Litteral(-123),
// new Litteral(Double.MAX_VALUE),
// new Litteral(Double.NaN),
// new Litteral(12.3),
// new Litteral(Double.NaN),
// new Litteral(45.7),
// new Litteral(-12.6),
// new Litteral(0.0),
// new Litteral(Double.MIN_NORMAL),
// new Litteral(false),
// new Litteral(false),
// new Litteral(true),
// new Litteral(true),
// new Litteral(true),
// new Litteral(true)
// };
//
// System.out.println("test de compareTo\nAvec des types identiques");
//
// for (int i = 0 ; i < VALIDES.length ; i++ ) {
//
// try {
// assert (VALIDES[i].compareTo(MEMES_TYPES[i]) == 0);
// } catch (AssertionError lancee) {
// System.err.println("Echec du test a l'indice " + i);
// }
// }
// System.out.println("Avec des types différents");
//
// for (int i = 0 ; i < VALIDES.length ; i++ ) {
//
// try {
// assert (VALIDES[i].compareTo(MEMES_TYPES[MEMES_TYPES.length
// - (i + 1)]) != 0);
// } catch (AssertionError lancee) {
// System.err.println("Echec du test a l'indice " + i);
// }
// }
// System.out.println("==>test terminé\n");
// }
//
// /**
// * Lancement des test
// * @param args non utilisé
// */
// public static void main(String[] args) {
// testGetValeur();
// testToString();
// testCompareTo();
// }
//}
@@ -1,115 +1,118 @@
/**
* TestIdentificateur.java 8 mai 2021
* IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
*/
package interpreteurlir.donnees.tests;
// Classe testée passé en abstract
import static info1.outils.glg.Assertions.*;
///**
// * TestIdentificateur.java 8 mai 2021
// * IUT-Rodez info1 2020-2021, pas de droits, pas de copyrights
// */
//package interpreteurlir.donnees.tests;
//
//import static info1.outils.glg.Assertions.*;
//
//import interpreteurlir.InterpreteurException;
//import interpreteurlir.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 25 caractères
// "$jeSuisUnTresLongIdentificateur", // 30 char
// "$jeSuisUnTresLongIdentifica",
//
// // 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 (InterpreteurException 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);
// }
// }
//
// /**
// * Tests unitaires de toString
// */
// public static void testToString() {
// final String[] CHAINES_VALIDES = {
// "b",
// "A",
// "zalpha",
// "Alpha",
// "Alpha5",
// "jeSuisUnTresLongIdentifi",
// "$b",
// "z",
// "$zalpha",
// "$Alpha",
// "$Alpha5",
// "$jeSuisUnTresLongIdentifi"
// };
//
// for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
// assertEquivalence(CHAINES_VALIDES[noJeu],
// FIXTURE[noJeu].toString());
// }
// }
//}
import interpreteurlir.InterpreteurException;
import interpreteurlir.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 25 caractères
"$jeSuisUnTresLongIdentificateur", // 30 char
"$jeSuisUnTresLongIdentifica",
// 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 (InterpreteurException 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);
}
}
/**
* Tests unitaires de toString
*/
public static void testToString() {
final String[] CHAINES_VALIDES = {
"b",
"A",
"zalpha",
"Alpha",
"Alpha5",
"jeSuisUnTresLongIdentifi",
"$b",
"z",
"$zalpha",
"$Alpha",
"$Alpha5",
"$jeSuisUnTresLongIdentifi"
};
for (int noJeu = 0 ; noJeu < CHAINES_VALIDES.length ; noJeu++) {
assertEquivalence(CHAINES_VALIDES[noJeu],
FIXTURE[noJeu].toString());
}
}
}
@@ -31,11 +31,11 @@ public class TestIdentificateurChaine {
};
/**
* Tests unitaires du constructeur IdentificateurEntier(String identificateur)
* Tests unitaires du constructeur
* IdentificateurEntier(String identificateur)
*/
public static void testIdentificateurChaineString() {
final String[] INVALIDE = {
null,
"",
// Commence par une lettre
@@ -62,7 +62,8 @@ public class TestIdentificateurChaine {
"$",
"$1"
};
System.out.println("\tExécution du test de "
+ "IdentificateurEntier(String identificateur)");
for(int noJeu = 0; noJeu < INVALIDE.length ; noJeu++) {
try {
new IdentificateurChaine(INVALIDE[noJeu]);
@@ -87,6 +88,7 @@ public class TestIdentificateurChaine {
"$jeSuisUnTresLongIdentifi"
};
System.out.println("\tExécution du test de getNom()");
for (int noJeu = 0 ; noJeu < NOM_VALIDES.length ; noJeu++) {
assertEquivalence(NOM_VALIDES[noJeu], FIXTURE[noJeu].getNom());
}
@@ -63,36 +63,24 @@ public class TestVariable {
new Chaine("\"titi\n\"")
};
// /** Jeu d'entiers valides */
// private static final Entier[] VALEUR_ENTIER = {
// // TODO: jeu d'entiers valide
// };
/** Jeu de variables chaîne valides*/
private static Variable[] fixtureChaine = new Variable[ID_CHAINE.length];
/* Jeu de variables entières valides*/
//private static Variable[] fixtureEntier= new Variable[ID_ENTIER.length];
private static Variable[] fixtureChaine = new Variable[ID_CHAINE.length];
private static void fixtureReload() {
for (int i = 0; i < ID_CHAINE.length; i++) {
fixtureChaine[i] = new Variable(ID_CHAINE[i], VALEURS_CHAINE[i]);
}
//TODO reload fixtureEntier
}
/**
* Test unitaire du constructeur Variable(Identificateur, Littéral)
*/
public static void testVariableIdentificateurChaineLitteral() {
System.out.println("\tExécution du test de "
+ "Variable(Identificateur, Littéral)");
for (int noJeu = 0; noJeu < VALEURS_CHAINE.length; noJeu++) {
try {
//new Variable(ID_CHAINE[noJeu], VALEURS_CHAINE[noJeu]); // bouchon
new Variable(ID_ENTIER[noJeu], VALEURS_CHAINE[noJeu]);
// TODO tester avec la classe Entier
// new Variable(ID_CHAINE[noJeu], VALEURS_ENTIER[noJeu]);
echec();
} catch (InterpreteurException lancee) {
// test OK
@@ -106,32 +94,21 @@ public class TestVariable {
public static void testGetIdentificateurChaine() {
fixtureReload();
System.out.println("\tExécution du test de getIdentificateur()");
for (int i = 0; i < VALEURS_CHAINE.length; i++ ) {
assertTrue(ID_CHAINE[i].compareTo(fixtureChaine[i]
.getIdentificateur()) == 0);
}
}
/**
* Test unitaire de getIdentificateur() d'une variable entière
*/
public static void testGetIdentificateurEntier() {
// fixtureReload();
//
// for (int i = 0; i < VALEURS_Entier.length; i++ ) {
// assertTrue(ID_ENTIER[i].compareTo(fixtureEntier[i]
// .getIdentificateur()) == 0);
// }
echec();
}
/**
* Test unitaire de getValeur() d'une variable chaîne
*/
public static void testGetValeurChaine() {
fixtureReload();
System.out.println("\tExécution du test de getValeur()");
for (int i = 0; i < VALEURS_CHAINE.length; i++ ) {
assertTrue(VALEURS_CHAINE[i]
.compareTo(fixtureChaine[i].getValeur()) == 0);
@@ -153,6 +130,7 @@ public class TestVariable {
new Chaine("\"-5 + 962\"")
};
System.out.println("\tExécution du test de setValeur()");
for (int i = 0; i < NOUVELLE_CHAINE.length; i++) {
fixtureChaine[i].setValeur(NOUVELLE_CHAINE[i]);
assertTrue(NOUVELLE_CHAINE[i]
@@ -178,7 +156,7 @@ public class TestVariable {
"$MichelSardou = \"tata\t\"",
"$PhilippePoutou2022 = \"titi\n\""
};
System.out.println("\tExécution du test de toString()");
for (int noJeu = 0; noJeu < fixtureChaine.length; noJeu++ ) {
assertEquivalence(fixtureChaine[noJeu].toString(),
ATTENDUS[noJeu]);
@@ -199,12 +177,12 @@ public class TestVariable {
= new Variable(new IdentificateurChaine("$z"),
new Chaine("\"Max\""));
System.out.println("\tExécution du test de compareTo");
for(int noJeu = 0; noJeu < fixtureChaine.length; noJeu++) {
assertTrue(fixtureChaine[noJeu].compareTo(REF_MIN) > 0);
assertTrue(fixtureChaine[noJeu].compareTo(REF_MAX) < 0);
assertTrue(fixtureChaine[noJeu].compareTo(fixtureChaine[noJeu]) == 0);
}
// TODO Faire le même test pour les variables contenant des entiers
}
}