This commit is contained in:
2026-10-14 11:34:55 +02:00
parent cecf7379f6
commit 12f12ca496
3 changed files with 81 additions and 9 deletions
+58
View File
@@ -0,0 +1,58 @@
# 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** |
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

+23 -9
View File
@@ -35,10 +35,7 @@ def mention(moyenne):
# Exercice P5
def analyser_mot_de_passe(mdp, login=None):
problemes = []
if len(mdp) < 12:
problemes.append("trop court")
def categories_presentes(mdp):
majuscule = minuscule = chiffre = special = False
for c in mdp:
if c.isupper():
@@ -49,7 +46,26 @@ def analyser_mot_de_passe(mdp, login=None):
chiffre = True
else:
special = True
if not (majuscule and minuscule):
return majuscule, minuscule, chiffre, special
def melange_casses(majuscule, minuscule):
return majuscule and minuscule
def contient_repetition(mdp):
for i in range(len(mdp) - 2):
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
return True
return False
def analyser_mot_de_passe(mdp, login=None):
problemes = []
if len(mdp) < 12:
problemes.append("trop court")
majuscule, minuscule, chiffre, special = categories_presentes(mdp)
if not melange_casses(majuscule, minuscule):
problemes.append("mélanger majuscules et minuscules")
if not chiffre:
problemes.append("ajouter un chiffre")
@@ -57,10 +73,8 @@ def analyser_mot_de_passe(mdp, login=None):
problemes.append("ajouter un caractère spécial")
if login and login.lower() in mdp.lower():
problemes.append("ne pas contenir le login")
for i in range(len(mdp) - 2):
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
problemes.append("éviter 3 caractères identiques")
break
if contient_repetition(mdp):
problemes.append("éviter 3 caractères identiques")
if not problemes:
return "fort", []
return ("moyen" if len(problemes) <= 2 else "faible"), problemes