Пример #1
0
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'
Пример #2
0
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())
Пример #3
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)
Пример #4
0
def test_Polygone():
    # cas général : polygone à 11 côtés :
    A = rand_pt()
    B = rand_pt()
    C = rand_pt()
    D = rand_pt()
    E = rand_pt()
    F = rand_pt()
    G = rand_pt()
    H = rand_pt()
    I = rand_pt()
    J = rand_pt()
    K = rand_pt()
    p = p0 = Polygone(A, B, C, D, E, F, G, H, I, J, K)
    assert (isinstance(p.etiquette, Label_polygone))
    assert (p.sommets[0] == A and p.sommets[10] == K)
    assert (Milieu(B, C) in p.cotes[1])
    assertAlmostEqual(p.centre.coordonnees,
                      Barycentre(A, B, C, D, E, F, G, H, I, J, K).coordonnees)
    # cas particuliers :
    t = Polygone(A, B, C)
    O = t.centre_cercle_circonscrit
    assertAlmostEqual(Segment(O, A).longueur, Segment(O, C).longueur)
    assert (Droite(t.orthocentre, C).perpendiculaire(Droite(A, B)))
    assert (t.__class__ is Triangle)
    p = Polygone(A, B, C, D)
    assert (p.__class__ is Quadrilatere)
    p = Polygone(A, B, C, D, E)
    assert (p.__class__ is Pentagone)
    p = Polygone(A, B, C, D, E, F)
    assert (p.__class__ is Hexagone)
    p = Polygone(A, B, C, D, E, F, G)
    assert (p.__class__ is Heptagone)
    p = Polygone(A, B, C, D, E, F, G, H)
    assert (p.__class__ is Octogone)
    assert (p._hierarchie < p.sommets[0]._hierarchie < p.sommets[1]._hierarchie
            < p.sommets[7]._hierarchie < p._hierarchie + 1)
    # Test keyword 'points'
    p = Polygone(points=(A, B, C, D, E, F, G, H, I, J, K))
    assert (p.centre.coordonnees == p0.centre.coordonnees)
    assert ("points" not in p.style())
    # Syntaxe spéciale : Polygone créé sans arguments, ou avec un entier comme argument.
    p = Polygone()
    p = Polygone(2)
    assert (isinstance(p, Segment))
    p = Polygone(3)
    assert (isinstance(p, Triangle))
    p = Polygone(n=5)
    assert (isinstance(p, Pentagone))
    p = Polygone(n=12)
    assert (len(p.points) == 12)
    p = Polygone(23)
    assert (len(p.points) == 23)
    assert (len(str(p.points)) < 30000)
Пример #5
0
def test_Rectangle():
    A = rand_pt()
    B = rand_pt()
    r = Rectangle(A, B)
    M, N, O, P = r.sommets
    diagonale1 = Segment(M, O)
    diagonale2 = Segment(N, P)
    assertAlmostEqual(diagonale1.longueur, diagonale2.longueur)
    cote = Droite(M, N)
    cote_oppose = Droite(O, P)
    assert(cote.parallele(cote_oppose))
Пример #6
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)
Пример #7
0
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())
Пример #8
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))
Пример #9
0
def test_DemiPlan():
    d = Droite('y=-x+1')
    P1 = DemiPlan(d, Point(0, 0), True)
    P2 = DemiPlan(d, Point(0, 0), False)
    assert Point(0, 0) in P1
    assert Point(1, 0) in P1
    assert Point(0, 0) in P2
    assert Point(1, 0) not in P2
Пример #10
0
def test_Losange():
    A = rand_pt()
    B = rand_pt()
    l = Losange(A, B)
    M, N, O, P = l.sommets
    diagonale1 = Droite(M, O)
    diagonale2 = Droite(N, P)
    assert(diagonale1.perpendiculaire(diagonale2))
    cote = Droite(M, N)
    cote_oppose = Droite(O, P)
    assert(cote.parallele(cote_oppose))
Пример #11
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))
Пример #12
0
def test_Intersection_droites():
    d1 = rand_dte()
    d2 = rand_dte()
    A = Intersection_droites(d1, d2)
    if not d1.parallele(d2):
        assert (A in d1 and A in d2)
    d3 = Parallele(d1, rand_pt())
    assert (not Intersection_droites(d1, d3).existe)
    D = Point(-14.201335283549275, 1.5093204196583834)
    U = Point(-14.201335283549273, 17.644024286752096)
    d = Droite(U, D)
    s = Segment(U, D)
    V = Point(1.933368583544437, 7.5065025053891166)
    W = Point(7.1347038670937115, 8.3895493390615954)
    d2 = Droite(W, V)
    M1 = Intersection_droites(s, d2)
    M2 = Intersection_droites(d, d2)
    assert (M1.existe)
    assert (M2.existe)
Пример #13
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)
Пример #14
0
def test_Orthocentre():
    A, B, C = rand_pt(), rand_pt(), rand_pt()
    p = Polygone(A, B, C)
    H = Orthocentre(p)
    assert (Droite(A, H).perpendiculaire(Droite(B, C)))
    assert (Droite(B, H).perpendiculaire(Droite(A, C)))
    assert (Droite(C, H).perpendiculaire(Droite(B, A)))
Пример #15
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))
Пример #16
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)
Пример #17
0
def test_Glisseur_droite():
    A = rand_pt()
    B = rand_pt()
    d = Droite(A, B)
    M = Glisseur_droite(d)
    assert (M in d)
    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, 2)
    M.k = -1
    assertEqual(M.k, -1)
    Q = Point(*M.coordonnees)
    assertAlmostEqual(Droite(P, Q).equation_reduite, d.equation_reduite)
    M.k = 1.7
    M(*M.coordonnees)
    assertAlmostEqual(M.k, 1.7)
Пример #18
0
def test_Droite():
    A = Point(4.5,  7.3)
    B = Point(4,  2.1)
    d = Droite(A,  B)
    assert(isinstance(d.etiquette, Label_droite))
    assertRaises(AttributeError,  getattr,  d, "longueur")
    I = Milieu(d.point1,  d.point2)
    assertEqual(I.coordonnees,  ((A.x+B.x)/2, (A.y+B.y)/2))
    M = Barycentre((A,  1),  (B,  -2))
    N = Barycentre((A,  -2),  (B,  1))
    assert(I in d)
    assert(M in d)
    assert(N in d)
    assert(isinstance(d.equation,  tuple))
    assert(d.style("legende") == RIEN)
    # Test du typage dynamique
    d = Droite("y=x+1")
    assert(Point(0, 1) in d)
    d = Droite(Point(1, 2), Vecteur_libre(1, 1))
    assert(Point(1, 2) in d)
    assert(Point(2, 3) in d)
    d2 = Droite("y=-x+1")
    assert(Point(0, 1) in d2)
    assert(Point(1, 0) in d2)
Пример #19
0
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')
Пример #20
0
def test_Droite():
    A = Point(4.5, 7.3)
    B = Point(4, 2.1)
    d = Droite(A, B)
    assert (isinstance(d.etiquette, Label_droite))
    assertRaises(AttributeError, getattr, d, "longueur")
    I = Milieu(d.point1, d.point2)
    assertEqual(I.coordonnees, ((A.x + B.x) / 2, (A.y + B.y) / 2))
    M = Barycentre((A, 1), (B, -2))
    N = Barycentre((A, -2), (B, 1))
    assert (I in d)
    assert (M in d)
    assert (N in d)
    assert (isinstance(d.equation, tuple))
    assert (d.style("legende") == RIEN)
    # Test du typage dynamique
    d = Droite("y=x+1")
    assert (Point(0, 1) in d)
    d = Droite(Point(1, 2), Vecteur_libre(1, 1))
    assert (Point(1, 2) in d)
    assert (Point(2, 3) in d)
    d2 = Droite("y=-x+1")
    assert (Point(0, 1) in d2)
    assert (Point(1, 0) in d2)
Пример #21
0
def test_equation_formatee():
    assert Droite('y=x').equation_formatee == '-x + y = 0'
Пример #22
0
def test_Projete_droite():
    d = Droite_equation(1.25, -7.12, 2.15)
    A = Point(1.52, 2.14)
    M = Projete_droite(A, d)
    assert (M in d)
    assert (Droite(A, M)._perpendiculaire(d))