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