Debian Codegraph @

wxgeometrie/modules/tablatex/tests/test_tabval.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
7 from wxgeometrie.modules.tablatex.tabval import tabval
8 from wxgeometrie import param
9
•10 import tools.unittests
11
•12 class ModuleTablatexTest(tools.unittests.TestCase):
13
14 def assert_tabval(self, chaine, code_latex, **options):
15 self.assert_tableau(tabval, chaine, code_latex, **options)
16
17
18 def test_mode_manuel(self, ):
19 s = "f(x)=exp(x+1): 0.25: -5, -4..0 ; 0.5 ; 1, 2..6 ; 7, 10..21"
20 tab = \
21 r"""\begin{center}
22 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
23 \hline
24 $x$ & $-5$ & $-4$ & $-3$ & $-2$ & $-1$ & $0$ & $0,5$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $10$ & $13$ & $16$ & $19$ & $21$ \\
25 \hline
26 $f(x)$ & $0$ & $0$ & $0,25$ & $0,25$ & $1$ & $2,75$ & $4,5$ & $7,5$ & $20$ & $54,5$ & $148,5$ & $403,5$ & $1096,75$ & $2981$ & $59874,25$ & $1202604,25$ & $24154952,75$ & $485165195,5$ & $3584912846,25$ \\
27 \hline
28 \end{tabular}
29 \end{center}
30 % f(x)=exp(x+1): 0.25: -5, -4..0 ; 0.5 ; 1, 2..6 ; 7, 10..21
31 """
32 self.assert_tabval(s, tab)
33
34 s = "f(x)=exp(x+1): [0.25]: -5,-4..0 ; 0.5 ; 1,2..6 ; 7,10..21"
35 tab = \
36 r"""\begin{center}
37 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
38 \hline
39 $x$ & $-5$ & $-4$ & $-3$ & $-2$ & $-1$ & $0$ & $0,5$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $10$ & $13$ & $16$ & $19$ & $21$ \\
40 \hline
41 $f(x)$ & $0$ & $0$ & $0,25$ & $0,25$ & $1$ & $2,75$ & $4,5$ & $7,5$ & $20$ & $54,5$ & $148,5$ & $403,5$ & $1096,75$ & $2981$ & $59874,25$ & $1202604,25$ & $24154952,75$ & $485165195,5$ & $3584912846,25$ \\
42 \hline
43 \end{tabular}
44 \end{center}
45 % f(x)=exp(x+1): [0.25]: -5,-4..0 ; 0.5 ; 1,2..6 ; 7,10..21
46 """
47 self.assert_tabval(s, tab)
48
49
50 def test_coupure(self, ):
51 s = "(2x+3)^2:-10..0// 1..10"
52 tab = \
53 r"""\begin{center}
54 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|}
55 \hline
56 $x$ & $-10$ & $-9$ & $-8$ & $-7$ & $-6$ & $-5$ & $-4$ & $-3$ & $-2$ & $-1$ & $0$ \\
57 \hline
58 $(2x+3)^2$ & $289$ & $225$ & $169$ & $121$ & $81$ & $49$ & $25$ & $9$ & $1$ & $1$ & $9$ \\
59 \hline
60 \end{tabular}
61
62 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|}
63 \hline
64 $x$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $8$ & $9$ & $10$ \\
65 \hline
66 $(2x+3)^2$ & $25$ & $49$ & $81$ & $121$ & $169$ & $225$ & $289$ & $361$ & $441$ & $529$ \\
67 \hline
68 \end{tabular}
69 \end{center}
70 % (2x+3)^2:-10..0// 1..10
71 """
72 self.assert_tabval(s, tab)
73
74
75 def test_mode_auto(self, ):
76 s = r"\frac{x^2}{2} sur [-4;4]"
77 tab = \
78 r"""\begin{center}
79 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}
80 \hline
81 $x$ & $-4$ & $-3$ & $-2$ & $-1$ & $0$ & $1$ & $2$ & $3$ & $4$ \\
82 \hline
83 $\frac{x^2}{2}$ & $8$ & $4,5$ & $2$ & $0,5$ & $0$ & $0,5$ & $2$ & $4,5$ & $8$ \\
84 \hline
85 \end{tabular}
86 \end{center}
87 % \frac{x^2}{2}:[0.01]:-4.0,-3.0..4
88 % \frac{x^2}{2} sur [-4;4]
89 """
90 self.assert_tabval(s, tab)
91
92 s = r"\frac{x^2}{2} sur [-4;4] pas 0,5"
93 tab = \
94 r"""\begin{center}
95 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
96 \hline
97 $x$ & $-4$ & $-3,5$ & $-3$ & $-2,5$ & $-2$ & $-1,5$ & $-1$ & $-0,5$ & $0$ & $0,5$ & $1$ & $1,5$ & $2$ & $2,5$ & $3$ & $3,5$ & $4$ \\
98 \hline
99 $\frac{x^2}{2}$ & $8$ & $6,13$ & $4,5$ & $3,13$ & $2$ & $1,13$ & $0,5$ & $0,13$ & $0$ & $0,13$ & $0,5$ & $1,13$ & $2$ & $3,13$ & $4,5$ & $6,13$ & $8$ \\
100 \hline
101 \end{tabular}
102 \end{center}
103 % \frac{x^2}{2}:[0.01]:-4.0,-3.5..4
104 % \frac{x^2}{2} sur [-4;4] pas 0,5
105 """
106 self.assert_tabval(s, tab)
107
108
109 def test_param_separateur_decimal(self, ):
110 try:
111 param.separateur_decimal = '.'
112 s = "f(x)=exp(x+1): 0.25: -5, -4..0 ; 0.5 ; 1, 2..6 ; 7, 10..21"
113 tab = \
114 r"""\begin{center}
115 \begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
116 \hline
117 $x$ & $-5$ & $-4$ & $-3$ & $-2$ & $-1$ & $0$ & $0.5$ & $1$ & $2$ & $3$ & $4$ & $5$ & $6$ & $7$ & $10$ & $13$ & $16$ & $19$ & $21$ \\
118 \hline
119 $f(x)$ & $0$ & $0$ & $0.25$ & $0.25$ & $1$ & $2.75$ & $4.5$ & $7.5$ & $20$ & $54.5$ & $148.5$ & $403.5$ & $1096.75$ & $2981$ & $59874.25$ & $1202604.25$ & $24154952.75$ & $485165195.5$ & $3584912846.25$ \\
120 \hline
121 \end{tabular}
122 \end{center}
123 % f(x)=exp(x+1): 0.25: -5, -4..0 ; 0.5 ; 1, 2..6 ; 7, 10..21
124 """
125 self.assert_tabval(s, tab)
126 finally:
127 param.separateur_decimal = ','
128
129
130 def test_formatage(self, ):
131 s = 'x^2:-2..2'
132 tab = \
133 r"""\begin{center}
134 \begin{tabular}{|c|c|c|c|c|c|}
135 \hline
136 $x$ & $\textbf{-2}$ & $\textbf{-1}$ & $\textbf{0}$ & $\textbf{1}$ & $\textbf{2}$ \\
137 \hline
138 $x^2$ & $\color{gray}4$ & $\color{gray}1$ & $\color{gray}0$ & $\color{gray}1$ & $\color{gray}4$ \\
139 \hline
140 \end{tabular}
141 \end{center}
142 % x^2:-2..2
143 """
144 self.assert_tabval(s, tab, formatage_antecedents=r'\textbf{VAL}',
145 formatage_images=r'\color{gray}VAL')