# Tests unitaires pour la fonction calcul_signaux_moteur(). # # IMPORTANT : # - Aucun résultat attendu n'est donné directement. # - Les élèves doivent connaître / déduire le comportement attendu # d'après l'énoncé du TP from logique_moteur import calcul_signaux_moteur def test(): pwm_max = 1000 # Test 1 : arrêt # Vérifier que les trois valeurs (in1, in2, pwm) correspondent à un moteur à l'arrêt sortie = calcul_signaux_moteur(0, pwm_max) assert sortie["in1"] == __0__ , "Test arrêt : valeur in1 incorrecte" assert sortie["in2"] == ___0_ , "Test arrêt : valeur in2 incorrecte" assert sortie["pwm"] == _0__ , "Test arrêt : valeur pwm incorrecte" # Test 2 : vitesse maximale en avant # Vérifier la direction et la valeur maximale du PWM sortie = calcul_signaux_moteur(100, pwm_max) assert sortie["in1"] == _1___ , "Test avant : in1 incorrect" assert sortie["in2"] == __0__ , "Test avant : in2 incorrect" assert sortie["pwm"] == __proportionel__ , "Test avant : pwm incorrect" # Test 3 : vitesse maximale en arrière # Vérifier la direction inverse et le PWM maximal sortie = calcul_signaux_moteur(-100, pwm_max) assert sortie["in1"] == ___0_ , "Test arrière : in1 incorrect" assert sortie["in2"] == ____1 , "Test arrière : in2 incorrect" assert sortie["pwm"] == __proportionel__ , "Test arrière : pwm incorrect" # Test 4 : valeur trop grande positive # Vérifier que la valeur est bien "clampée" à la valeur maximale sortie = calcul_signaux_moteur(150, pwm_max) assert sortie["pwm"] == ___pwm max_ , "Test clamp positif : pwm incorrect" # Test 5 : valeur trop grande négative # Vérifier que la valeur est bien "clampée" et le sens correct sortie = calcul_signaux_moteur(-200, pwm_max) assert sortie["in2"] == ____ , "Test clamp négatif : in2 incorrect" assert sortie["pwm"] == pwm max____ , "Test clamp négatif : pwm incorrect" # Test 6 : valeur intermédiaire (par exemple 50 %) # Vérifier la direction et la proportion du PWM sortie = calcul_signaux_moteur(50, pwm_max) assert sortie["in1"] == __1__ , "Test intermédiaire : in1 incorrect" assert sortie["in2"] == __0__ , "Test intermédiaire : in2 incorrect" assert sortie["pwm"] == __proportionel__ , "Test intermédiaire : pwm incorrect" print("Tous les tests du moteur sont PASSÉS si vous voyez ce message !") if __name__ == "__main__": test()