cours_progra/bac1/q1/29sept/ex2-1/droite_test.py

39 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-09-29 17:42:52 +02:00
from droite import *
def test(function, p1, p2, exp_result):
fun_result = function(p1, p2)
if fun_result == exp_result:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- SUCCESS!")
else:
print(f"{function.__name__}({p1}, {p2}) == {exp_result} --- ERROR! (result was:{fun_result})")
def tests():
test(droite, (-2, 0), (1, 1.5), (-0.5, 1, 1.0))
test(droite, (0, -3), (0, 5), (1, 0, 0))
test(droite, (0, -1), (0, -1), None)
test(appartient, (-0.5, 1, 1.0), (-2, 0), True)
test(appartient, (-0.5, 1, 1.0), (1, 1.5), True)
test(appartient, (-0.5, 1, 1.0), (0, -1), False)
test(paralleles, (0, 1, 1), (0, 2, 3), True)
test(paralleles, (-0.5, 1, 1.0), (0, 2, 3), False)
test(intersection, (-0.5, 1, 1.0), (0, 2, 3), (1.0, 1.5))
test(intersection, (0, 1, 1), (0, 2, 3), None)
test(droite_normale, (-0.5, 1, 1.0), (-2, 0), (2.0, 1, -4.0))
test(droite_normale, (-0.5, 1, 1.0), (3, 4), (2.0, 1, 10.0))
test(symetrie_orthogonale, (-0.5, 1, 1.0), (-2, 0), (-2.0, 0.0))
2022-09-30 11:49:26 +02:00
test(symetrie_orthogonale, (-0.5, 1, 1.0), (3, 4), (4.2, 1.6))
2022-09-29 17:42:52 +02:00
2022-10-01 11:49:25 +02:00
test(distance_droite_point, (-0.5, 1, 1.0), (3, 4), 1.3416407864998738)
2022-09-29 17:42:52 +02:00
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0)
if __name__ == "__main__":
tests()