def test_transformations(): c = Cercle(('1/5', '4/5'), '1/3') h = Homothetie(('1', '1'), '5/7') v = Vecteur(c.centre, h.centre) c1 = h(c) v1 = Vecteur(c1.centre, h.centre) assert v1.coordonnees == tuple(h.rapport * array(v.coordonnees)) assert_eq('c1.centre.coordonnees', '(3/7, 6/7)', l()) assert_eq('c1.rayon', '5/21', l()) c.rayon = '2' assert_eq('c1.rayon', '10/7', l()) r = Rotation(('0', '1'), 'pi/3') c2 = r(c) t = Translation(('2/3', '-1/3')) c3 = t(c) m = Reflexion(Droite('y=x')) c4 = m(c) c.rayon = '3/7' assert_eq('c2.rayon', '3/7', l()) assert_eq('c2.centre.coordonnees', '(1/10 + 3**(1/2)/10, 9/10 + 3**(1/2)/10)', l()) assert_eq('c3.rayon', '3/7', l()) assert_eq('c3.centre.coordonnees', '(13/15, 7/15)', l()) assert_eq('c4.rayon', '3/7', l()) assert_eq('c4.centre.coordonnees', '(4/5, 1/5)', l())
def test_intersections(): c = Cercle(('1/2', '2/3'), 'sqrt(2)') assert_eq('c.diametre', '2*2**(1/2)', l()) d = Droite(('0', '0'), ('1', '1')) assert_eq('d._longueur()', '2**(1/2)', l()) e = Droite(('1', '0'), ('2/3', '1')) assert_eq('e._longueur()', '10**(1/2)/3', l()) c1 = Cercle(('1/3', '3'), 'pi') assert_eq('c1.diametre', '2*pi', l()) assert_eq('c1.perimetre', '2*pi**2', l()) d1 = Disque(c1) assert_eq('d1.aire', 'pi**3', l()) # Droite/droite M = Intersection(d, e) assert_eq('M.coordonnees', '(3/4, 3/4)', l()) # Cercle/droite I = Intersection(c, d) assert_eq('I.coordonnees', '(7/12 - 143**(1/2)/12, 7/12 - 143**(1/2)/12)', l()) assert_eq_num(I.coordonnees_approchees, (-0.41318839525844997, -0.41318839525844997)) # Cercle/cercle J = Intersection(c, c1) assert_eq( 'J.coordonnees', '(913/2364 - 98*(212563/12348 + (-913/1176 - 3*pi**2/98)**2' '- 394*pi**2/343 - 197*(125/56 - 3*pi**2/14)**2/49)**(1/2)/197' '+ 3*pi**2/197,' '2671/1182 - 7*(212563/12348 + (-913/1176 - 3*pi**2/98)**2' '- 394*pi**2/343 - 197*(125/56 - 3*pi**2/14)**2/49)**(1/2)/197' '- 42*pi**2/197)', l())
def test_Intersection_cercles(): A = Point(-4.4375, 1.95833333333, legende=2) B = Point(-2.10416666667, 0.875, legende=2) c1 = Cercle(A, B) C = Point(2.1875, 1.35416666667, legende=2) c2 = Cercle(C, B) D = Intersection_cercles(c2, c1, False, legende=2) assert (D == (-1.9466976004889973, 2.6017297602107377)) assert (Intersection_cercles(c2, c1, True, legende=2) == B) assert (Droite(A, C) == Mediatrice(B, D))
def test_Cercle(): A = Point(2.78841, -5.25) O = Point(27.8841, -0.525) c = Cercle(O, A) assert (c.centre is O) assert (c.point is A) assertAlmostEqual(c.rayon, 25.5366262763) # Test du typage dynamique c = Cercle(Point(1, 1), 1) assert (Point(1, 2) in c) c = Cercle(Point(1, 1), Point(0, 2), Point(-1, 1)) assert (Point(0, 0) in c) assertAlmostEqual(c.centre.coordonnees, (0, 1))
def test_eqn_formatee(): c = Cercle(('1/2', '2/3'), 'sqrt(2)') assert c.equation_formatee == u'x\xb2 + y\xb2 - x - 4/3 y - 47/36 = 0' d = Droite(('0', '0'), ('1', '1')) assert d.equation_formatee == '-x + y = 0' e = Droite(('1', '0'), ('2/3', '1')) assert e.equation_formatee == '-x - 1/3 y + 1 = 0'
def test_Point(): A = Point(1, 2) assert (isinstance(A.etiquette, Label_point)) assertEqual(A.x, 1) assertEqual(A.y, 2) assertEqual(type(A.coordonnees), tuple) A.x = 5 A.y = 7 assertEqual(A.coordonnees, (5, 7)) assert (A.style("legende") == NOM) # Test du typage dynamique d = Droite(rand_pt(), rand_pt()) B = Point(d) assert (isinstance(B, Glisseur_droite)) c = Cercle(A, 3) C = Point(c) assert (isinstance(C, Glisseur_cercle)) d = Demidroite(rand_pt(), rand_pt()) B = Point(d) assert (isinstance(B, Glisseur_demidroite)) s = Segment(rand_pt(), rand_pt()) B = Point(s) assert (isinstance(B, Glisseur_segment)) a = Arc_points(Point(), Point(1, 1), Point(1, 2)) B = Point(a) assert (isinstance(B, Glisseur_arc_cercle))
def test_Cercle_diametre(): A = Point(2.78841, -5.25) B = Point(27.8841, -0.525) c = Cercle_diametre(A, B) c1 = Cercle(A, B) assertAlmostEqual(c.diametre, c1.rayon) assertAlmostEqual(c.diametre, Segment(A, B).longueur) assertAlmostEqual(c.centre.coordonnees, Milieu(A, B).coordonnees)
def test_Centre_cercle_inscrit(): A, B, C = rand_pt(), rand_pt(), rand_pt() p = Polygone(A, B, C) I = Centre_cercle_inscrit(p) P = Projete_segment(I, Segment(B, C)) Q = Projete_segment(I, Segment(A, C)) R = Projete_segment(I, Segment(A, B)) c = Cercle(I, P) assert (P in c and Q in c and R in c)
def test_aire_diametre_perimetre(): p = Triangle(('0', '0'), ('0', '1/3'), ('1/3', '0')) assert_eq('p.aire', '1/18', l()) c = Cercle(('0', '0'), '5/3') assert_eq('c.rayon', '5/3', l()) assert_eq('c.diametre', '10/3', l()) assert_eq('c.perimetre', '10/3*pi', l()) D = Disque(c) assert_eq('D.aire', 'pi*25/9', l())
def test_nommage_automatique(): f = Feuille() M1 = f.objets._ = Point() assert("M1" in f.objets) M2 = f.objets._ = Point(1, 3) assert("M2" in f.objets) f.objets._ = Droite(M1, M2) assert("d1" in f.objets) f.objets._ = Cercle(M1, M2) assert("c1" in f.objets) f.objets._ = Segment(M1, M2) assert("s1" in f.objets)
def test_Tangente(): A = Point(4.75, -2.56887) O = Point(2.56874, -85.2541) M = Point(7.854, -552.444) c = Cercle(O, A) d = Tangente(c, A) assert (A in d) assert (M not in d) d1 = Tangente(c, M) assert (M in d1) assert (A not in d1) assert (not Tangente(c, O).existe)
def test_Intersection_droite_cercle(): A = Point(-3.075, 2.0, legende=2) B = Point(0.0, 1.625, legende=2) c1 = Cercle(A, B) C = Point(-0.375, 4.425, legende=2) D = Point(3.25, 0.125, legende=2) d1 = Droite(C, D) assert (not Intersection_droite_cercle(d1, c1).existe) C(-5.675, 4.95) I = Intersection_droite_cercle(d1, c1, True) assert (I == (-4.87791007862, 4.51908023858)) J = Intersection_droite_cercle(d1, c1, False) assert (J == (0.0201000262814, 1.87113640036))
def test_intersection_et_feuille(): u"""On teste que par défaut, le deuxième d'intersection soit différent du premier.""" f = Feuille() f.objets._ = Point(-5.11060948081, 0.144469525959) f.objets._ = Point(-3.97291196388, 0.794582392777) f.objets._ = Cercle(f.objets.M1, f.objets.M2) f.objets._ = Point(-3.26862302483, -1.10158013544) f.objets._ = Point(-5.79683972912, 2.41986455982) f.objets._ = Droite(f.objets.M3, f.objets.M4) f.objets._ = Intersection_droite_cercle(f.objets.d1, f.objets.c1, True) f.objets._ = Intersection_droite_cercle(f.objets.d1, f.objets.c1) # On vérifie qu'on a bien obtenu le 2e point d'intersection (et non deux fois de suite le même) assert (f.objets.M6.premier_point == False)
def test_transformations(): c = Cercle(('1/5', '4/5'), '1/3') h = Homothetie(('1', '1'), '5/7') v = Vecteur(c.centre, h.centre) c1 = h(c) v1 = Vecteur(c1.centre, h.centre) assert v1.coordonnees == tuple(h.rapport*array(v.coordonnees)) assert_eq('c1.centre.coordonnees', '(3/7, 6/7)', l()) assert_eq('c1.rayon', '5/21', l()) c.rayon = '2' assert_eq('c1.rayon', '10/7', l()) r = Rotation(('0', '1'), 'pi/3') c2 = r(c) t = Translation(('2/3', '-1/3')) c3 = t(c) m = Reflexion(Droite('y=x')) c4 = m(c) c.rayon = '3/7' assert_eq('c2.rayon', '3/7', l()) assert_eq('c2.centre.coordonnees', '(1/10 + 3**(1/2)/10, 9/10 + 3**(1/2)/10)', l()) assert_eq('c3.rayon', '3/7', l()) assert_eq('c3.centre.coordonnees', '(13/15, 7/15)', l()) assert_eq('c4.rayon', '3/7', l()) assert_eq('c4.centre.coordonnees', '(4/5, 1/5)', l())
def test_noms_latex(): f = Feuille() f.objets.A = Point() assert(f.objets.A.nom == "A") assert(f.objets.A.nom_latex == "$A$") f.objets.B1 = Point() assert(f.objets.B1.nom == "B1") assert(f.objets.B1.nom_latex == "$B_{1}$") f.objets.C17 = Point() assert(f.objets.C17.nom == "C17") assert(f.objets.C17.nom_latex == "$C_{17}$") f.objets.objet5 = Point() assert(f.objets.objet5.nom == "objet5") assert(f.objets.objet5.nom_latex == "$objet_{5}$") f.objets.Delta = Point() assert(f.objets.Delta.nom == "Delta") assert(f.objets.Delta.nom_latex == "$\\Delta$") f.objets.delta = Point() assert(f.objets.delta.nom == "delta") assert(f.objets.delta.nom_latex == "$\\delta$") f.objets.phi15 = Point() assert(f.objets.phi15.nom == "phi15") assert(f.objets.phi15.nom_latex == "$\\phi_{15}$") f.objets.A_prime_prime = Point() assert(f.objets.A_prime_prime.nom == "A_prime_prime") assert(f.objets.A_prime_prime.nom_latex == "$A''$") f.objets["A'B'"] = Point() assert(f.objets.A_primeB_prime.nom == "A_primeB_prime") assert(f.objets.A_primeB_prime.nom_latex == "$A'B'$") f.objets.A_prime71 = Point() assert(f.objets.A_prime71.nom == "A_prime71") assert(f.objets.A_prime71.nom_latex == "$A'_{71}$") f.objets.A17B22 = Point() assert(f.objets.A17B22.nom == "A17B22") assert(f.objets.A17B22.nom_latex == "$A_{17}B_{22}$") f.objets.C_prime = Cercle() assert(f.objets.C_prime.nom_latex == "$\\mathscr{C}'$") f.objets.u = Vecteur() assert(f.objets.u.nom_latex == "$\\vec u$") f.objets.u_prime = Vecteur() assert(f.objets.u_prime.nom_latex == "$\\overrightarrow{u'}$")
def test_info(): f = Feuille() o = f.objets with contexte(decimales = 2): A = o.A = Point(5, 7) assert(A.info == u"Point A de coordonnées (5, 7)") B = o.B = Point(6.5, 9.3) assert(B.info == u"Point B de coordonnées (6.5, 9.3)") s = o.s = Segment(A, B) assert(s.info == u"Segment s de longueur 2.75") c = o.c = Cercle(s) assert(c.info == u"Cercle c de rayon 1.37") d = o.d = Droite(A, B) assert(d.info == u"Droite d d'équation -2.3 x + 1.5 y + 1 = 0") C = o.C = Point(-1.5, 2.7) a = o.a = Arc_cercle(A, B, C) assert(a.info == u'Arc a de longueur 7.5') alpha = o.alpha = Angle(A, B, C) assert(alpha.info == u'Angle alpha de valeur 0.3') with contexte(decimales = 3): assert(a.info == u'Arc a de longueur 7.505')
def test_equation_formatee(): assert Cercle((10, 0), (1, 5)).equation_formatee == u'x\xb2 + y\xb2 - 20 x - 6 = 0'
def test_cercle_defini_par_equation(): c = Cercle("x^2+y^2-2x+y-3=0") assertAlmostEqual(c.centre.xy, (1, -.5)) assertAlmostEqual(c.rayon, sqrt(4.25))
def test_Rayon(): c = Cercle((1, 1), (4, 5)) r = Rayon(c) assertAlmostEqual(r.val, 5) c.point.x = 1 assertAlmostEqual(r.val, 4)