Compare commits
2 Commits
MalcuitEmi
...
09cf3836c2
Author | SHA1 | Date | |
---|---|---|---|
09cf3836c2 | |||
19d2e618c3 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1 @@
|
|||||||
/target/
|
/target/
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
*.xml
|
|
||||||
>>>>>>> 6e8f63e2c0b4f89a6f46070511e8ce4223af4bb7
|
|
||||||
|
@@ -12,22 +12,7 @@ public class LivreValide {
|
|||||||
// 1. ISBN : exactement 13 chiffres
|
// 1. ISBN : exactement 13 chiffres
|
||||||
public static boolean isValidIsbn(String isbn) {
|
public static boolean isValidIsbn(String isbn) {
|
||||||
// TODO Emile: implémenter la validation
|
// TODO Emile: implémenter la validation
|
||||||
|
return false;
|
||||||
boolean valide = true;
|
|
||||||
if(isbn.length() == 13){
|
|
||||||
int i = 0;
|
|
||||||
while (i < 13 && valide) {
|
|
||||||
if(!Character.isDigit(isbn.charAt(i))){
|
|
||||||
valide = false;
|
|
||||||
}else{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
valide = false;
|
|
||||||
}
|
|
||||||
return valide;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Titre : pas de balises HTML/JS (<script>, <img>, etc.)
|
// 2. Titre : pas de balises HTML/JS (<script>, <img>, etc.)
|
||||||
@@ -45,7 +30,11 @@ public class LivreValide {
|
|||||||
// 4. Titre : longueur maximale 200 caractères
|
// 4. Titre : longueur maximale 200 caractères
|
||||||
public static boolean isLongueurTitreValid(String titre) {
|
public static boolean isLongueurTitreValid(String titre) {
|
||||||
// TODO Morgann: implémenter la validation
|
// TODO Morgann: implémenter la validation
|
||||||
return false;
|
boolean valide = false;
|
||||||
|
if(titre.length()<=200 && titre != "" && titre != null){
|
||||||
|
valide = true;
|
||||||
|
}
|
||||||
|
return valide;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Titre : non null et au moins 2 caractères
|
// 5. Titre : non null et au moins 2 caractères
|
||||||
|
@@ -16,7 +16,7 @@ public void testCreationLivre() {
|
|||||||
|
|
||||||
assertNotNull(b);
|
assertNotNull(b);
|
||||||
assertEquals("1984", b.getTitre());
|
assertEquals("1984", b.getTitre());
|
||||||
assertEquals("George Orwel", b.getAuteur()); // corrigé
|
assertEquals("George Orwell", b.getAuteur()); // corrigé
|
||||||
assertEquals("1234567890123", b.getIsbn());
|
assertEquals("1234567890123", b.getIsbn());
|
||||||
assertFalse(b.isEmprunte()); // si la méthode existe
|
assertFalse(b.isEmprunte()); // si la méthode existe
|
||||||
}
|
}
|
||||||
|
@@ -29,48 +29,12 @@ public class LivreValideTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsValidIsbn() {
|
public void testIsValidIsbn() {
|
||||||
System.out.println("isValidIsbn");
|
System.out.println("isValidIsbn");
|
||||||
|
String isbn = "";
|
||||||
|
boolean expResult = false;
|
||||||
//Test 1 : un isbn avec moins de 13 carractères
|
boolean result = LivreValide.isValidIsbn(isbn);
|
||||||
System.out.println("Test1 : un isbn avec moins de 13 carractères");
|
assertEquals(expResult, result);
|
||||||
String isbn1 = "1234568912";
|
// TODO review the generated test code and remove the default call to fail.
|
||||||
boolean expResult1 = false;
|
fail("The test case is a prototype.");
|
||||||
boolean result1 = LivreValide.isValidIsbn(isbn1);
|
|
||||||
assertEquals("Le nombre de carractère est censé est trop petit",expResult1, result1);
|
|
||||||
System.out.println("Le test1 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test2 : lettre dans l'isbn
|
|
||||||
System.out.println("Test2 : lettre dans l'isbn");
|
|
||||||
String isbn2 = "123456789ABC2";
|
|
||||||
boolean expResult2 = false;
|
|
||||||
boolean result2 = LivreValide.isValidIsbn(isbn2);
|
|
||||||
assertEquals("Les alphas ne sont pas autorisés", expResult2, result2);
|
|
||||||
System.out.println("Le test2 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test3 : mauvais nombre de carratère 15
|
|
||||||
System.out.println("Test3: isbn comportant plus de 13 chiffres");
|
|
||||||
String isbn3 = "1234568912123568";
|
|
||||||
boolean expResult3 = false;
|
|
||||||
boolean result3 = LivreValide.isValidIsbn(isbn3);
|
|
||||||
assertEquals("Le nombre de carractère est censé est trop grand",expResult3, result3);
|
|
||||||
System.out.println("Le test3 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test4 : Un isbn valide
|
|
||||||
System.out.println("Test4: Un isbn valide");
|
|
||||||
String isbn4 = "1234568912126";
|
|
||||||
boolean expResult4 = true;
|
|
||||||
boolean result4 = LivreValide.isValidIsbn(isbn4);
|
|
||||||
assertEquals("L'isbn est censé être valide",expResult4, result4);
|
|
||||||
System.out.println("Le test4 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,12 +74,30 @@ public class LivreValideTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsLongueurTitreValid() {
|
public void testIsLongueurTitreValid() {
|
||||||
System.out.println("isLongueurTitreValid");
|
System.out.println("isLongueurTitreValid");
|
||||||
String titre = "";
|
|
||||||
boolean expResult = false;
|
//test 1 : aucune valeur saisie
|
||||||
boolean result = LivreValide.isLongueurTitreValid(titre);
|
System.out.println("Test avec aucune valeur saisie");
|
||||||
assertEquals(expResult, result);
|
String titre1 = "";
|
||||||
// TODO review the generated test code and remove the default call to fail.
|
boolean expResult1 = false;
|
||||||
fail("The test case is a prototype.");
|
boolean result1 = LivreValide.isLongueurTitreValid(titre1);
|
||||||
|
assertEquals(expResult1, result1);
|
||||||
|
System.out.println("Titre invalide. Aucune valeur n'a été saisie\n");
|
||||||
|
|
||||||
|
//test 2 : titre inférieur à 200
|
||||||
|
System.out.println("Test avec aucune valeur saisie");
|
||||||
|
String titre2 = "Hadal Blacksite bestiary";
|
||||||
|
boolean expResult2 = true;
|
||||||
|
boolean result2 = LivreValide.isLongueurTitreValid(titre2);
|
||||||
|
assertEquals(expResult2, result2);
|
||||||
|
System.out.println("Titre valide. Le titre a moins de 200 caractères\n");
|
||||||
|
|
||||||
|
System.out.println("Test avec un titre avec plus de 200 caractères");
|
||||||
|
String titre3 = "YOU !! You could've had everything you ever wanted... Everything I ever wanted... And you still went out of your way to take everything I had left in the process. You entitled brat. You expect me to sit idly by and keep smiling, As if nothing ever happened? Oh, I'm smiling alright... GRINNING ear to ear. Don't even start with that 'following orders' schlock. You knew what you were doing all too well. Sure took your sweet time. Enjoyed every last second of it? Good. *Chuckles* EXCELLENT, even! I'll merely return the favor. And you bet, I'll be enjoying, every last moment, of THIS!!! THE BEST PART!? I get to do this, over, and over, again. You'll come back, I'll know, and I'll be waiting... You have no one to blame but yourself. You're in a hell of your own making... And you're NEVER GETTING OUT!!! *grrgh* WHAT!!! WHAT IS IT THIS TIME!?!?";
|
||||||
|
boolean expResult3 = false;
|
||||||
|
boolean result3 = LivreValide.isLongueurTitreValid(titre3);
|
||||||
|
assertEquals(expResult3, result3);
|
||||||
|
System.out.println("Titre invalide. Titre trop long\n");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user