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