Scicos src: comment out Structs in var2vec
[scilab.git] / scilab / modules / scicos / tests / unit_tests / var2vec.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
4 // Copyright (C) ????-2008 - INRIA
5 //
6 //  This file is distributed under the same license as the Scilab package.
7 // =============================================================================
8
9 // <-- CLI SHELL MODE -->
10
11 a = list("cos", [1.1 2]);
12 b = var2vec(a);
13 assert_checkequal(type(b), 1);
14 assert_checkequal(size(b), [15 1]);
15
16 // Double
17 a = [];
18 assert_checkequal(var2vec(a), [12; 2; 0; 0; 0]);
19 Mat = [10 11 12 13; 14 15 16 17];
20 assert_checkequal(var2vec(Mat), [12; 2; 2; 4; 0; 10; 14; 11; 15; 12; 16; 13; 17]);
21 HyperMat = hypermat([2, 2, 2], 1:8);
22 assert_checkequal(var2vec(HyperMat), [12; 3; 2; 2; 2; 0; (1:8)']);
23 cplx = HyperMat+HyperMat*%i;
24 assert_checkequal(var2vec(cplx), [12; 3; 2; 2; 2; 1; (1:8)'; (1:8)']);
25
26 // Integers
27 // int8
28 Mat8 = int8(Mat);
29 assert_checkequal(vec2var(var2vec(Mat8)), Mat8);
30 HyperMat8 = int8(HyperMat);
31 assert_checkequal(vec2var(var2vec(HyperMat8)), HyperMat8);
32 // uint8
33 uMat8 = uint8(Mat);
34 assert_checkequal(vec2var(var2vec(uMat8)), uMat8);
35 uHyperMat8 = uint8(HyperMat);
36 assert_checkequal(vec2var(var2vec(uHyperMat8)), uHyperMat8);
37 // int16
38 Mat16 = int16(Mat);
39 assert_checkequal(vec2var(var2vec(Mat16)), Mat16);
40 HyperMat16 = int16(HyperMat);
41 assert_checkequal(vec2var(var2vec(HyperMat16)), HyperMat16);
42 // uint16
43 uMat16 = uint16(Mat);
44 assert_checkequal(vec2var(var2vec(uMat16)), uMat16);
45 uHyperMat16 = uint16(HyperMat);
46 assert_checkequal(vec2var(var2vec(uHyperMat16)), uHyperMat16);
47 // int32
48 Mat32 = int32(Mat);
49 assert_checkequal(vec2var(var2vec(Mat32)), Mat32);
50 HyperMat32 = int32(HyperMat);
51 assert_checkequal(vec2var(var2vec(HyperMat32)), HyperMat32);
52 // uint32
53 uMat32 = uint32(Mat);
54 assert_checkequal(vec2var(var2vec(uMat32)), uMat32);
55 uHyperMat32 = uint32(HyperMat);
56 assert_checkequal(vec2var(var2vec(uHyperMat32)), uHyperMat32);
57
58 // Bool
59 bMat = (Mat>15);
60 assert_checkequal(vec2var(var2vec(bMat)), bMat);
61 bHyperMat = (HyperMat>4);
62 assert_checkequal(vec2var(var2vec(bHyperMat)), bHyperMat);
63
64 // String
65 sMat = string(Mat);
66 assert_checkequal(vec2var(var2vec(sMat)), sMat);
67 sHyperMat = string(HyperMat);
68 assert_checkequal(vec2var(var2vec(sHyperMat)), sHyperMat);
69
70 // List
71 // Double
72 l = list();
73 assert_checkequal(vec2var(var2vec(l)), l);
74 lEmpties = list([], "", [], "");
75 assert_checkequal(vec2var(var2vec(lEmpties)), lEmpties);
76 lMat = list(Mat);
77 assert_checkequal(vec2var(var2vec(lMat)), lMat);
78 lHyperMat = list(HyperMat);
79 assert_checkequal(vec2var(var2vec(lHyperMat)), lHyperMat);
80 // Integer
81 lMat8 = list(int8(Mat));
82 assert_checkequal(vec2var(var2vec(lMat8)), lMat8);
83 lHyperMat8 = list(int8(HyperMat));
84 assert_checkequal(vec2var(var2vec(lHyperMat8)), lHyperMat8);
85 // Bool
86 lbMat = list(Mat>15);
87 assert_checkequal(vec2var(var2vec(lbMat)), lbMat);
88 lbHyperMat = list(HyperMat>4);
89 assert_checkequal(vec2var(var2vec(lbHyperMat)), lbHyperMat);
90 // String
91 lsMat = list(string(Mat));
92 assert_checkequal(vec2var(var2vec(lsMat)), lsMat);
93 lsHyperMat = list(string(HyperMat));
94 assert_checkequal(vec2var(var2vec(lsHyperMat)), lsHyperMat);
95
96 // TList
97 tl = tlist("");
98 assert_checkequal(vec2var(var2vec(tl)), tl);
99 tlEmpties = tlist(["Type" "f1" "f2" "f3" "f4" "f5", "f6"]);
100 assert_checkequal(vec2var(var2vec(tlEmpties)), tlEmpties);
101 tlMixed = tlist(["Type" "f1" "f2" "f3" "f4" "f5", "f6"], [], Mat, HyperMat, int32(Mat), string(Mat), Mat>15);
102 assert_checkequal(vec2var(var2vec(tlMixed)), tlMixed);
103
104 // MList
105 ml = mlist("");
106 assert_checkequal(vec2var(var2vec(ml)), ml);
107 mlEmpties = mlist(["Type" "f1" "f2" "f3" "f4" "f5", "f6"]);
108 assert_checkequal(vec2var(var2vec(mlEmpties)), mlEmpties);
109 mlMixed = mlist(["Type" "f1" "f2" "f3" "f4" "f5", "f6"], [], Mat, HyperMat, int32(Mat), string(Mat), Mat>15);
110 assert_checkequal(vec2var(var2vec(mlMixed)), mlMixed);
111
112 // Struct
113 //st = struct();
114 //assert_checkequal(vec2var(var2vec(st)), st);
115 //stFull = struct("f1", [], "f2", Mat, "f3", HyperMat, "f4", int32(Mat), "f5", string(Mat), "f6", Mat>15);
116 //assert_checkequal(vec2var(var2vec(stFull)), stFull);
117
118 // List containing a full TList, taken from PDE.sci
119 params_pde = tlist(["paramspde";"a";"b";"txt_exp";"check_op1";"a1";"b1";"check_op2";"a2";"b2";..
120 "check_op3";"a3";"b3";"check_op4";"a4";"b4";"check_op5";"a5";"b5";"check_op6";"a6";"b6";..
121 "check_op7";"a7";"b7";"discr_cst";"discr_non_cst";"signe";"rad_automatique";"rad_manuel";..
122 "methode";"ord1";"ord2";"ord3";"degre";"nnode";"txt_pas";"CI";"dCI";"CLa";"CLa_exp";"CLb";..
123 "CLb_exp";"points"],"","","","0","","IN_EDP1(t)","0","","IN_EDP2(t)","0","","IN_EDP3(t)",..
124 "0","","IN_EDP4(t)","0","","IN_EDP5(t)","0","","IN_EDP6(t)","0","","IN_EDP7(t)","0","0",..
125 "0","0","0","0","","","","","","","","","0","IN_CL1(t)","0","IN_CL2(t)","");
126 label = list(params_pde, [], "");
127 assert_checkequal(vec2var(var2vec(params_pde)), params_pde);
128 assert_checkequal(vec2var(var2vec(label)), label);
129
130 // TList containing a List, taken from MBLOCK.sci
131 in = ["u1"];
132 intype = ["I"];
133 out = ["y1";"y2"];
134 outtype = ["I";"E"];
135 param = ["R";"L"];
136 paramv = list(0.1,.0001);
137 pprop = [0;0];
138 nameF = "generic";
139 exprs = tlist(["MBLOCK","in","intype","out","outtype",...
140 "param","paramv","pprop","nameF","funtxt"],...
141 sci2exp(in(:)),..
142 sci2exp(intype(:)),..
143 sci2exp(out(:)),..
144 sci2exp(outtype(:)),..
145 sci2exp(param(:)),..
146 list(string(0.1),string(.0001)),...
147 sci2exp(pprop(:)),..
148 nameF,[]);
149 assert_checkequal(vec2var(var2vec(exprs)), exprs);
150
151 // List containing a Struct
152 //lStFull = list(stFull, [], stFull, "test");
153 //assert_checkequal(vec2var(var2vec(lStFull)), lStFull);
154
155 // corner-cases
156 a = var2vec(tlist(["" ""],list()));
157 vec2var(a);
158
159 //a = var2vec(struct("toto", list(struct("titi", 12))));
160 //vec2var(a);
161