Debian Codegraph @

wxgeometrie/geolib/tests/test_fonctions.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2 import os, sys
3 TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),"../.."))
4 sys.path.insert(0, TOPDIR)
5
•6 import tools.unittests, unittest
7 from wxgeometrie.geolib import Fonction, Feuille
8
9 _VAL0 = -5.156557933
10
•11 class GeolibTest(tools.unittests.TestCase):
12
13 @unittest.expectedFailure
14 def test_Fonction(self):
15 "Test sans feuille."
16 g = Fonction('2x+7')
17 self.assertEqual(g(17), 41)
18 # La fonction n'est compilée que s'il y a une feuille.
19 # -> à tester lorsque chaque objet aura un feuille par défaut.
20
21
22 def test_base(self):
23 f = Feuille()
24 H = f.objets.H = Fonction("2*t**3+5", variable = 't')
25 self.assertAlmostEqual(H(_VAL0), 2*_VAL0**3+5)
26
27
28 def test_reecriture(self):
29 f = Feuille()
30 H = f.objets.H = Fonction("2x^2+3x(1+x)", 'R')
31 def h(x):
32 return 2*x**2+3*x*(1+x)
33 self.assertAlmostEqual(H(17), h(17))
34 self.assertAlmostEqual(H(_VAL0), h(_VAL0))
35
36
37 def test_variables(self):
38 f = Feuille()
39 o = f.objets
40 a = o.a = 3
41 b = o.b = 5
42 g = o.g = Fonction("a*x+b")
43 self.assertAlmostEqual(g(4), a*4+b)
44 self.assertAlmostEqual(g(_VAL0), a*_VAL0+b)
45
46 def test_intervalle(self):
47 f = Feuille()
48 o = f.objets
49 g = o.g = Fonction('x^2+2x+1', ']0;5')
50 self.assertEqual(g.style('extremites_cachees')[0][0].val, 5) # ([Variable(5)],)
51 self.assertEqual(g.ensemble, ']0;5[')
52