Exemplo n.º 1
0
def test_Parallelogramme():
    A = rand_pt()
    B = rand_pt()
    C = rand_pt()
    p = Parallelogramme(A, B, C)
    D = p.sommets[3]
    assertEqual(Vecteur(A, B), Vecteur(D, C))
Exemplo n.º 2
0
def test_issue_258():
    # Issue: "Le mode approché ne fonctionne pas pour une liste."
    i = Interprete(verbose=VERBOSE)
    i.evaluer("v(p,n) = (p-1.96*sqrt(p*(1-p))/sqrt(n), p+1.96*sqrt(p*(1-p))/sqrt(n))")
    r, l = i.evaluer("v(0.28, 50)", calcul_exact=False)
    assertEqual(r, "(0,155543858327521659 ; 0,404456141672478341)")
    assertEqual(l, r"$\left(0,155543858327521659;\,0,404456141672478341\right)$")
Exemplo n.º 3
0
def test_resolution_avec_fonction():
    i = Interprete(verbose=VERBOSE)
    i.evaluer("f(x)=a*x+1")
    i.evaluer("resoudre(f(3)=7)")
    res = i.derniers_resultats[-1]
    # Le type du résultat est actuellement un ensemble, mais cela pourrait changer à l'avenir.
    assertEqual(res, {S(2)})
Exemplo n.º 4
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)
Exemplo n.º 5
0
def test_Decim():
    expr = S.One*Decim('0.3')
    assert isinstance(expr,  Decim), type(expr)
    expr = Decim('0.3')*x
    assert isinstance(expr.args[0],  Decim), type(expr.args[0])
    assertEqual(repr(Decim(1, 2)*x + Decim(1, 5)), '0.5*x + 0.2')
    assertEqual(repr(Decim(1, 2)*Rational(1, 5)), '0.1')
Exemplo n.º 6
0
def test_systeme():
    i = Interprete(verbose=VERBOSE)
    i.evaluer("g(x)=a x^3+b x^2 + c x + d")
    i.evaluer("resoudre(g(-3)=2 et g(1)=6 et g(5)=3 et g'(1)=0)")
    res = i.derniers_resultats[-1]
    assert isinstance(res, dict)
    assertEqual(res, {S('a'): S(1)/128, S('b'): -S(31)/128, S('c'): S(59)/128, S('d'): S(739)/128})
Exemplo n.º 7
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)
Exemplo n.º 8
0
def test_systeme():
    i = Interprete(verbose=VERBOSE)
    i.evaluer("g(x)=a x^3+b x^2 + c x + d")
    i.evaluer("resoudre(g(-3)=2 et g(1)=6 et g(5)=3 et g'(1)=0)")
    res = i.derniers_resultats[-1]
    # Le type du résultat est actuellement un dictionnaire, mais cela pourrait changer à l'avenir.
    assert isinstance(res, dict)
    assertEqual(res, {S('a'): S(1)/128, S('b'): -S(31)/128, S('c'): S(59)/128, S('d'): S(739)/128})
Exemplo n.º 9
0
def test_Label_segment():
    f = Feuille()
    s = f.objets.s = Segment()
    assert s.label() == ''
    s.label('bonjour !')
    assert s.label() == 'bonjour !'
    s.label(mode='nom')
    assertEqual(s.label(), r'$\mathscr{s}$')
Exemplo n.º 10
0
def test_conversion_chaine_ensemble():
    chaine = '{-(-216*2^(2/3)+4*(-3616+64*sqrt(8113))^(1/3)+2^(1/3)' \
             '*(-3616+64*sqrt(8113))^(2/3))/(16*(-3616+64*sqrt(8113))^(1/3))}'
    attendu = "Ensemble('{(-2^(1/3)*(-3616 + 64*sqrt(8113))^(2/3) " \
               "- 4*(-3616 + 64*sqrt(8113))^(1/3) + 216*2^(2/3))" \
               "/(16*(-3616 + 64*sqrt(8113))^(1/3))}')"
    resultat = repr(conversion_chaine_ensemble(chaine, utiliser_sympy=True))
    assertEqual(resultat, attendu)
Exemplo n.º 11
0
def test_issue_278():
    i = Interprete(verbose=VERBOSE)
    i.evaluer("delta = 25")
    r, l = i.evaluer('delta')
    assertEqual(r, '25')
    i.evaluer('del delta')
    r, l = i.evaluer('delta')
    assertEqual(r, 'delta')
Exemplo n.º 12
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'))
Exemplo n.º 13
0
def test_Point_final():
    A = Point(random(),random())
    C = Point(random(),random())
    u = Vecteur_libre(random(),random())
    v = Vecteur(Point(random(),  random()),  Point(random(),  random()))
    w = Representant(Vecteur(Point(random(),  random()),  Point(random(),  random())),  A)
    F = Point_final(C,  (u, v, w), (-2, 1.5, 4))
    assertEqual(type(F.coordonnees),  tuple)
    assertAlmostEqual(F.x,  C.x -2*u.x+1.5*v.x+4*w.x)
    assertAlmostEqual(F.y,  C.y -2*u.y+1.5*v.y+4*w.y)
Exemplo n.º 14
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)
Exemplo n.º 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'))
Exemplo n.º 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)
Exemplo n.º 17
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))
Exemplo n.º 18
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)
Exemplo n.º 19
0
def test_Point_final():
    A = Point(random(), random())
    C = Point(random(), random())
    u = Vecteur_libre(random(), random())
    v = Vecteur(Point(random(), random()), Point(random(), random()))
    w = Representant(
        Vecteur(Point(random(), random()), Point(random(), random())), A)
    F = Point_final(C, (u, v, w), (-2, 1.5, 4))
    assertEqual(type(F.coordonnees), tuple)
    assertAlmostEqual(F.x, C.x - 2 * u.x + 1.5 * v.x + 4 * w.x)
    assertAlmostEqual(F.y, C.y - 2 * u.y + 1.5 * v.y + 4 * w.y)
Exemplo n.º 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))
Exemplo n.º 21
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)
Exemplo n.º 22
0
def test_sauvegarde():
    f1 = Feuille(titre="Ma feuille")
    o = f1.objets
    o.A = (1, 2)
    o.B = (-1, 3)
    o.k = 7
    o.s = Segment(o.A, o.B)
    sauvegarde = f1.sauvegarder()
    f2 = Feuille(titre="Nouvelle feuille")
    f2.charger(sauvegarde)
    assertEqual(f2.objets.noms, set(['A', 'B', 'k', 's', 'dpy', 'dpx',
                                     'xmax', 'xmin', 'ymin', 'ymax']))
Exemplo n.º 23
0
def test_sympy():
    x = Symbol('x', real=True)
    assert -oo < oo
    assert not(-1.5 < -oo)
    assert (1 - exp(x)).is_negative is None
    assert Matrix([[1, 2], [3, 4]])**Integer(2) == Matrix([[7, 10], [15, 22]])
    assertAlmostEqual(E._evalf(50), math.e)
    assert solve(1/x, x) == [] # issue 1694
    assert solve(-(1 + x)/(2 + x)**2 + 1/(2 + x), x) == [] # issue 1694
    assert limit(1 + 1/x, x, 0, dir='-') == -oo
    assert limit(1/x**2, x, 0, dir='-') == oo
    assert sympify('45') == 45 # issue 2508
    assertEqual(solve((2*x + 8)*exp(-6*x), x), [-4]) # issue 10391 (FS#319)
Exemplo n.º 24
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)
Exemplo n.º 25
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.mode_affichage == 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))
Exemplo n.º 26
0
def test_Projete_arc_cercle():
    O = Point(23.15, -12.75)
    A = Point(-12.5, 7.14)
    B = Point(7.15, 8.64)
    a = Arc_cercle(O, A, B)
    M = rand_pt()
    P = Projete_arc_cercle(M, a)
    assert(P in a)
    M.coordonnees = a.centre.coordonnees
    assert(not P.existe)
    M.coordonnees = -17.826266675199999, 11.760911186
    assert(type(P.coordonnees) is tuple)
    assertAlmostEqual(A.coordonnees, P.coordonnees)
    assertEqual(A, P)
Exemplo n.º 27
0
def test_issue_259():
    i = Interprete(verbose=VERBOSE)
    # First part.
    r, l = i.evaluer("normal(140,1 ; 150,3 ; 100 ; 5)")
    # sympy 1.0 : '5,28725822993202*10^-16'
    # Wofram Alpha (01/05/2016) : 5/9007199254740992~~5.55112×10^-16
    # On teste que ce soit en gros correct, sans se focaliser sur les décimales.
    assert re.match("5,[0-9]+\*10\^\-16$", r)
    assert re.match(r"\$5,[0-9]+[ ]\\cdot[ ]10\^{-16}\$$", l)
    # Second part of the issue (scientific notation handling).
    i.calcul_exact = False
    r, l = i.evaluer("10,0^-125,0")
    assertEqual(r, "1,0*10^-125")
    assertEqual(l, r"$10^{-125}$")
Exemplo n.º 28
0
def test_Demidroite():
    A = Point(4.5, 7.3)
    B = Point(4, 2.1)
    s = Demidroite(A, B)
    assert (isinstance(s.etiquette, Label_demidroite))
    assertRaises(AttributeError, getattr, s, "longueur")
    I = Milieu(s.origine, s.point)
    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 s)
    assert (M in s)
    assert (N not in s)
    assert (s.style("legende") == RIEN)
Exemplo n.º 29
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)
Exemplo n.º 30
0
def test_Segment():
    A = Point(4.5,  7.3)
    B = Point(4,  2.1)
    s = Segment(A,  B)
    assert(isinstance(s.etiquette, Label_segment))
    assertAlmostEqual(s.longueur, sqrt((B.x - A.x)**2 + (B.y - A.y)**2))
    I = Milieu(s.point1,  s.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 s)
    assert(M not in s)
    assert(N not in s)
    assert(s.style("legende") == RIEN)
Exemplo n.º 31
0
def test_Segment():
    A = Point(4.5, 7.3)
    B = Point(4, 2.1)
    s = Segment(A, B)
    assert (isinstance(s.etiquette, Label_segment))
    assertAlmostEqual(s.longueur, sqrt((B.x - A.x)**2 + (B.y - A.y)**2))
    I = Milieu(s.point1, s.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 s)
    assert (M not in s)
    assert (N not in s)
    assert (s.style("legende") == RIEN)
Exemplo n.º 32
0
def test_Demidroite():
    A = Point(4.5,  7.3)
    B = Point(4,  2.1)
    s = Demidroite(A,  B)
    assert(isinstance(s.etiquette, Label_demidroite))
    assertRaises(AttributeError,  getattr,  s, "longueur")
    I = Milieu(s.origine,  s.point)
    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 s)
    assert(M in s)
    assert(N not in s)
    assert(s.mode_affichage == RIEN)
Exemplo n.º 33
0
def test_Projete_arc_cercle():
    O = Point(23.15, -12.75)
    A = Point(-12.5, 7.14)
    B = Point(7.15, 8.64)
    a = Arc_cercle(O, A, B)
    M = rand_pt()
    P = Projete_arc_cercle(M, a)
    assert (P in a)
    M.coordonnees = a.centre.coordonnees
    assert (not P.existe)
    M.coordonnees = -17.826266675199999, 11.760911186
    assert (type(P.coordonnees) is tuple)
    assertAlmostEqual(A.coordonnees, P.coordonnees)
    assertEqual(A, P)
Exemplo n.º 34
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))
Exemplo n.º 35
0
def test_Segment():
    A = Point(4.5,  7.3)
    B = Point(4,  2.1)
    s = Segment(A,  B)
    assert(isinstance(s.etiquette, Label_segment))
    assertAlmostEqual(s.longueur, sqrt((B.x - A.x)**2 + (B.y - A.y)**2))
    I = Milieu(s.point1,  s.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 s)
    assert(M not in s)
    assert(N not in s)
    assert(s.mode_affichage == 'rien')
    K = Point(s, 0.5)
    assert K.confondu(I)
Exemplo n.º 36
0
def test_repetition_plusieurs_niveaux():
    s = rep(3, evts=['S'], probas=['3/4'])
    resultat = '''>S_1:3/4
>>S_2:3/4
>>>S_3:3/4
>>>&S_3:1/4
>>&S_2:1/4
>>>S_3:3/4
>>>&S_3:1/4
>&S_1:1/4
>>S_2:3/4
>>>S_3:3/4
>>>&S_3:1/4
>>&S_2:1/4
>>>S_3:3/4
>>>&S_3:1/4'''
    assertEqual(s, resultat)
Exemplo n.º 37
0
def test_nettoyer():
    f = Feuille()
    o = f.objets
    ex = f.executer
    ex('A=(5,4)')
    ex('B=(6,5.3)')
    ex('s=Segment(A, B)')
    ex('I=Milieu(s)')
    ex('M=Point(s)')
    ex('d=Droite(A,  B)')
    ex('C=(4, 8)')
    ex('d2=Droite(A, C)')

    ex('B.style(visible = False)')
    noms = o.noms
    assert(noms == set(("A", "B", "s", "I", "M", "d", "C", "d2", "B", "xmin", "xmax", "ymin", "ymax", "dpx", "dpy")))
    f.nettoyer()
    assert(o.noms == noms)

    ex('s.style(visible = False)')
    f.nettoyer()
    assert(o.noms == noms)

    ex('M.style(visible = False)')
    f.nettoyer()
    noms -= set(("M", "s"))
    assertEqual(o.noms, noms)

    ex('d.style(visible = False)')
    f.nettoyer()
    noms.remove("d")
    assertEqual(o.noms, noms)

    ex('I.style(visible = False)')
    f.nettoyer()
    noms -= set(("B", "I"))
    assertEqual(o.noms, noms)

    # Les textes vides sont supprimés.
    ex('txt = Texte()')
    noms.add('txt')
    assertEqual(o.noms, noms)
    f.nettoyer()
    noms.remove('txt')
    assertEqual(o.noms, noms)
Exemplo n.º 38
0
def test_repetition_sans_numeroter():
    rep2 = partial(rep, 2, False)

    s = rep2(evts=['A', 'B', 'C'], probas=['0,5', '0,3', '0,2'])
    resultat = '''>A:0,5
>>A:0,5
>>B:0,3
>>C:0,2
>B:0,3
>>A:0,5
>>B:0,3
>>C:0,2
>C:0,2
>>A:0,5
>>B:0,3
>>C:0,2'''
    assertEqual(s, resultat)

    s = rep2(evts=['&A'], probas=['0,6'])
    resultat = '''>A:0,4
>>A:0,4
>>&A:0,6
>&A:0,6
>>A:0,4
>>&A:0,6'''

    s = rep(3, False, evts=['F', 'G'], probas=['', ''])
    resultat = '''>F:
>>F:
>>>F:
>>>G:
>>G:
>>>F:
>>>G:
>G:
>>F:
>>>F:
>>>G:
>>G:
>>>F:
>>>G:'''
    assertEqual(s, resultat)
Exemplo n.º 39
0
def test_repetition_sans_numeroter():
    rep2 = partial(rep, 2, False)

    s = rep2(A=.5, B=.3, C=.2)
    resultat = '''>A:0,5
>>A:0,5
>>B:0,3
>>C:0,2
>B:0,3
>>A:0,5
>>B:0,3
>>C:0,2
>C:0,2
>>A:0,5
>>B:0,3
>>C:0,2'''
    assertEqual(s, resultat)

    s = rep2(**{'&A': .6})
    resultat = '''>A:0,4
>>A:0,4
>>&A:0,6
>&A:0,6
>>A:0,4
>>&A:0,6'''

    s = rep(3, False, **{'F': '', 'G': ''})
    resultat = '''>F:
>>F:
>>>F:
>>>G:
>>G:
>>>F:
>>>G:
>G:
>>F:
>>>F:
>>>G:
>>G:
>>>F:
>>>G:'''
    assertEqual(s, resultat)
Exemplo n.º 40
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)
        assertEqual(alpha.info, u'Angle alpha de valeur 0.3 rad')
    with contexte(decimales = 3):
        assert(a.info == u'Arc a de longueur 7.505')
Exemplo n.º 41
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)
        assertEqual(alpha.info, u'Angle alpha de valeur 0,3 rad')
    with contexte(decimales = 3):
        assert(a.info == u'Arc a de longueur 7,505')
Exemplo n.º 42
0
def test_trigo():
    # Vérifie que arcsin est correctement implémenté (appel à math, numpy ou
    # sympy suivant le type d'objet).
    assertAlmostEqual(asin(.2), math.asin(.2))
    a, b, c = asin([.2, .3, .4])
    d, e, f = numpy.arcsin([.2, .3, .4])
    assertAlmostEqual(a, d)
    assertAlmostEqual(b, e)
    assertAlmostEqual(c, f)
    assertEqual(asin(x + 1), sympy.asin(x + 1))
    # Vérifie que arccos est correctement implémenté (appel à math, numpy ou
    # sympy suivant le type d'objet).
    assertAlmostEqual(acos(.2), math.acos(.2))
    a, b, c = acos([.2, .3, .4])
    d, e, f = numpy.arccos([.2, .3, .4])
    assertAlmostEqual(a, d)
    assertAlmostEqual(b, e)
    assertAlmostEqual(c, f)
    assertEqual(acos(x + 1), sympy.acos(x + 1))
    # Vérifie que arctan est correctement implémenté (appel à math, numpy ou
    # sympy suivant le type d'objet).
    assertAlmostEqual(atan(.2), math.atan(.2))
    a, b, c = atan([.2, .3, .4])
    d, e, f = numpy.arctan([.2, .3, .4])
    assertAlmostEqual(a, d)
    assertAlmostEqual(b, e)
    assertAlmostEqual(c, f)
    assertEqual(atan(x + 1), sympy.atan(x + 1))
Exemplo n.º 43
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)
Exemplo n.º 44
0
def test_Barycentre():
    M = Point(3, 4)
    A = Point(1, 2)
    B = Point(2, 4)
    I = Milieu(A, B)
    K = Barycentre(M, A, B, (I, -4))
    assertEqual(K.x, 0)
    assertEqual(K.y, 2)
    assert (not Barycentre(M, A, (B, -2)).existe)
    assertEqual(type(K.coordonnees), tuple)
    # Test keyword 'points_ponderes'
    G = Barycentre(points_ponderes=(M, A, B, (I, -4)))
    assert (K.coordonnees == G.coordonnees)
    assert ("point_ponderes" not in G.style())
Exemplo n.º 45
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)
Exemplo n.º 46
0
def test_Cercle_rayon():
    A = Point(-2.586, 7.541)
    c_1 = Cercle_rayon(A, -1)
    c0 = Cercle_rayon(A, 0)
    c2 = Cercle_rayon(A, 2)
    assert (isinstance(c_1.etiquette, Label_cercle))
    assert (not c_1.existe)
    assert (c0.existe)
    assert (c2.existe)
    assertAlmostEqual(A.coordonnees, c0.centre.coordonnees)
    assert (A not in c_1)
    assert (A in c0)
    assert (A not in c2)
    assertEqual(c_1.rayon, -1)
    assertEqual(c0.rayon, 0)
    assertEqual(c2.rayon, 2)
    k = random()
    B = Point(A.x + 2 * sin(k), A.y + 2 * cos(k))
    assert (B in c2)
Exemplo n.º 47
0
def test_Vecteur_unitaire():
    u = Vecteur_unitaire(Vecteur_libre(random(), random()))
    assertAlmostEqual(u.norme, 1)
    assertEqual(type(u.coordonnees), tuple)
Exemplo n.º 48
0
def test_Point_sympy():
    A = Point('1/2', '2/3')
    assertEqual(A.x, symp('1/2'))
    assertAlmostEqual(A.coordonnees, (1 / 2, 2 / 3))
Exemplo n.º 49
0
def test_operations():
    for i in xrange(10):
        a = randint(50) - randint(50)
        b = randint(50) - randint(50)
        if i >= 5:
            a += random()
            b += random()
        u = Variable(a)
        v = Variable(b)
        # Test opérations :
        if i < 5:
            assertEqual(u + v, a + b)
            assertEqual(u - v, a - b)
            assertEqual(u * v, a * b)
            if a != 0:
                assertEqual(u**v, a**b)
            if b != 0:
                assertEqual(u / v, a / b)
                assertEqual(u // v, a // b)
                assertEqual(u % v, a % b)
        else:
            assertAlmostEqual(u + v, a + b)
            assertAlmostEqual(u - v, a - b)
            assertAlmostEqual(u * v, a * b)
            if a != 0:
                assertAlmostEqual(abs(u)**v, abs(a)**b)
    # Test assignations :
        u += v
        a += b
        assertEqual(u, a)
        u *= v
        a *= b
        assertEqual(u, a)
Exemplo n.º 50
0
def test_strip_trailing_zeros():
    assertEqual(strip_trailing_zeros('.0450*1.54556000+4.2003+a.e00+.003+4.000'), '.045*1.54556+4.2003+a.e00+.003+4')
Exemplo n.º 51
0
def test_preformatage_geolib_ensemble():
    p = intervalles.preformatage_geolib_ensemble
    assertEqual(p('{2}'), ('{2}', ([], )))
    assertEqual(p(']-3;4'), (']-3;4[', (['4'], )))
    assertEqual(p('-5;'), (']-5;oo[', (['-5'], )))
    assertEqual(p('R*'), (']-oo;+oo[-{0}', ([], )))
    assertEqual(p('R+*'), (']0;+oo[', ([], )))
    assertEqual(p('{2;5}'), ('{2;5}', ([], )))
    assertEqual(p(']-1;1|2;3[U]4;6'),
                (']-1;1[|]2;3[+]4;6[', (['1'], ['2', '6'])))
    assertEqual(p(']1;2[+]1;2['), (']1;2[+]1;2[', ([], )))
    assertEqual(p('R-{1;2}'), (']-oo;+oo[-{1;2}', ([], )))
Exemplo n.º 52
0
def test_Vecteur_libre():
    u = Vecteur_libre(1, -2)
    u.y = -3
    assertEqual(u.norme, sqrt(10))
    assertEqual(type(u.coordonnees), tuple)