2.4 KiB
Balanced strings
A string containing grouping symbols {}[]() is said to be balanced if every open symbol {[( has a matching closed symbol )]} and the substrings before, after and between each pair of symbols is also balanced. The empty string is considered as balanced.
For example: {[][]}({}) is balanced, while ][, ([)], {, {(}{} are not.
Implement the following method:
public static boolean isBalanced(String str) {
...
}
isBalanced returns true if str is balanced according to the rules explained above. Otherwise, it returns false.
Use the coverage criteria studied in classes as follows:
- Use input space partitioning to design an initial set of inputs. Explain below the characteristics and partition blocks you identified.
- Evaluate the statement coverage of the test cases designed in the previous step. If needed, add new test cases to increase the coverage. Describe below what you did in this step.
- If you have in your code any predicate that uses more than two boolean operators, check if the test cases written so far satisfy Base Choice Coverage. If needed, add new test cases. Describe below how you evaluated the logic coverage and the new test cases you added.
- Use PIT to evaluate the test suite you have so far. Describe below the mutation score and the live mutants. Add new test cases or refactor the existing ones to achieve a high mutation score.
Write below the actions you took on each step and the results you obtained. Use the project in tp3-balanced-strings to complete this exercise.
Answer
Test simple true: "()", "{}", "[]", "(abc)", "a[b]", "aaa{aaaa}aa", "" et "test"
des test simple false : "(]", "{)", "[}", ")(", "a{]", "a()b[c]{)}"
des Test avec des parenthèsé qui se suivent : "a()b[c]{}"
La même chose avec des erreur : "a()b[c]{)}"
des Test avec des parenthèse imbriqué : "white(true){println("Tester c'est pas douter");}"
des Test avec des oublies, d'ouverture et fermeture: "white(true){println("Tester c'est pas douter";}", "white(true){println"Tester c'est pas douter");}"
avec ses tests la couverture est à 100%
if(balancedQueue.isEmpty() || CONVERT.get(balancedQueue.pollFirst()) != c) if(A||B)
B est exécuté que si A est vrai, sinon B lèverait une exception
on a donc que 3 cas possibles : A B 1 1 1 1 0 0 0 err 0
mvn test-compile org.pitest:pitest-maven:mutationCoverage
Tout les mutants on été tué.