* Bug #8687 fixed - typeof() function failed on uint8, depending on the format (...
[scilab.git] / scilab / modules / core / tests / unit_tests / typeof.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 //
8 // <-- TEST WITH GRAPHICS -->
9 // unit test for typeof()
10
11 // constant
12 assert_checkequal(typeof(1),"constant");
13 assert_checkequal(typeof([1,1]),"constant");
14 assert_checkequal(typeof([1;1]),"constant");
15 assert_checkequal(typeof([1,1;1,1]),"constant");
16 assert_checkequal(typeof([1+%i,1+%i;1,1]),"constant");
17
18 // polynomial
19 assert_checkequal(typeof(poly(0,"s")),"polynomial");
20
21 // boolean
22 assert_checkequal(typeof(%t),"boolean");
23 assert_checkequal(typeof([%t,%t;%f,%f]),"boolean");
24 assert_checkequal(typeof("s"=="s"),"boolean");
25
26 // sparse
27 assert_checkequal(typeof(sparse([0,1,0,1:1,0,1,0])),"sparse");
28
29 // boolean sparse
30 assert_checkequal(typeof(sparse([1,1;2,2;3,3],[%t,%t,%t])),"boolean sparse");
31
32 // Matlab sparse
33 X=sparse(rand(2,2)); Y=mtlb_sparse(X);
34 assert_checkequal(typeof(Y),"Matlab sparse");
35
36 // int
37 assert_checkequal(typeof(int8(1:4)),"int8");
38 assert_checkequal(typeof(uint8(1:4)),"uint8");
39 assert_checkequal(typeof(int16(1:4)),"int16");
40 assert_checkequal(typeof(uint16(1:4)),"uint16");
41 assert_checkequal(typeof(int32(1:4)),"int32");
42 assert_checkequal(typeof(uint32(1:4)),"uint32");
43 format("e");
44 assert_checkequal(typeof(uint8(1:4)),"uint8"); // bug 8687
45 format("v");
46
47 // handle
48 plot();
49 f=gcf();
50 assert_checkequal(typeof(f),"handle");
51 a=gca();
52 assert_checkequal(typeof(a),"handle");
53 e=gce();
54 assert_checkequal(typeof(e),"handle");
55 assert_checkequal(typeof(a.children(1)),"handle");
56 close
57
58 // string
59 assert_checkequal(typeof("s"),"string");
60 assert_checkequal(typeof("string"),"string");
61 assert_checkequal(typeof(["s","s"]),"string");
62
63 // function
64 deff('[x]=myplus(y,z)','x=y+z');
65 assert_checkequal(typeof(myplus),"function");
66
67 // library
68 assert_checkequal(typeof(elementary_functionslib),"library");
69 assert_checkequal(typeof(corelib),"library");
70
71 // pointer
72 a=rand(5,5);b=rand(5,1);A=sparse(a);
73 [h,rk]=lufact(A);
74 x=lusolve(h,b);a*x-b;
75 ludel(h);
76 assert_checkequal(typeof(h),"pointer");
77
78 // size implicit
79 assert_checkequal(typeof(1:1:$), "size implicit");
80
81 // list
82 assert_checkequal(typeof(list(1,2)),"list");
83 t = tlist(["listtype","field1","field2"], [], []);
84 assert_checkequal(typeof(t),t(1)(1));
85 M = mlist(['V','name','value'],['a','b','c'],[1 2 3]);
86 M1=getfield(1,M);
87 assert_checkequal(typeof(M),M1(1));
88
89 // rational, state-space
90 assert_checkequal(typeof(1/poly(0,"s")),"rational");
91 A=[0,1;0,0];B=[1;1];C=[1,1];
92 S1=syslin('c',A,B,C);
93 assert_checkequal(typeof(S1),"state-space");
94 S2=syslin('d',A,B,C);
95 assert_checkequal(typeof(S2),"state-space");
96 S3=syslin(1,A,B,C);
97 assert_checkequal(typeof(S3),"state-space");
98 assert_checkequal(typeof(tf2ss(1/poly(0,"s"))),"state-space");
99
100 // hypermat
101 assert_checkequal(typeof(hypermat([2 3 2 2],1:24)),"hypermat");
102 A=[1,2,3;4,5,6];
103 A(:,:,2)=[1,2,3;4,5,6];
104 assert_checkequal(typeof(A),"hypermat");
105
106 // fptr
107 assert_checkequal(typeof(abs),"fptr");
108
109 // cell
110 assert_checkequal(typeof(cell(3)),"ce");
111
112 //structure
113 assert_checkequal(typeof(struct('jour',25,'mois','DEC','annee',2006)),"st");