✏️ Exercices : Approche combinatoire
1. Exercice 1 : daysInMonth
On souhaite tester la méthode suivante :
/**
* Determines the number of days in a given month of the year.
* Takes leap year into account for February.
*
* @param month The month number. Should be between 1 and 12.
* @param year The year. Should be between 2000 and 2100.
* @return The number of days in the given month, or -1 if arguments are invalid.
**/
public static int daysInMonth(int month, int year)
1.1. Question 1
Identifiez les paramètres d’entrée de la méthode (domaine d’entrée), ainsi les valeurs observables en résultat (domaine de sortie).
1.2. Question 2
Proposez un arbre de classification (et, si besoin, des contraintes entre choix) pour tester cette méthode.
2. Exercice 2 : addBook
Soit l’interface Java suivante :
public interface Library {
/**
* Return the maximum size of the library.
* Is always superior to zero.
* (the maximum number of books)
*/
public int getMaximumSize();
/**
* Return a non-null, read-only view of the list of all books already in the library.
*/
public List<String> getBooks();
/**
* Add a book to the library.
* Does nothing if the library is already full.
* @param title The title of the book.
* @throws IllegalArgumentException If the title is empty, or if it only contains whitespaces, or if it is null.
*/
public void addBook(String title);
...
}
Nous souhaitons tester la méthode addBook.
2.1. Question 1
Identifiez les paramètres d’entrée de la méthode (domaine d’entrée), ainsi les valeurs observables en résultat (domaine de sortie).
2.2. Question 2
Proposez un arbre de classification (et, si besoin, des contraintes entre choix) pour tester cette méthode.
2.3. Question 3
Combien de combinaisons au total peuvent être énumérées à partir de votre arbre ?
Est-ce qu’un critère de couverture serait pertinent ici, et si oui lequel ?
3. Exercice 3 : typeOfTriangle
Soit à tester la méthode :
/**
* Determines the type of a triangle based on the lengths of its sides:
*
* @return ISOSCELES if two sides are equal, EQUILATERAL if three are equal, SCALENE otherwise
* @throws InvalidTriangleException if a length is negative or if lengths cannot represent a triangle
*/
public static TypeTriangle typeOfTriangle(double length1, double length2, double length3) throws InvalidTriangleException
avec :
enum TypeTriangle {
ISOSCELES,
EQUILATERAL,
SCALENE
}
3.1. Question 1
Identifiez les paramètres d’entrée de la méthode (domaine d’entrée), ainsi les valeurs observables en résultat (domaine de sortie).