Debian Codegraph @

wxgeometrie/modules/tablatex/tests/test_tabsign.py

raw symbols ◀ ▶ SCIP
2 Debian patches 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
7 from wxgeometrie.modules.tablatex.tabsign import tabsign
8
•9 import tools.unittests
10
•11 class ModulesTablatexTest(tools.unittests.TestCase):
12
13 def assert_tabsign(self, chaine, code_latex, **options):
14 self.assert_tableau(tabsign, chaine, code_latex, **options)
15
16
17 def test_mode_manuel(self, ):
18 s = "x: -oo;+oo// 2x+1: -- -1/2 ++// 3-x: ++ 3 --// f(x)"
19 tab = \
20 r"""\begin{center}
21 \begin{tabular}{|c|ccccccc|}
22 \hline
23 $x$ & $-\infty$ & & $-\frac{1}{2}$ & & $3$ & & $+\infty$ \\
24 \hline
25 $2x+1$ & & $-$ & 0 & + & & + & \\
26 \hline
27 $3-x$ & & + & & + & 0 & $-$ & \\
28 \hline
29 $f(x)$ & & $-$ & 0 & + & 0 & $-$ & \\
30 \hline
31 \end{tabular}
32 \end{center}
33 % x: -oo;+oo// 2x+1: -- -1/2 ++// 3-x: ++ 3 --// f(x)
34 """
35 self.assert_tabsign(s, tab)
36
37
38
39 def test_mode_auto(self, ):
40 s = 'g(x)=(x-7/2)(x+7/2)'
41 tab = \
42 r'''\begin{center}
43 \begin{tabular}{|c|ccccccc|}
44 \hline
45 $x$ & $-\infty$ & & $-\frac{7}{2}$ & & $\frac{7}{2}$ & & $+\infty$ \\
46 \hline
47 $x-\frac{7}{2}$ & & $-$ & & $-$ & 0 & + & \\
48 \hline
49 $x+\frac{7}{2}$ & & $-$ & 0 & + & & + & \\
50 \hline
51 $g(x)$ & & + & 0 & $-$ & 0 & + & \\
52 \hline
53 \end{tabular}
54 \end{center}
55 % x: -oo;+oo// x-7/2: -- 7/2 ++ // x+7/2: -- -7/2 ++ // g(x)
56 % g(x)=(x-7/2)(x+7/2)
57 '''
58 self.assert_tabsign(s, tab)
59
60
61 def test_polynomes(self, ):
62 s= 'f(x)=x^3-30x^2+112'
63 tab = \
64 r"""\begin{center}
65 \begin{tabular}{|c|ccccccccc|}
66 \hline
67 $x$ & $-\infty$ & & $14-6 \sqrt{7}$ & & $2$ & & $14+6 \sqrt{7}$ & & $+\infty$ \\
68 \hline
69 $f(x)$ & & $-$ & 0 & + & 0 & $-$ & 0 & + & \\
70 \hline
71 \end{tabular}
72 \end{center}
73 % x: -oo;+oo// x^3-30 x^2+112: -- 14 - 6*sqrt(7) ++ 2 -- 14 + 6*sqrt(7) ++ // f(x)
74 % f(x)=x^3-30x^2+112
75 """
76 self.assert_tabsign(s, tab)
77
78 s = '- 6 x^{2} - 12 x + 4'
79 tab = \
80 r'''\begin{center}
81 \begin{tabular}{|c|ccccccc|}
82 \hline
83 $x$ & $-\infty$ & & $-\frac{\sqrt{15}}{3}-1$ & & $-1+\frac{\sqrt{15}}{3}$ & & $+\infty$ \\
84 \hline
85 $-6 x^{2}-12 x+4$ & & $-$ & 0 & + & 0 & $-$ & \\
86 \hline
87 \end{tabular}
88 \end{center}
89 % x: -oo;+oo// -6 x^(2)-12 x+4: -- -sqrt(15)/3 - 1 ++ -1 + sqrt(15)/3 -- // - 6 x^{2} - 12 x + 4
90 % - 6 x^{2} - 12 x + 4
91 '''
92 self.assert_tabsign(s, tab)
93
94
95 def test_quotients(self, ):
96 s = '(3x-2)/((x-1)^2)'
97 tab = \
98 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
99 \begin{center}
100 \begin{tabular}{|c|ccccccc|}
101 \hline
102 $x$ & $-\infty$ & & $\frac{2}{3}$ & & $1$ & & $+\infty$ \\
103 \hline
104 $3 x-2$ & & $-$ & 0 & + & & + & \\
105 \hline
106 $(x-1)^{2}$ & & + & & + & 0 & + & \\
107 \hline
108 $\frac{3x-2}{(x-1)^{2}}$ & & $-$ & 0 & + & \geopharDB{$\frac{3x-2}{(x-1)^{2}}$} & + & \\
109 \hline
110 \end{tabular}
111 \end{center}
112 % x: -oo;!1: !1;+oo// 3 x-2: -- 2/3 ++ // !(x-1)^2: ++ 1 ++ // (3x-2)/((x-1)^2)
113 % (3x-2)/((x-1)^2)
114 '''
115 self.assert_tabsign(s, tab)
116
117 s = '(3x-2)/(x-1)^2'
118 tab = \
119 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
120 \begin{center}
121 \begin{tabular}{|c|ccccccc|}
122 \hline
123 $x$ & $-\infty$ & & $\frac{2}{3}$ & & $1$ & & $+\infty$ \\
124 \hline
125 $3 x-2$ & & $-$ & 0 & + & & + & \\
126 \hline
127 $(x-1)^{2}$ & & + & & + & 0 & + & \\
128 \hline
129 $\frac{3x-2}{(x-1)^{2}}$ & & $-$ & 0 & + & \geopharDB{$\frac{3x-2}{(x-1)^{2}}$} & + & \\
130 \hline
131 \end{tabular}
132 \end{center}
133 % x: -oo;!1: !1;+oo// 3 x-2: -- 2/3 ++ // !(x-1)^2: ++ 1 ++ // (3x-2)/(x-1)^2
134 % (3x-2)/(x-1)^2
135 '''
136 self.assert_tabsign(s, tab)
137
138
139 def test_latex(self, ):
•140 s = r'\dfrac{3x-2}{(x-1)^2}'
141 tab = \
142 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
143 \begin{center}
144 \begin{tabular}{|c|ccccccc|}
145 \hline
146 $x$ & $-\infty$ & & $\frac{2}{3}$ & & $1$ & & $+\infty$ \\
147 \hline
148 $3 x-2$ & & $-$ & 0 & + & & + & \\
149 \hline
150 $(x-1)^{2}$ & & + & & + & 0 & + & \\
151 \hline
152 $\dfrac{3x-2}{(x-1)^{2}}$ & & $-$ & 0 & + & \geopharDB{$\dfrac{3x-2}{(x-1)^{2}}$} & + & \\
153 \hline
154 \end{tabular}
155 \end{center}
156 % x: -oo;!1: !1;+oo// 3 x-2: -- 2/3 ++ // !(x-1)^2: ++ 1 ++ // \dfrac{3x-2}{(x-1)^2}
157 % \dfrac{3x-2}{(x-1)^2}
158 '''
159 self.assert_tabsign(s, tab)
160
•161 s = r"g(x)=\dfrac{-x+1}{\e^{x}}"
162 tab = \
163 r'''\begin{center}
164 \begin{tabular}{|c|ccccc|}
165 \hline
166 $x$ & $-\infty$ & & $1$ & & $+\infty$ \\
167 \hline
168 $-x+1$ & & + & 0 & $-$ & \\
169 \hline
170 $\e^{x}$ & & + & & + & \\
171 \hline
172 $g(x)$ & & + & 0 & $-$ & \\
173 \hline
174 \end{tabular}
175 \end{center}
176 % x: -oo;+oo// -x+1: ++ 1 -- // e^(x): ++ // g(x)
177 % g(x)=\dfrac{-x+1}{\e^{x}}
178 '''
179 self.assert_tabsign(s, tab)
180
•181 s= r"f'(x)=1-\e^{-x+2}"
182 tab = \
183 r'''\begin{center}
184 \begin{tabular}{|c|ccccc|}
185 \hline
186 $x$ & $-\infty$ & & $2$ & & $+\infty$ \\
187 \hline
188 $f'(x)$ & & $-$ & 0 & + & \\
189 \hline
190 \end{tabular}
191 \end{center}
192 % x: -oo;+oo// 1-e^(-x+2): -- 2 ++ // f'(x)
193 % f'(x)=1-\e^{-x+2}
194 '''
195 self.assert_tabsign(s, tab)
196
197
198 def test_intervalle(self, ):
199 s = "x^2 sur [1;+oo["
200 tab = \
201 r'''\begin{center}
202 \begin{tabular}{|c|ccc|}
203 \hline
204 $x$ & $1$ & & $+\infty$ \\
205 \hline
206 $x^{2}$ & & + & \\
207 \hline
208 \end{tabular}
209 \end{center}
210 % x: 1;+oo// x^2: ++ // x^2
211 % x^2 sur [1;+\infty[
212 '''
213 self.assert_tabsign(s, tab)
214
215 s = "u(x)=1-x sur ]0;+oo["
216 tab = \
217 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
218 \begin{center}
219 \begin{tabular}{|c|ccccc|}
220 \hline
221 $x$ & $0$ & & $1$ & & $+\infty$ \\
222 \hline
223 $u(x)$ & \geopharDB{$u(x)$} & + & 0 & $-$ & \\
224 \hline
225 \end{tabular}
226 \end{center}
227 % x: !0;+oo// 1-x: ++ 1 -- // u(x)
228 % u(x)=1-x sur ]0;+\infty[
229 '''
230 self.assert_tabsign(s, tab)
231
232 s = "u(x)=x(1-x) sur ]-1;0[U]0;4["
233 tab = \
234 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
235 \begin{center}
236 \begin{tabular}{|c|ccccccc|}
237 \hline
238 $x$ & $-1$ & & $0$ & & $1$ & & $4$ \\
239 \hline
240 $x$ & & $-$ & 0 & + & & + & \\
241 \hline
242 $1-x$ & & + & & + & 0 & $-$ & \\
243 \hline
244 $u(x)$ & \geopharDB{$u(x)$} & $-$ & \geopharDB{$u(x)$} & + & 0 & $-$ & \geopharDB{$u(x)$} \\
245 \hline
246 \end{tabular}
247 \end{center}
248 % x: !-1;!0: !0;!4// !x: -- 0 ++ // 1-x: ++ 1 -- // u(x)
249 % u(x)=x(1-x) sur ]-1;0[U]0;4[
250 '''
251 self.assert_tabsign(s, tab)
252
253
254 s = "u(x)=(1+x)(1-x)/x sur ]-3;2[U]2;4]"
255 tab = \
256 r'''\providecommand{\geopharDB}[1]{$\left|\vphantom{\text{#1}}\right|$}
257 \begin{center}
258 \begin{tabular}{|c|ccccccccccc|}
259 \hline
260 $x$ & $-3$ & & $-1$ & & $0$ & & $1$ & & $2$ & & $4$ \\
261 \hline
262 $1+x$ & & $-$ & 0 & + & & + & & + & & + & \\
263 \hline
264 $1-x$ & & + & & + & & + & 0 & $-$ & & $-$ & \\
265 \hline
266 $x$ & & $-$ & & $-$ & 0 & + & & + & & + & \\
267 \hline
268 $u(x)$ & \geopharDB{$u(x)$} & + & 0 & $-$ & \geopharDB{$u(x)$} & + & 0 & $-$ & \geopharDB{$u(x)$} & $-$ & \\
269 \hline
270 \end{tabular}
271 \end{center}
272 % x: !-3;!0: !0;!2: !2;4// 1+x: -- -1 ++ // 1-x: ++ 1 -- // !x: -- 0 ++ // u(x)
273 % u(x)=(1+x)(1-x)/x sur ]-3;2[U]2;4]
274 '''
275 self.assert_tabsign(s, tab)
276
277
278 def test_issue_173(self, ):
•279 s = r"(1 - x)\e^{ 2x}"
280 tab = \
281 r'''\begin{center}
282 \begin{tabular}{|c|ccccc|}
283 \hline
284 $x$ & $-\infty$ & & $1$ & & $+\infty$ \\
285 \hline
286 $1-x$ & & + & 0 & $-$ & \\
287 \hline
288 $\e^{2 x}$ & & + & & + & \\
289 \hline
290 $(1-x)\e^{ 2x}$ & & + & 0 & $-$ & \\
291 \hline
292 \end{tabular}
293 \end{center}
294 % x: -oo;+oo// 1-x: ++ 1 -- // e^(2 x): ++ // (1 - x)\e^{ 2x}
295 % (1 - x)\e^{ 2x}
296 '''
297 self.assert_tabsign(s, tab)
298
299
300 def test_issue_200(self, ):
301 s = 'f(x)=x^2-3'
302 tab = \
303 r'''\begin{center}
304 \begin{tabular}{|c|ccccccc|}
305 \hline
306 $x$ & $-\infty$ & & $-\sqrt{3}$ & & $\sqrt{3}$ & & $+\infty$ \\
307 \hline
308 $f(x)$ & & + & 0 & $-$ & 0 & + & \\
309 \hline
310 \end{tabular}
311 \end{center}
312 % x: -oo;+oo// x^2-3: ++ -sqrt(3) -- sqrt(3) ++ // f(x)
313 % f(x)=x^2-3
314 '''
315 self.assert_tabsign(s, tab)
316
317
318 def test_issue_189(self, ):
319 # Tableaux de signes et de variation avec des decimaux
320 s = '2-0.25x'
321 options = {'cellspace': True}
322 tab = \
323 r'''\begin{center}
324 \begin{tabular}{|Sc|ScScScScSc|}
325 \hline
326 $x$ & $-\infty$ & & $8$ & & $+\infty$ \\
327 \hline
328 $2-0.25x$ & & + & 0 & $-$ & \\
329 \hline
330 \end{tabular}
331 \end{center}
332 % x: -oo;+oo// 2-0.25 x: ++ 8 -- // 2-0.25x
333 % 2-0.25x
334 '''
335 self.assert_tabsign(s, tab, **options)
336
337
338 def test_intervalle_virgule(self, ):
339 s = 'h(x)=x^2-x/2-3 sur [-2,5;3,5]'
340 options = {'cellspace': True}
341 tab = \
342 r'''\begin{center}
343 \begin{tabular}{|Sc|ScScScScScScSc|}
344 \hline
345 $x$ & $-2,5$ & & $-\frac{3}{2}$ & & $2$ & & $3,5$ \\
346 \hline
347 $h(x)$ & & + & 0 & $-$ & 0 & + & \\
348 \hline
349 \end{tabular}
350 \end{center}
351 % x: -2,5;3,5// x^2-x/2-3: ++ -3/2 -- 2 ++ // h(x)
352 % h(x)=x^2-x/2-3 sur [-2,5;3,5]
353 '''
354 self.assert_tabsign(s, tab, **options)
355
356
357 def test_constante(self, ):
358 s = 'f(x)=5'
359 tab = \
360 r'''\begin{center}
361 \begin{tabular}{|c|ccc|}
362 \hline
363 $x$ & $-\infty$ & & $+\infty$ \\
364 \hline
365 $f(x)$ & & + & \\
366 \hline
367 \end{tabular}
368 \end{center}
369 % x: -oo;+oo// 5: ++ // f(x)
370 % f(x)=5
371 '''
372 self.assert_tabsign(s, tab)
373
374
375 def test_issue_247(self, ):
376 "FS#247 - Accepter la syntaxe suivant : 'f(x): -- -8 ++ -2 -- 5 ++'."
377 s = "f(x): -- -8 ++ -2 -- 5 ++"
378 tab = \
379 r'''\begin{center}
380 \begin{tabular}{|c|ccccccccc|}
381 \hline
382 $x$ & $-\infty$ & & $-8$ & & $-2$ & & $5$ & & $+\infty$ \\
383 \hline
384 $f(x)$ & & $-$ & 0 & + & 0 & $-$ & 0 & + & \\
385 \hline
386 \end{tabular}
387 \end{center}
388 % f(x): -- -8 ++ -2 -- 5 ++
389 '''
390 self.assert_tabsign(s, tab)
391
392 def test_mix_numeric_and_symbolic_values(self, ):
393 s = 'f(x): -- x_1 ++ 5 ++ x_2 -- 7 --'
394 tab = \
395 r'''\begin{center}
396 \begin{tabular}{|c|ccccccccccc|}
397 \hline
398 $x$ & $-\infty$ & & $x_1$ & & $5$ & & $x_2$ & & $7$ & & $+\infty$ \\
399 \hline
400 $f(x)$ & & $-$ & 0 & + & 0 & + & 0 & $-$ & 0 & $-$ & \\
401 \hline
402 \end{tabular}
403 \end{center}
404 % f(x): -- x_1 ++ 5 ++ x_2 -- 7 --
405 '''
406 self.assert_tabsign(s, tab)
407
408 s = r'x:-oo;+oo // f(x): -- 5 ++ // g(x): ++ \alpha=2,1 --'
409 tab = \
410 r'''\begin{center}
411 \begin{tabular}{|c|ccccccc|}
412 \hline
413 $x$ & $-\infty$ & & $\alpha$ & & $5$ & & $+\infty$ \\
414 \hline
415 $f(x)$ & & $-$ & & $-$ & 0 & + & \\
416 \hline
417 $g(x)$ & & + & 0 & $-$ & & $-$ & \\
418 \hline
419 $f(x)g(x)$ & & $-$ & 0 & + & 0 & $-$ & \\
420 \hline
421 \end{tabular}
422 \end{center}
423 % x:-oo;+oo // f(x): -- 5 ++ // g(x): ++ \alpha=2,1 --
424 '''
425 self.assert_tabsign(s, tab)
426
427 def test_approche(self, ):
428 s = "f(x)=x^2-3x-5"
429 tab = \
430 r'''\begin{center}
431 \begin{tabular}{|c|ccccccc|}
432 \hline
433 $x$ & $-\infty$ & & $\frac{3}{2}-\frac{\sqrt{29}}{2}$ & & $\frac{3}{2}+\frac{\sqrt{29}}{2}$ & & $+\infty$ \\
434 \hline
435 $f(x)$ & & + & 0 & $-$ & 0 & + & \\
436 \hline
437 \end{tabular}
438 \end{center}
439 % x: -oo;+oo// x^2-3 x-5: ++ 3/2 - sqrt(29)/2 -- 3/2 + sqrt(29)/2 ++ // f(x)
440 % f(x)=x^2-3x-5
441 '''
442 self.assert_tabsign(s, tab)
443
444 options = {'approche': True, "decimales": 2}
445 tab = \
446 r'''\begin{center}
447 \begin{tabular}{|c|ccccccc|}
448 \hline
449 $x$ & $-\infty$ & & $-1,19$ & & $4,19$ & & $+\infty$ \\
450 \hline
451 $f(x)$ & & + & 0 & $-$ & 0 & + & \\
452 \hline
453 \end{tabular}
454 \end{center}
455 % x: -oo;+oo// x^2-3 x-5: ++ -1,19 -- 4,19 ++ // f(x)
456 % f(x)=x^2-3x-5
457 '''
458 self.assert_tabsign(s, tab, **options)