cours_progra/q1/29sept/ex2-1/droite_test.py
2023-02-15 13:40:50 +01:00

39 lines
1.3 KiB
Python

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))
test(symetrie_orthogonale, (-0.5, 1, 1.0), (3, 4), (4.2, 1.6))
test(distance_droite_point, (-0.5, 1, 1.0), (3, 4), 1.3416407864998738)
test(distance_droite_point, (-0.5, 1, 1.0), (-2, 0), 0.0)
if __name__ == "__main__":
tests()