本文整理汇总了Python中tools.testlib.assertAlmostEqual函数的典型用法代码示例。如果您正苦于以下问题:Python assertAlmostEqual函数的具体用法?Python assertAlmostEqual怎么用?Python assertAlmostEqual使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assertAlmostEqual函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reecriture
def test_reecriture():
f = Feuille()
H = f.objets.H = Fonction("2x^2+3x(1+x)", 'R')
def h(x):
return 2*x**2+3*x*(1+x)
assertAlmostEqual(H(17), h(17))
assertAlmostEqual(H(_VAL0), h(_VAL0))
示例2: test_executer
def test_executer():
f = Feuille()
o = f.objets
f.executer("A = (1, 2)")
f.executer("A.x += 1")
assert(o.A.x == 2)
f.executer("A' = 3, 4")
f.executer("s = [A A']")
f.executer("I = Milieu(s)")
assertAlmostEqual(o.I.xy, (2.5, 3))
f.executer("del")
assert("I" not in o.noms)
assert("A_prime" in o.noms)
f.executer("del")
f.executer("del")
assert("A_prime" not in o.noms)
f.executer("= (1, 2)")
assert(o.M1.coordonnees == (1, 2))
f.executer("txt0 = `Bonjour !`")
f.executer(r"txt1 = `$P\`ere et m\`ere ont un accent grave.$`")
f.executer("chaine_vide = ``")
assert(o.txt0.texte == "Bonjour !")
assert(o.txt1.texte == r"$P\`ere et m\`ere ont un accent grave.$")
assert(o.chaine_vide.texte == "")
f.executer("M = (5, 7)")
f.executer("C = _")
assert(o.C.x == 5)
f.executer("=((i,sqrt(i)) for i in (3,4,5,6))")
assert(o.M2.xy == (3, sqrt(3)))
assert(o.M3.xy == (4, sqrt(4)))
assert(o.M4.xy == (5, sqrt(5)))
assert(o.M5.xy == (6, sqrt(6)))
示例3: test_Droite_equation
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)
示例4: test_Carre_centre
def test_Carre_centre():
O = rand_pt()
M = rand_pt()
p = Carre_centre(O, M)
assert(p.centre.existe and p.centre is O)
assert(len(p.cotes) == 4)
assertAlmostEqual(p.aire, p.cotes[0].longueur**2)
示例5: test_Reflexion
def test_Reflexion():
d = Droite_equation(1, 6, -2)
r = Reflexion(d)
M = Point(random()+randint(50)-randint(50), random()+randint(50)-randint(50))
m = Mediatrice(M, r(M))
assertAlmostEqual(d.equation_reduite, m.equation_reduite)
assert(r(d) is d)
示例6: test_Triangle
def test_Triangle():
A = rand_pt()
B = rand_pt()
C = rand_pt()
t = Triangle(A, B, C)
O = t.centre_cercle_circonscrit
assertAlmostEqual(Segment(O, A).longueur, Segment(O, C).longueur)
示例7: test_Quadrilatere
def test_Quadrilatere():
A = rand_pt()
B = rand_pt()
C = rand_pt()
D = rand_pt()
p = Quadrilatere(A, B, C, D)
assertAlmostEqual(p.centre.coordonnees, Barycentre(A, B, C, D).coordonnees)
示例8: test_session
def test_session():
i = Interprete(verbose = VERBOSE)
i.evaluer("1+7")
i.evaluer("x-3")
i.evaluer("ans()+ans(1)")
assertDernier(i, "x + 5")
i.evaluer("f(x, y, z)=2x+3y-z")
i.evaluer("f(-1, 5, a)")
assertDernier(i, "-a + 13")
i.evaluer("f(x)=x^2-7x+3")
i.evaluer("f'(x)")
assertDernier(i, "2*x - 7")
# Noms réservés
assertRaises(NameError, i.evaluer, "e=3")
assertRaises(NameError, i.evaluer, "pi=3")
assertRaises(NameError, i.evaluer, "i=3")
assertRaises(NameError, i.evaluer, "oo=3")
assertRaises(NameError, i.evaluer, "factorise=3")
# Etc.
# Test des générateurs
i.evaluer('f(x)=x+3')
i.evaluer('[f(j) for j in range(1, 11)]')
assertDernier(i, '[4, 5, 6, 7, 8, 9, 10, 11, 12, 13]')
i.evaluer('tuple(i for i in range(7))')
assertDernier(i, '(0, 1, 2, 3, 4, 5, 6)')
i.evaluer('[j for j in range(7)]')
assertDernier(i, '[0, 1, 2, 3, 4, 5, 6]')
# _11 is an alias for ans(11)
i.evaluer('_11 == _')
assertDernier(i, 'True')
i.evaluer('_7')
assertDernier(i, "2*x - 7")
# _ is an alias for ans(-1), __ is an alias for ans(-2), and so on.
i.evaluer('_ == -7 + 2*x')
assertDernier(i, 'True')
i.evaluer('__')
assertDernier(i, "2*x - 7")
i.evaluer('______') # ans(-6)
assertDernier(i, '(0, 1, 2, 3, 4, 5, 6)')
# Affichage des chaînes en mode text (et non math)
i.evaluer('"Bonjour !"')
assert i.latex_dernier_resultat == u'\u201CBonjour !\u201D'
# Virgule comme séparateur décimal
resultat, latex = i.evaluer('1,2')
assert resultat == '1,2'
assertAlmostEqual(i.derniers_resultats[-1], 1.2)
# Avec un espace, c'est une liste (tuple) par contre
resultat, latex = i.evaluer('1, 2')
assertEqual(resultat, '(1 ; 2)')
resultat, latex = i.evaluer('"1.2"')
assert resultat == '"1.2"'
i.evaluer('?aide')
i.evaluer('aide?')
i.evaluer('aide(aide)')
msg_aide = u"\n== Aide sur aide ==\nRetourne (si possible) de l'aide sur la fonction saisie."
resultats = i.derniers_resultats
assert resultats[-3:] == [msg_aide, msg_aide, msg_aide]
# LaTeX
latex = i.evaluer("gamma(x)")[1]
assertEqual(latex, r'$\mathrm{\Gamma}\left(x\right)$')
示例9: test_Parallele
def test_Parallele():
d0 = Droite_equation(2, 1, 7)
A = Point(-2, 3)
d = Parallele(d0, A)
assert(d.parallele(d0))
assert(d.droite is d0 and d.point is A)
assertAlmostEqual(d0.equation[:1], d.equation[:1])
示例10: test_Point_equidistant
def test_Point_equidistant():
A = rand_pt()
B = rand_pt()
C = rand_pt()
P = Point_equidistant(A, B, C)
assertAlmostEqual(Segment(A, P).longueur, Segment(B, P).longueur)
assertAlmostEqual(Segment(A, P).longueur, Segment(C, P).longueur)
assert(P in Mediatrice(A, B))
示例11: test_variables
def test_variables():
f = Feuille()
o = f.objets
a = o.a = 3
b = o.b = 5
g = o.g = Fonction("a*x+b")
assertAlmostEqual(g(4), a*4+b)
assertAlmostEqual(g(_VAL0), a*_VAL0+b)
示例12: test_Secteur_angulaire
def test_Secteur_angulaire():
u = Vecteur_libre(5.458, -2.546)
v = Vecteur_libre(-5.75, 12.6)
P = Point(2.54, -5.68)
a = Secteur_angulaire(P, u, v)
assert(isinstance(a.etiquette, Label_angle))
assertAlmostEqual(a.val, 2.43538435941)
assertAlmostEqual(a.degre, 139.537245287)
示例13: test_Pentagone
def test_Pentagone():
A = rand_pt()
B = rand_pt()
C = rand_pt()
D = rand_pt()
E = rand_pt()
p = Pentagone(A, B, C, D, E)
assertAlmostEqual(p.centre.coordonnees, Barycentre(A, B, C, D, E).coordonnees)
示例14: test_Hexagone
def test_Hexagone():
A = rand_pt()
B = rand_pt()
C = rand_pt()
D = rand_pt()
E = rand_pt()
F = rand_pt()
p = Hexagone(A, B, C, D, E, F)
assertAlmostEqual(p.centre.coordonnees, Barycentre(A, B, C, D, E, F).coordonnees)
示例15: test_Extremite
def test_Extremite():
v=Vecteur_libre(-4.2, -6.7)
w = Representant(v)
A = w.origine
B = w.extremite
assertAlmostEqual((B.x - A.x, B.y - A.y), (v.x, v.y))
C = Extremite(w, couleur = 'purple')
assert C is B
assert C.style('couleur') == 'purple'