Debian Codegraph @

wxgeometrie/mathlib/tests/test_sympy.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 # -*- coding: utf-8 -*-
2
3 import os, math,sys
4 TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__),"../../.."))
5 sys.path.insert(0, TOPDIR)
6
7 from sympy import (Symbol, exp, solve, limit, S, E, Matrix, Integer, oo,
8 sympify, Float, sqrt,
9 )
10
•11 import tools.unittests, unittest
12
13 def isDebian():
14 issueFile = os.path.join('/etc','issue')
15 return os.path.isfile(issueFile) and "Debian" in open(issueFile).read()
16
17 # Teste que certains bugs de sympy sont bien ou résolus, ou temporairement patchés
18
•19 class MathlibTest(tools.unittests.TestCase):
20
21 def test_sympy(self):
22 x = Symbol('x', real=True)
23 self.assertTrue(-oo < oo)
24 self.assertFalse(-1.5 < -oo)
25 self.assertIsNone((1 - exp(x)).is_negative)
26 self.assertEqual(Matrix([[1, 2], [3, 4]])**Integer(2),
27 Matrix([[7, 10], [15, 22]]))
28 self.assertAlmostEqual(E._evalf(50), math.e)
29 self.assertEqual( solve(1/x, x), []) # issue 1694
30 self.assertEqual(solve(-(1 + x)/(2 + x)**2 + 1/(2 + x), x),
31 []) # issue 1694
32 self.assertEqual(limit(1 + 1/x, x, 0, dir='-'), -oo)
33 self.assertEqual(limit(1/x**2, x, 0, dir='-'), oo)
34 self.assertEqual(sympify('45'), 45) # issue 2508
35
36 @unittest.expectedFailure
37 def test_issue10391(self):
38 # issue 10391 (FS#319)
39 x = Symbol('x', real=True)
40 self.assertEqual(solve((2*x + 8)*exp(-6*x), x), [-4])
41
42 def test_sympy_solving_with_floats(self):
43 x = Symbol('x', real=True)
44
45 sols = solve(exp(-Float('0.5')*x + Float('0.4')) - 1)
46 self.assertEqual(len(sols), 1)
47 sol = sols[0]
48 self.assertAlmostEqual(sol, Float('0.8'))
49
50 sols = solve(exp(-Float('0.5')*x - Float('0.4')) - 1)
51 self.assertEqual(len(sols), 1)
52 sol = sols[0]
53 self.assertAlmostEqual(sol, Float('-0.8'))
54
55 sols = solve(exp(-Float('0.5', 10)*x + Float('0.4', 10)) - 1)
56 self.assertEqual(len(sols), 1)
57 sol = sols[0]
58 self.assertAlmostEqual(sol, Float('0.8'))
59
60 def test_sympy_1_div_0(self):
61 self.assertIs(S.One/S.Zero, S.ComplexInfinity)
62
63 @unittest.skipIf(isDebian(),
64 "Debian Geophar packages do not embed sympy")
65 def test_sympy_files(self):
66 sympy_dir = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../../sympy')
67 def tst(path):
68 result = os.path.isfile(os.path.join(sympy_dir, path))
69 if not result:
70 print(os.path.join(sympy_dir, path), "is not an existing file")
71 self.assertTrue(result)
72 tst('AUTHORS')
73 tst('LICENSE')
74 tst('README.rst')
75
76
77
78 def test_solve_reals(self):
79 x = Symbol('x', real=True)
80 self.assertEqual(solve(sqrt(x)), [0])
81
82 def test_set(self):
83 self.assertEqual(S(2), 2)
84 self.assertEqual({S(2)}, {2})