* Bugs 16071+16072+16075 fixed: prettyprint() debugged & a bit improved
[scilab.git] / scilab / modules / string / tests / unit_tests / prettyprint_syslin.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2019 - Samuel GOUGEON
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9 // <-- NO CHECK REF -->
10
11 TMP = strsubst(fileparts(TMPDIR), "\", "/");
12
13 // LINEAR SYSTEMS
14 // ==============
15 grand("setsd",0);
16 A = grand(3,3,"uin",-999,999)/100;
17 B = grand(3,2,"uin",-999,999)/100;
18 C = grand(2,3,"uin",-999,999)/100;
19
20 // Continuous time:
21 // ---------------
22 s = syslin("c", A, B, C);
23
24 // LaTeX
25 ref = "${\begin{pmatrix}{\left\{\begin{array}{rcl}\dot{X}(t)&=&{\begin{pmatrix}2.02&7.14&-8.59\cr -9.99&-9.64&-1.27\cr 5.59&7.25&7.44\cr \end{pmatrix}} X(t)+{\begin{pmatrix}4.46&-0.62\cr 8.42&-3.3\cr -2.67&9.04\cr \end{pmatrix}}U(t)\cr Y(t) &=& {\begin{pmatrix}-7.72&6.86&-6.75\cr -4.58&-3.59&-8.06\cr \end{pmatrix}} X(t) \end{array}\right.}\cr \end{pmatrix}}$";
26 assert_checkequal(prettyprint(s), ref);
27
28 // TeX
29 ref = "${\pmatrix{{\left\{\eqalign{\dot{X}(t) &= {\pmatrix{2.02&7.14&-8.59\cr -9.99&-9.64&-1.27\cr 5.59&7.25&7.44\cr }} X(t)+{\pmatrix{4.46&-0.62\cr 8.42&-3.3\cr -2.67&9.04\cr }}U(t)\cr Y(t) &= {\pmatrix{-7.72&6.86&-6.75\cr -4.58&-3.59&-8.06\cr }} X(t) }\right.}\cr }}$";
30 assert_checkequal(prettyprint(s, "tex"), ref);
31
32 // MathML
33 ref = [""
34 "<mfenced open=""("" close="")"">"
35 "<mtable>"
36 "<mtr>"
37 "<mtd><mfenced close="""" open=""{"">"
38 "<mtable columnalign=""right center left"">"
39 "<mtr><mtd><mrow><mover><mi>X</mi><mo>.</mo></mover><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd><mtd><mo>=</mo></mtd><mtd>"
40 "<mfenced open=""("" close="")"">"
41 "<mtable>"
42 "<mtr>"
43 "<mtd><mn>2.02</mn></mtd>"
44 "<mtd><mn>7.14</mn></mtd>"
45 "<mtd><mo>-</mo><mn>8.59</mn></mtd>"
46 "</mtr>"
47 "<mtr>"
48 "<mtd><mo>-</mo><mn>9.99</mn></mtd>"
49 "<mtd><mo>-</mo><mn>9.64</mn></mtd>"
50 "<mtd><mo>-</mo><mn>1.27</mn></mtd>"
51 "</mtr>"
52 "<mtr>"
53 "<mtd><mn>5.59</mn></mtd>"
54 "<mtd><mn>7.25</mn></mtd>"
55 "<mtd><mn>7.44</mn></mtd>"
56 "</mtr>"
57 "</mtable>"
58 "</mfenced>"
59 "<mrow><mi>X</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mo>+</mo>"
60 "<mfenced open=""("" close="")"">"
61 "<mtable>"
62 "<mtr>"
63 "<mtd><mn>4.46</mn></mtd>"
64 "<mtd><mo>-</mo><mn>0.62</mn></mtd>"
65 "</mtr>"
66 "<mtr>"
67 "<mtd><mn>8.42</mn></mtd>"
68 "<mtd><mo>-</mo><mn>3.3</mn></mtd>"
69 "</mtr>"
70 "<mtr>"
71 "<mtd><mo>-</mo><mn>2.67</mn></mtd>"
72 "<mtd><mn>9.04</mn></mtd>"
73 "</mtr>"
74 "</mtable>"
75 "</mfenced>"
76 "<mrow><mi>U</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd></mtr>"
77 "<mtr><mtd><mrow><mi>Y</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd><mtd><mo>=</mo></mtd><mtd>"
78 "<mfenced open=""("" close="")"">"
79 "<mtable>"
80 "<mtr>"
81 "<mtd><mo>-</mo><mn>7.72</mn></mtd>"
82 "<mtd><mn>6.86</mn></mtd>"
83 "<mtd><mo>-</mo><mn>6.75</mn></mtd>"
84 "</mtr>"
85 "<mtr>"
86 "<mtd><mo>-</mo><mn>4.58</mn></mtd>"
87 "<mtd><mo>-</mo><mn>3.59</mn></mtd>"
88 "<mtd><mo>-</mo><mn>8.06</mn></mtd>"
89 "</mtr>"
90 "</mtable>"
91 "</mfenced>"
92 "<mrow><mi>X</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd></mtr>"
93 "</mtable>"
94 "</mfenced>"
95 "</mtd>"
96 "</mtr>"
97 "</mtable>"
98 "</mfenced>"
99 ""];
100 ref = strcat(ref, ascii(10));
101 assert_checkequal(prettyprint(s, "mathml"), ref);
102
103 // Discrete states (and improper syslin):
104 // -------------------------------------
105 s = syslin("d", A, B, C, [1+%s, 1-%s; -%s, %s]);
106 // LaTeX
107 ref = "${\begin{pmatrix}{\left\{\begin{array}{rcl}\stackrel{+}{X}(t)&=&{\begin{pmatrix}2.02&7.14&-8.59\cr -9.99&-9.64&-1.27\cr 5.59&7.25&7.44\cr \end{pmatrix}} X(t)+{\begin{pmatrix}4.46&-0.62\cr 8.42&-3.3\cr -2.67&9.04\cr \end{pmatrix}}U(t)\cr Y(t) &=& {\begin{pmatrix}-7.72&6.86&-6.75\cr -4.58&-3.59&-8.06\cr \end{pmatrix}} X(t)  + {\begin{pmatrix}1+s &1-s \cr -s &s \cr \end{pmatrix}} U(t)\end{array}\right.}\cr \end{pmatrix}}$";
108 assert_checkequal(prettyprint(s, "latex"), ref);
109
110 // TeX
111 ref = "${\pmatrix{{\left\{\eqalign{{\buildrel + \over X(t)} &= {\pmatrix{2.02&7.14&-8.59\cr -9.99&-9.64&-1.27\cr 5.59&7.25&7.44\cr }} X(t)+{\pmatrix{4.46&-0.62\cr 8.42&-3.3\cr -2.67&9.04\cr }}U(t)\cr Y(t) &= {\pmatrix{-7.72&6.86&-6.75\cr -4.58&-3.59&-8.06\cr }} X(t)  + {\pmatrix{1+s &1-s \cr -s &s \cr }} U(t)}\right.}\cr }}$";
112 assert_checkequal(prettyprint(s, "tex"), ref);
113
114 // MathML
115 ref = [""
116 "<mfenced open=""("" close="")"">"
117 "<mtable>"
118 "<mtr>"
119 "<mtd><mfenced close="""" open=""{"">"
120 "<mtable columnalign=""right center left"">"
121 "<mtr><mtd><mrow><mover><mi>X</mi><mo>+</mo></mover><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd><mtd><mo>=</mo></mtd><mtd>"
122 "<mfenced open=""("" close="")"">"
123 "<mtable>"
124 "<mtr>"
125 "<mtd><mn>2.02</mn></mtd>"
126 "<mtd><mn>7.14</mn></mtd>"
127 "<mtd><mo>-</mo><mn>8.59</mn></mtd>"
128 "</mtr>"
129 "<mtr>"
130 "<mtd><mo>-</mo><mn>9.99</mn></mtd>"
131 "<mtd><mo>-</mo><mn>9.64</mn></mtd>"
132 "<mtd><mo>-</mo><mn>1.27</mn></mtd>"
133 "</mtr>"
134 "<mtr>"
135 "<mtd><mn>5.59</mn></mtd>"
136 "<mtd><mn>7.25</mn></mtd>"
137 "<mtd><mn>7.44</mn></mtd>"
138 "</mtr>"
139 "</mtable>"
140 "</mfenced>"
141 "<mrow><mi>X</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mo>+</mo>"
142 "<mfenced open=""("" close="")"">"
143 "<mtable>"
144 "<mtr>"
145 "<mtd><mn>4.46</mn></mtd>"
146 "<mtd><mo>-</mo><mn>0.62</mn></mtd>"
147 "</mtr>"
148 "<mtr>"
149 "<mtd><mn>8.42</mn></mtd>"
150 "<mtd><mo>-</mo><mn>3.3</mn></mtd>"
151 "</mtr>"
152 "<mtr>"
153 "<mtd><mo>-</mo><mn>2.67</mn></mtd>"
154 "<mtd><mn>9.04</mn></mtd>"
155 "</mtr>"
156 "</mtable>"
157 "</mfenced>"
158 "<mrow><mi>U</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd></mtr>"
159 "<mtr><mtd><mrow><mi>Y</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd><mtd><mo>=</mo></mtd><mtd>"
160 "<mfenced open=""("" close="")"">"
161 "<mtable>"
162 "<mtr>"
163 "<mtd><mo>-</mo><mn>7.72</mn></mtd>"
164 "<mtd><mn>6.86</mn></mtd>"
165 "<mtd><mo>-</mo><mn>6.75</mn></mtd>"
166 "</mtr>"
167 "<mtr>"
168 "<mtd><mo>-</mo><mn>4.58</mn></mtd>"
169 "<mtd><mo>-</mo><mn>3.59</mn></mtd>"
170 "<mtd><mo>-</mo><mn>8.06</mn></mtd>"
171 "</mtr>"
172 "</mtable>"
173 "</mfenced>"
174 "<mrow><mi>X</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow><mo>+</mo>"
175 "<mfenced open=""("" close="")"">"
176 "<mtable>"
177 "<mtr>"
178 "<mtd><mn>1</mn><mo>+</mo><mi>s</mi></mtd>"
179 "<mtd><mn>1</mn><mo>-</mo><mi>s</mi></mtd>"
180 "</mtr>"
181 "<mtr>"
182 "<mtd><mo>-</mo><mi>s</mi></mtd>"
183 "<mtd><mi>s</mi></mtd>"
184 "</mtr>"
185 "</mtable>"
186 "</mfenced>"
187 "<mrow><mi>U</mi><mo>(</mo><mi>t</mi><mo>)</mo></mrow></mtd></mtr>"
188 "</mtable>"
189 "</mfenced>"
190 "</mtd>"
191 "</mtr>"
192 "</mtable>"
193 "</mfenced>"
194 ""];
195 ref = strcat(ref, ascii(10));
196 assert_checkequal(prettyprint(s, "mathml"), ref);