From 07402684191baea3af3f3b527c0471e5d636622b Mon Sep 17 00:00:00 2001 From: trochas Date: Fri, 5 Dec 2025 13:00:29 +0100 Subject: [PATCH] correction couverture de test Date --- .../main/java/fr/istic/vv/StringUtils.java | 62 +++++++++-- .../java/fr/istic/vv/StringUtilsTest.java | 104 ++++++++++++++++-- .../src/main/java/fr/istic/vv/Date.java | 21 ++-- .../src/test/java/fr/istic/vv/DateTest.java | 2 + exercises/balanced-strings.md | 30 +++++ 5 files changed, 191 insertions(+), 28 deletions(-) diff --git a/code/tp3-balanced-strings/src/main/java/fr/istic/vv/StringUtils.java b/code/tp3-balanced-strings/src/main/java/fr/istic/vv/StringUtils.java index 07c52e6..c0422c8 100644 --- a/code/tp3-balanced-strings/src/main/java/fr/istic/vv/StringUtils.java +++ b/code/tp3-balanced-strings/src/main/java/fr/istic/vv/StringUtils.java @@ -1,21 +1,65 @@ package fr.istic.vv; +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.Queue; +import java.util.Set; + public class StringUtils { private StringUtils() {} - public static boolean isBalanced(String str) { + static Set OPEN = Set.of('(', '[', '{'); + static Set CLOSE = Set.of(')', ']', '}'); + public static final Map CONVERT; - return false; + static { + CONVERT = new HashMap<>(); + CONVERT.put('(', ')'); + CONVERT.put('{', '}'); + CONVERT.put('[', ']'); + } + + + + public static boolean isBalanced(String str) { + Deque balancedQueue = new ArrayDeque(); + + return reqIsBalanced(str, balancedQueue); } - public static String reqIsBalanced(String str){ - String all = "[\\[\\(\\{\\]\\)\\}\"]"; - String openRegex = "[\\[\\(\\{\"]"; - String closeRegex = "[\\]\\)\\}\"]"; - String regex = "^[^"+all+"]*"+openRegex+"."+closeRegex+"^["+all+"]*"; - - return str; + public static boolean reqIsBalanced(String str,Deque balancedQueue){ + int nbRemove = 1; + if(str.length()>0){ + char c=str.charAt(0); + while(true){ + if(OPEN.contains(c)){ + balancedQueue.push(c); + + return reqIsBalanced(str.substring(nbRemove), balancedQueue); + } + else if(CLOSE.contains(c)){ + if(balancedQueue.isEmpty()){ + return false; + } + else if(CONVERT.get(balancedQueue.pollFirst()) == c){ + return reqIsBalanced(str.substring(nbRemove),balancedQueue); + } + else{ + return false; + } + } + else if(nbRemove { int max_day = max_day(m, y); if (d < max_day) { return new Date(d + 1, m, y); - } else if (d == max_day) { + } else { if (m == 12) { return new Date(1, 1, y + 1); } else { return new Date(1, m + 1, y); } } - return null; // This line should never be reached } public Date previousDate() { @@ -64,18 +63,16 @@ class Date implements Comparable { if (other == null) { throw new NullPointerException(); } - if (isValidDate(other.getDay(), other.getMonth(), other.getYear())) { - int cmpYear = Integer.compare(this.getYear(), other.getYear()); - if (cmpYear != 0) - return cmpYear; + int cmpYear = Integer.compare(this.getYear(), other.getYear()); + if (cmpYear != 0) + return cmpYear; - int cmpMonth = Integer.compare(this.getMonth(), other.getMonth()); - if (cmpMonth != 0) - return cmpMonth; + int cmpMonth = Integer.compare(this.getMonth(), other.getMonth()); + if (cmpMonth != 0) + return cmpMonth; + + return Integer.compare(this.getDay(), other.getDay()); - return Integer.compare(this.getDay(), other.getDay()); - } - throw new IllegalArgumentException("The date to compare is not valid"); } public int getDay() { diff --git a/code/tp3-date/src/test/java/fr/istic/vv/DateTest.java b/code/tp3-date/src/test/java/fr/istic/vv/DateTest.java index 2c136e9..944b3f8 100644 --- a/code/tp3-date/src/test/java/fr/istic/vv/DateTest.java +++ b/code/tp3-date/src/test/java/fr/istic/vv/DateTest.java @@ -204,4 +204,6 @@ class DateTest { Date d2 = new Date(5, 5, 2025); assertEquals(0, d1.compareTo(d2)); } + + } \ No newline at end of file diff --git a/exercises/balanced-strings.md b/exercises/balanced-strings.md index 29f415a..3f42e93 100644 --- a/exercises/balanced-strings.md +++ b/exercises/balanced-strings.md @@ -26,3 +26,33 @@ Use the project in [tp3-balanced-strings](../code/tp3-balanced-strings) to compl ## Answer +1. +Test simple true: +"{}","[]","()","(a)","a[b]","" et "test" + +des test simple false : +"{]","(}","[)","a{]","(b}" + +des Test avec des parenthèsé qui se suivent : +"{}()a[a]" + +La même chose avec des erreur : +"{}()a[a}" + +des Test avec des parenthèse imbriqué : +"white(true){println("Tester c'est pas douter")} + +des Test avec des oublies, d'ouverture et fermeture: +"whitetrue){println("Tester c'est pas douter")}", +"white(true{println("Tester c'est pas douter")}" + + +2. +avec ses tests la couverture est à 100% + +3. +toutes les conditions n'ont qu'un seul opérateur boolean + +4. + +un mutant qui remplacé un return par un return true, il s'agit du cas ou le programme avec une erreur de parenthésage fini par des caractère, ex : "(a" on peut donc le rajouter dans les "test simple" \ No newline at end of file