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