Beispiel #1
0
def test_Cercle_points():
    A = Point(2.78841, -5.25)
    B = Point(27.8841, -0.525)
    C = Point(-42.25, 2.351)
    c = Cercle_points(A, B, C)
    assert (c.centre in Mediatrice(Segment(A, B)))
    assert (c.centre in Mediatrice(Segment(A, C)))
Beispiel #2
0
def test_Demicercle():
    A = Point(-1.2561, 45.236)
    B = Point(251.2561, 41.256)
    c = Demicercle(A, B)
    assertAlmostEqual(Milieu(A, B).coordonnees, c.centre.coordonnees)
    assertAlmostEqual(c.diametre, Segment(A, B).longueur)
    assertAlmostEqual(c.rayon, Segment(A, B).longueur / 2)
Beispiel #3
0
def test_Droite_equation():
    a = randint(50) - randint(50) + 0.1  # afin que a ne soit pas nul
    b = randint(50) - randint(50) + random()
    c = randint(50) - randint(50) + random()
    d, e, f = Droite_equation(a, b, c).equation
    assertAlmostEqual((e / d, f / d), (b / a, c / a))
    assertEqual(Droite_equation(a, 0, 0).equation[1:], (0, 0))
    assertEqual((Droite_equation(0, a, 0).equation[0], Droite_equation(
        0, a, 0).equation[2]), (0, 0))
    assert (not Droite_equation(0, 0, 0).existe)
    d = Droite_equation("y=-5/2x-3/2")
    assert (Point(0, -1.5) in d)
    assert (Point(-1, 1) in d)
    d = Droite_equation("x=2*10**2")
    assert (Point(200, -1000) in d)
    assert (Point(100, -1000) not in d)
    d = Droite_equation("2*x+2*y=1")
    assert (Point(0.5, 0) in d)
    assert (Point(1, -0.5) in d)
    d = Droite_equation("x+y=1")
    assert (Point(0, 1) in d)
    assert (Point(1, 0) in d)
    d = Droite_equation("x+2y=-2")
    assert (Point(0, -1) in d)
    assert (Point(-2, 0) in d)
Beispiel #4
0
def test_issue_176():
    f = Feuille()
    A = f.objets.A = Point()
    B = f.objets.B = Point()
    f.objets.s = Segment(A, B)
    del f.objets.A, f.objets.B, f.objets.s
    assert set(('A', 'B', 's')).isdisjoint(f.objets.noms)
Beispiel #5
0
def test_Glisseur_segment():
    A = rand_pt()
    B = rand_pt()
    s = Segment(A, B)
    M = Glisseur_segment(s)
    assert (M in s)
    M.k = 0
    assertEqual(M.k, 0)
    assertAlmostEqual(M.coordonnees, A.coordonnees)
    P = Point(*M.coordonnees)
    M.k = 1
    assertEqual(M.k, 1)
    assertAlmostEqual(M.coordonnees, B.coordonnees)
    M.k = 2
    assertEqual(M.k, 1)  # 0<=k<=1 pour un segment
    assert (M in s)
    M.k = -1
    assertEqual(M.k, 0)  # 0<=k<=1 pour un segment
    assert (M in s)
    M.k = 1
    Q = Point(*M.coordonnees)
    assertAlmostEqual(Droite(P, Q).equation_reduite, s.equation_reduite)
    M.k = 1.7
    M(*M.coordonnees)
    assertAlmostEqual(M.k, 1)
Beispiel #6
0
def test_formules():
    f = Feuille()
    o = f.objets
    o.A = Point(e, 3)
    o.M = Point()
    o.M.label(u'{1/ln(A.x)}', True)
    assert(eval(o.M.label()) == 1)
Beispiel #7
0
def test_relier_point_axes():
    f = Feuille()
    f.objets.M1 = Point(-1.27482678984, 1.69976905312, legende=2)
    f.objets.M2 = Point(2.42032332564, 1.25635103926, legende=2)
    f.objets.s1 = Segment(f.objets.M1, f.objets.M2)
    f.objets.M1.relier_axe_x()
    f.objets.M1.relier_axe_y()
Beispiel #8
0
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_Segment():
    A = Point('1/2', '3/4')
    B = Point('pi', 'pi')
    C = Point(S('1/2'), S('3/4'))
    assert_eq("A.coordonnees", "C.coordonnees", "(1/2, 3/4)", l())
    assert_eq('B.coordonnees', '(pi, pi)', l())
    s = Segment(A, B)
    assert_eq('s.longueur', '((pi - 1/2)**2 + (pi - 3/4)**2)**(1/2)', l())
Beispiel #10
0
def test_Bissectrice():
    A = Point(1, -5)
    B = Point(1.5, -5.3)
    C = Point(3, -4)
    d = Bissectrice(A, B, C)
    a, b, c = d.equation
    d, e = (0.0870545184921, -1.03861105199)
    assertAlmostEqual(b / a, d)
    assertAlmostEqual(c / a, e)
Beispiel #11
0
def test_Arc_cercle():
    A = Point(-1.2561, 45.236)
    B = Point(251.2561, 41.256)
    O = Point(-42.25, 2.351)
    a = Arc_cercle(O, A, B)
    assert (isinstance(a.etiquette, Label_arc_cercle))
    assert (A in a)
    assert (B not in a)
    assert (O not in a)
Beispiel #12
0
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))
Beispiel #13
0
def test_Rotation():
    A = Point(1.523, 45.35211)
    r = Rotation(A, pi/4)
    M = Point(1.4452,  -1.2545)
    assertAlmostEqual(r(M).coordonnees, (34.423837071540447, 12.341247113306926))
    assertAlmostEqual(r(A).coordonnees, A.coordonnees)
    d = Droite(A, M)
    d1 = Droite(A, r(M))
    assertAlmostEqual(r(d).equation_reduite, d1.equation_reduite)
    assert(r(A) is A)
Beispiel #14
0
def test_modification_variable():
    f = Feuille()
    o = f.objets
    o.a = Variable(1)
    o.fa = "5*sin(4/(a+.5))-1.5"
    o.A = Point(o.a, o.fa)
    o.fa = "-5*sin(4/(a+.5))+5.5"
    o.A = Point(o.a, o.fa)
    assertAlmostEqual(o.A.x, o.a)
    assertAlmostEqual(o.A.y, o.fa)
Beispiel #15
0
def test_Milieu():
    A = Point(1, 2)
    B = Point(2, 4)
    I = Milieu(A, B)
    assert (I.x == (A.x + B.x) / 2 and I.y == (A.y + B.y) / 2)
    assertEqual(type(I.coordonnees), tuple)
    C = Point('1/3', '1')
    D = Point('1', '1')
    J = Milieu(C, D)
    assert (J.x == symp('2/3'))
Beispiel #16
0
def test_Representant():
    A = Point(1, 2)
    B = Point(2, 4)
    v = Vecteur(A, B)
    w = Representant(v, B)
    assert (w.x == v.x and w.y == v.y and w.z == v.z)
    assert (w.origine == v.point2)
    assertEqual(type(w.coordonnees), tuple)
    assertAlmostEqual(w.extremite.coordonnees, (3, 6))
    assert (w._hierarchie < w.extremite._hierarchie < w._hierarchie + 1)
Beispiel #17
0
def test_Point_translation():
    u = Vecteur_libre(1.56, 2.78)
    v = Vecteur(Point(1.1457, 2.7895), Point(2.458, -8.25))
    A = Point(5.256, -7.231)
    tu = Translation(u)
    tv = Translation(v)
    Au = Point_translation(A, tu)
    Av = Point_translation(A, tv)
    assertAlmostEqual(Au.coordonnees, (6.816, -4.451))
    assertAlmostEqual(Av.coordonnees, (6.5683, -18.2705))
Beispiel #18
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))
Beispiel #19
0
def test_Point_rotation():
    A = Point(1, -4)
    r = Rotation(Point(-2, 7.56), 4.25)
    B = Point_rotation(A, r)
    assertAlmostEqual(r(A).coordonnees, B.coordonnees)
    assertAlmostEqual(B.coordonnees, (-13.684339450863803, 10.031803308717693))
    A = Point('1', '0')
    r = Rotation(('0', '0'), 'pi/4')
    B = Point_rotation(A, r)
    C = Point('sqrt(2)/2', 'sqrt(2)/2')
    assert (C.x == B.x and C.y == B.y)
Beispiel #20
0
def test_Vecteur():
    A = Point(1, 2)
    B = Point(2, 4)
    v = Vecteur(A, B)
    assert (isinstance(v.etiquette, Label_vecteur))
    assert (v.x == 1 and v.y == 2)
    assertEqual(v.norme, sqrt(5))
    assertEqual(type(v.coordonnees), tuple)
    # Test du typage dynamique :
    assert (isinstance(Vecteur(1, 3), Vecteur_libre))
    assert (Vecteur(1, 3).coordonnees == (1, 3))
Beispiel #21
0
def test_Arc_points():
    A = Point(-1.2561, 45.236)
    B = Point(251.2561, 41.256)
    C = Point(-42.25, 2.351)
    a = Arc_points(A, B, C)
    assert (A in a)
    assert (B in a)
    assert (C in a)
    assertAlmostEqual(a.longueur, 1208.25931027)
    assertAlmostEqual(a.centre.coordonnees,
                      (122.51970100911581, -114.11725498641933))
Beispiel #22
0
def test_variables_composees_1():
    f = Feuille()
    A = f.objets.A = Point()
    B = f.objets.B = Point()
    A(-5, 13)
    B.x = A.x
    assert(B.x == B.coordonnees[0] == A.x == -5)
    A(1, 9)
    assert(B.x == B.coordonnees[0] == -5 and A.x == 1)
    B.x="A.x"
    A(17, 5)
    assert(B.coordonnees[0] == B.x == 17)
Beispiel #23
0
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)
Beispiel #24
0
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)
Beispiel #25
0
def test_Somme_vecteurs():
    A = Point(1, 2)
    B = Point(2, 4)
    v = Vecteur(A, B)
    w = Vecteur_libre(-4, 5)
    u = Representant(v, Point(1, 2))
    vec = 2 * u + 1 * v
    vec -= 5 * w
    assert (tuple(vec.coordonnees) == (23, -19))
    assertEqual(type(vec.coordonnees), tuple)
    assertEqual(vec.coordonnees,
                Somme_vecteurs((u, v, w), (2, 1, -5)).coordonnees)
Beispiel #26
0
def test_redefinir():
    f = Feuille()
    A = f.objets.A = Point()
    B = f.objets.B = Point()
    f.objets.AB = Segment(A, B)
    f.objets.AB.redefinir('Vecteur(A, B)')
    assert isinstance(f.objets.AB, Vecteur)
    assert f.objets.AB == Vecteur(A, B)
    f.objets.txt = Texte('Hello', 2, 3)
    f.objets.txt.redefinir("Texte('Bonjour', 1, 4)")
    assert isinstance(f.objets.txt, Texte)
    assert f.objets.txt.texte == 'Bonjour'
    assert f.objets.txt.coordonnees == (1, 4)
Beispiel #27
0
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))
Beispiel #28
0
def test_Mediatrice():
    A = Point(4.5, 7.3)
    B = Point(-4.147, 2.1)
    s = Segment(A, B)
    d0 = Mediatrice(s)
    d1 = Mediatrice(A, B)
    I = Milieu(A, B)
    assert (I in d0)
    assert (I in d1)
    a, b, c = s.equation
    a0, b0, c0 = d0.equation
    assertAlmostEqual(a * a0 + b * b0, 0)
    assertAlmostEqual(d0.equation, d1.equation)
Beispiel #29
0
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)
Beispiel #30
0
def test_Disque():
    A = Point(2.78841, -5.25)
    B = Point(27.8841, -0.525)
    C = Point(-42.25, 2.351)
    c = Cercle_points(A, B, C)
    d = Disque(c)
    assertAlmostEqual(d.centre.coordonnees, c.centre.coordonnees)
    assertAlmostEqual(d.rayon, c.rayon)
    assert (A in d)
    assert (B in d)
    assert (C in d)
    assert (d.centre in d)
    assert (Point(-500, -500) not in d)