# TD — Complexité cyclomatique : questions 1, 2 et 3 Nathan COUCHOT et Lucas POT ## 1. Graphes de flot de contrôle Voir diagramme (DIAGRAMME.png). ## 2. Compter les décisions de toutes les fonctions | C1 | `carre` | Aucune décision | 0 + 1 = **1** | | C2 | `moyenne` | 1 `for` + 1 `if`| 2 + 1 = **3** | | C3 | `est_bissextile` | 1 `&&` + 1 `||` | 2 + 1 = **3** | | C4 | `nom_jour` | 7 `case` | 7 + 1 = **8** | | C5 | `compter_mots` | 1 `while` + 4 `||` + 1 `if` + 1 `else if` | 7 + 1 = **8** | | C6 | `date_valide` | 4 `if`/`else if` + 3 `||` + 3 `||` | 10 + 1 = **11** | | J1 | `nombreDeLivres` | Aucune décision | 0 + 1 = **1** | | J2 | `estDisponible` | 2 `&&` | 2 + 1 = **3** | | J3 | `peutEmprunter` | 7 `if`/`else if` + 1 `&&` | 8 + 1 = **9** | | J4 | `calculerPenalite` | 6 `if`/`else if` + 1 `||` + 1 `for` | 8 + 1 = **9** | | J5 | `rechercher` | 1 `for` + 5 `if` + 2 `&&` + 2 `||` | 10 + 1 = **11** | | J6 | `importer` | 1 `for` + 3 `if` + 1 `||` + 1 `&&` + 1 `catch` | 7 + 1 = **8** | | P1 | `celsius_vers_fahrenheit` | Aucune décision | 0 + 1 = **1** | | P2 | `signe` | 1 `if` + 1 `elif` | 2 + 1 = **3** | | P3 | `notes_valides` | 1 `for` + 1 `if` | 2 + 1 = **3** | | P4 | `mention` | 1 `for` + 1 `if` | 2 + 1 = **3** | | P5 | `analyser_mot_de_passe` | 11 `if`/`elif` + 2 `for` + 2 `and`| 15 + 1 = **16** | ## 3. Classer C1 = simple C2 = simple C3 = simple C4 = moyen C5 = moyen C6 = complexe J1 = simple J2 = simple J3 = complexe J4 = complexe J5 = complexe J6 = complexe P1 = simple P2 = simple P3 = moyen P4 = moyen P5 = complexe ## 5. Refactoriser La fonction P5 `analyser_mot_de_passe` passe de **M = 16 à M = 10**. Trois autres fonctions extraient la recherche des catégories de caractères, le mélange des casses et la détection des répétitions. Les messages, leur ordre et le classement du mot de passe sont conservés. | Fonction après refactorisation | Décisions | Calcul de M | |---|---|---| | `analyser_mot_de_passe` | 8 `if` + 1 `and`| 9 + 1 = **10** | | `categories_presentes` | 1 `for` + 1 `if` + 2 `elif` | 4 + 1 = **5** | | `melange_casses` | 1 `and` | 1 + 1 = **2** | | `contient_repetition` | 1 `for` + 1 `if` | 2 + 1 = **3** |