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