This commit is contained in:
lnino
2025-12-03 01:04:28 +01:00
commit 4790175b7f
3 changed files with 82 additions and 0 deletions

47
tests/test_moteurDC.py Normal file
View File

@@ -0,0 +1,47 @@
from logique_moteurDC import calc_signal_moteur
def lancer_tests():
# On prend un pwm_max simple pour vérifier : 1000
pwm_max = 1000
# Test 1 : arrêt
sortie = calc_signal_moteur(0, pwm_max)
assert sortie["in1"] == 0 and sortie["in2"] == 0 and sortie["pwm"] == 0, \
"Test arrêt : échec"
# Test 2 : 100% avant
sortie = calc_signal_moteur(100, pwm_max)
assert sortie["in1"] == 1 and sortie["in2"] == 0, \
"Test avant (sens) : échec"
assert sortie["pwm"] == 1000, \
"Test avant (PWM) : échec"
# Test 3 : 100% arrière
sortie = calc_signal_moteur(-100, pwm_max)
assert sortie["in1"] == 0 and sortie["in2"] == 1, \
"Test arrière (sens) : échec"
assert sortie["pwm"] == 1000, \
"Test arrière (PWM) : échec"
# Test 4 : valeur > 100 -> doit être clampée
sortie = calc_signal_moteur(150, pwm_max)
assert sortie["pwm"] == 1000, \
"Test clamp >100 : échec"
# Test 5 : valeur < -100 -> doit être clampée
sortie = calc_signal_moteur(-200, pwm_max)
assert sortie["pwm"] == 1000 and sortie["in2"] == 1, \
"Test clamp <-100 : échec"
# Test 6 : vitesse intermédiaire 50% avant
sortie = calc_signal_moteur(50, pwm_max)
assert sortie["in1"] == 1 and sortie["in2"] == 0, \
"Test 50% avant (sens) : échec"
assert sortie["pwm"] == 500, \
"Test 50% avant (PWM) : échec"
print("Tous les tests unitaires du moteur sont PASSE !")
if __name__ == "__main__":
lancer_tests()