CLI SHELL MODE only test
[scilab.git] / scilab / modules / hdf5 / tests / unit_tests / loadhdf5data.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2011 - DIGITEO - Sylvestre LEDRU
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9
10 // Load previously saved data (check backward compatibility)
11
12
13 ///// Empty matrix
14 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/emptymatrix.sod");
15 assert_checkequal(emptymatrix, []);
16
17 ///// Double
18 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedoublescalar.sod");
19 assert_checkequal(ascalar,42);
20
21 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedouble.sod");
22 assert_checkequal(a,[2,3;4,5]);
23
24
25 ///// Double complex
26 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedoublecomplex.sod");
27 assert_checkequal(b,[2+%i,3+%i*2;4+%i*%pi,5]);
28
29 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricedoublecomplexscalar.sod");
30 assert_checkequal(bscalar,42+%i);
31
32
33 ///// String
34 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricestring.sod");
35 assert_checkequal(c,["my matrix","of strings";"is","saved in Scilab data format"]);
36   
37 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/matricestringscalar.sod");
38 assert_checkequal(cscalar,["my single string"]);
39
40 // Polynomials
41 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/polynomials.sod");
42 p_reference=poly([1 2],'s') ;
43 assert_checkequal(p,p_reference);
44
45 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/polynomialscoef.sod");
46 q_reference=poly([1 42],'s','c');
47 assert_checkequal(q,q_reference);
48
49
50 // Boolean matrices
51 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/booleanscalar.sod");
52 assert_checkequal(bm,%t);
53 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/booleanmatrix.sod");
54 assert_checkequal(bmm,[%t,%f; %f, %t]);
55
56 // Sparse
57 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/sparsematrix.sod");
58 assert_checkequal(sp,sparse([1,2;4,5;3,10],[1,2,3]));
59
60 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/emptysparse.sod");
61 assert_checkequal(emptysparse,sparse([]));
62
63 // boolean sparse
64 dense=[%F, %F, %T, %F, %F
65 %T, %F, %F, %F, %F
66 %F, %F, %F, %F, %F
67 %F, %F, %F, %F, %T];
68 sp_reference=sparse(dense);
69 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/booleansparse.sod");
70 assert_checkequal(sp,sp_reference);
71
72 // List
73 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/list.sod");
74 assert_checkequal(ls,list(2,%i,'f',ones(3,3)));
75 ls(2) =  list( %t, [32,42]); // alter ls to add the list
76 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/listnested.sod");
77 assert_checkequal(lsnested,ls);
78
79 // tlist
80 lst_reference  =  tlist(['random numbers';'Name';'Example'], 'Uniform',ones(1,2, 3));
81 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/tlist.sod");
82 assert_checkequal(lst,lst_reference);
83
84 // mlist
85 M_ref=mlist(['V','name','value'],['a','b';'c' 'd'],[1 2; 3 4]);
86 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/mlist.sod");
87 // Commented because of bug 9531
88 //assert_checkequal(M_ref,M);
89
90 // hypermatrices
91 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/hypermatrix.sod");
92 assert_checkequal(HM,hypermat([2 3 2 2],1:24));
93
94 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/hypermatrixcomplex.sod");
95 HMC_reference(1,1,1,1:2)=[1+%i 2*2*%i];
96 assert_checkequal(HMC,HMC_reference);
97
98 // int
99
100 emptyint8matrix_ref = int8([]);
101 int8scalar_ref = int8(1);
102 int8rowvector_ref = int8([1 -4 7]);
103 int8colvector_ref = int8([1;-4;7]);
104 int8matrix_ref = int8([1 -4 7;-9 6 -3]);
105 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/int8.sod");
106 assert_checkequal(emptyint8matrix, emptyint8matrix_ref);
107 assert_checkequal(int8scalar, int8scalar_ref);
108 assert_checkequal(int8rowvector, int8rowvector_ref);
109 assert_checkequal(int8colvector, int8colvector_ref);
110 assert_checkequal(int8matrix, int8matrix_ref);
111
112
113 emptyint16matrix_ref = int16([]);
114 int16scalar_ref = int16(1);
115 int16rowvector_ref = int16([1 -4 7]);
116 int16colvector_ref = int16([1;-4;7]);
117 int16matrix_ref = int16([1 -4 7;-9 6 -3]);
118 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/int16.sod");
119 assert_checkequal(emptyint16matrix, emptyint16matrix_ref);
120 assert_checkequal(int16scalar, int16scalar_ref);
121 assert_checkequal(int16rowvector, int16rowvector_ref);
122 assert_checkequal(int16colvector, int16colvector_ref);
123 assert_checkequal(int16matrix, int16matrix_ref);
124
125
126 emptyint32matrix_ref = int32([]);
127 int32scalar_ref = int32(1);
128 int32rowvector_ref = int32([1 -4 7]);
129 int32colvector_ref = int32([1;-4;7]);
130 int32matrix_ref = int32([1 -4 7;-9 6 -3]);
131 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/int32.sod");
132 assert_checkequal(emptyint32matrix, emptyint32matrix_ref);
133 assert_checkequal(int32scalar, int32scalar_ref);
134 assert_checkequal(int32rowvector, int32rowvector_ref);
135 assert_checkequal(int32colvector, int32colvector_ref);
136 assert_checkequal(int32matrix, int32matrix_ref);
137
138
139 emptyuint8matrix_ref = uint8([]);
140 uint8scalar_ref = uint8(1);
141 uint8rowvector_ref = uint8([1 4 7]);
142 uint8colvector_ref = uint8([1;4;7]);
143 uint8matrix_ref = uint8([1 4 7;9 6 3]);
144 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/uint8.sod");
145 assert_checkequal(emptyuint8matrix, emptyuint8matrix_ref);
146 assert_checkequal(uint8scalar, uint8scalar_ref);
147 assert_checkequal(uint8rowvector, uint8rowvector_ref);
148 assert_checkequal(uint8colvector, uint8colvector_ref);
149 assert_checkequal(uint8matrix, uint8matrix_ref);
150
151
152 emptyuint16matrix_ref = uint16([]);
153 uint16scalar_ref = uint16(1);
154 uint16rowvector_ref = uint16([1 4 7]);
155 uint16colvector_ref = uint16([1;4;7]);
156 uint16matrix_ref = uint16([1 4 7;9 6 3]);
157 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/uint16.sod");
158 assert_checkequal(emptyuint16matrix, emptyuint16matrix_ref);
159 assert_checkequal(uint16scalar, uint16scalar_ref);
160 assert_checkequal(uint16rowvector, uint16rowvector_ref);
161 assert_checkequal(uint16colvector, uint16colvector_ref);
162 assert_checkequal(uint16matrix, uint16matrix_ref);
163
164
165 emptyuint32matrix_ref = uint32([]);
166 uint32scalar_ref = uint32(1);
167 uint32rowvector_ref = uint32([1 4 7]);
168 uint32colvector_ref = uint32([1;4;7]);
169 uint32matrix_ref = uint32([1 4 7;9 6 3]);
170 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/uint32.sod");
171 assert_checkequal(emptyuint32matrix, emptyuint32matrix_ref);
172 assert_checkequal(uint32scalar, uint32scalar_ref);
173 assert_checkequal(uint32rowvector, uint32rowvector_ref);
174 assert_checkequal(uint32colvector, uint32colvector_ref);
175 assert_checkequal(uint32matrix, uint32matrix_ref);
176
177
178 // undefined
179 undefinedelement_ref=list(2,%i,'f',ones(3,3));
180 undefinedelement_ref(6)="toto";
181 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/undefinedelement.sod");
182 assert_checkequal(undefinedelement, undefinedelement_ref);
183
184
185 // void
186 voidelement_ref=list(1,,3);
187 import_from_hdf5(SCI+"/modules/hdf5/tests/sample_scilab_data/voidelement.sod");
188 // Commented because of bug 9529
189 //assert_checkequal(voidelement, voidelement_ref);
190