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 GRAPHIC -->
9// unit test for typeof()
10
11// constant
12assert_checkequal(typeof(1),"constant");
13assert_checkequal(typeof([1,1]),"constant");
14assert_checkequal(typeof([1;1]),"constant");
15assert_checkequal(typeof([1,1;1,1]),"constant");
16assert_checkequal(typeof([1+%i,1+%i;1,1]),"constant");
17
18// polynomial
19assert_checkequal(typeof(poly(0,"s")),"polynomial");
20
21// boolean
22assert_checkequal(typeof(%t),"boolean");
23assert_checkequal(typeof([%t,%t;%f,%f]),"boolean");
24assert_checkequal(typeof("s"=="s"),"boolean");
25
26// sparse
27assert_checkequal(typeof(sparse([0,1,0,1:1,0,1,0])),"sparse");
28
29// boolean sparse
30assert_checkequal(typeof(sparse([1,1;2,2;3,3],[%t,%t,%t])),"boolean sparse");
31
32// int
33assert_checkequal(typeof(int8(1:4)),"int8");
34assert_checkequal(typeof(uint8(1:4)),"uint8");
35assert_checkequal(typeof(int16(1:4)),"int16");
36assert_checkequal(typeof(uint16(1:4)),"uint16");
37assert_checkequal(typeof(int32(1:4)),"int32");
38assert_checkequal(typeof(uint32(1:4)),"uint32");
39format("e");
40assert_checkequal(typeof(uint8(1:4)),"uint8"); // bug 8687
41format("v");
42
43// handle
44plot();
45f=gcf();
46assert_checkequal(typeof(f),"handle");
47a=gca();
48assert_checkequal(typeof(a),"handle");
49e=gce();
50assert_checkequal(typeof(e),"handle");
51assert_checkequal(typeof(a.children(1)),"handle");
52close
53
54// string
55assert_checkequal(typeof("s"),"string");
56assert_checkequal(typeof("string"),"string");
57assert_checkequal(typeof(["s","s"]),"string");
58
59// function
60deff("[x]=myplus(y,z)","x=y+z");
61assert_checkequal(typeof(myplus),"function");
62
63// library
64assert_checkequal(typeof(elementary_functionslib),"library");
65assert_checkequal(typeof(corelib),"library");
66
67// pointer
68a=rand(5,5);b=rand(5,1);A=sparse(a);
69[h,rk]=lufact(A);
70x=lusolve(h,b);a*x-b;
71ludel(h);
72assert_checkequal(typeof(h),"pointer");
73
74// size implicit
75assert_checkequal(typeof(1:1:$), "implicitlist");
76
77// list
78assert_checkequal(typeof(list(1,2)),"list");
79t = tlist(["listtype","field1","field2"], [], []);
80assert_checkequal(typeof(t),t(1)(1));
81M = mlist(["V","name","value"],["a","b","c"],[1 2 3]);
82M1=getfield(1,M);
83assert_checkequal(typeof(M),M1(1));
84
85// rational, state-space, uitree
86assert_checkequal(typeof(1/poly(0,"s")),"rational");
87A=[0,1;0,0];B=[1;1];C=[1,1];
88S1=syslin("c",A,B,C);
89assert_checkequal(typeof(S1),"state-space");
90S2=syslin("d",A,B,C);
91assert_checkequal(typeof(S2),"state-space");
92S3=syslin(1,A,B,C);
93assert_checkequal(typeof(S3),"state-space");
94assert_checkequal(typeof(tf2ss(1/poly(0,"s"))),"state-space");
95l1 = uiCreateNode("CONST_m","default","");
96assert_checkequal(typeof(l1),"uitree");
97tree = uiCreateTree(l1);
98assert_checkequal(typeof(tree),"uitree");
99
100// hypermat
101assert_checkequal(typeof(matrix(1:24, [2 3 2 2])),"constant");
102A=[1,2,3;4,5,6];
103A(:,:,2)=[1,2,3;4,5,6];
104assert_checkequal(typeof(string(A)),"string");
105
106// fptr
107assert_checkequal(typeof(abs),"fptr");
108
109// cell
110assert_checkequal(typeof(cell(3)),"ce");
111
112//structure
113assert_checkequal(typeof(struct("jour",25,"mois","DEC","annee",2006)),"st");
114