exercice base roulante
This commit is contained in:
57
tests/test_logique_moteur.py
Normal file
57
tests/test_logique_moteur.py
Normal file
@@ -0,0 +1,57 @@
|
||||
# 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"] == 1000____ , "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"] == 1000____ , "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"] == _1000___ , "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"] == __1__ , "Test clamp négatif : in2 incorrect"
|
||||
assert sortie["pwm"] == _1000___ , "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"] == 500____ , "Test intermédiaire : pwm incorrect"
|
||||
|
||||
print("Tous les tests du moteur sont PASSÉS si vous voyez ce message !")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test()
|
||||
Reference in New Issue
Block a user