File: function.tst

package info (click to toggle)
scilab 5.3.3-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 330,656 kB
file content (276 lines) | stat: -rw-r--r-- 4,579 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// =============================================================================
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ????-2008 - INRIA
//
//  This file is distributed under the same license as the Scilab package.
// =============================================================================

//Checks syntactical aspects  related to functions
funcprot(0)
//
//               Various calling sequences
//               -------------------------
function y=foo(x)
 y=x^2
endfunction
if foo(2)<>4  then pause,end
//
function y=foo(a,b)
 y=a+b
endfunction
if foo(2,3)<>5  then pause,end
//
function [y,z]=foo(a)
 y=a^2
 z=a^3
endfunction
[y,z]=foo(2);if y<>4|z<>8 then pause,end
//
function y=foo()
 y=2
endfunction
if foo()<>2  then pause,end
//
function y=foo
 y=2
endfunction
if foo()<>2  then pause,end
//
function []=foo
 y=resume(2)
endfunction
foo();if y<>2  then pause,end
//
function foo
 y=resume(3)
endfunction
foo();if y<>3  then pause,end

//
//               Various line splits
//               -------------------
function y=foo(x),y=x^2
endfunction
if foo(2)<>4  then pause,end
//
function y=foo(x),y=3*x,endfunction
if foo(2)<>6  then pause,end
//
function y=foo(x)
  z=x^2
  function y=foo1(x)
    y=x+1
  endfunction
  y=foo1(z)
endfunction
if foo(2)<>5  then pause,end 
//
//               Combined with deff
//               -------------------
function y=foo(x)
  z=x^2
  deff('y=foo1(x)','y=x+1')
  y=foo1(z)
endfunction
if foo(2)<>5  then pause,end 
//  
deff('y=foo(x)',[
    'z=x^2'
    'function y=foo1(x)'
    'y=x+1'
    'endfunction'
    'y=foo1(z)'])
if foo(2)<>5  then pause,end 
		 
function y=foo(x),y=x+1
endfunction;if foo(2)<>3  then pause,end
//
//               Combined with exec
//               -------------------
function foo
  z=9;
  function y=foo1(x)
    y=x+1;
  endfunction
  y=foo1(z);
endfunction
exec(foo); if y<>10  then pause,end 
//  

//               Combined with control instructions
//               ----------------------------------
if %t then
  function  y=foo(x)
    y=sin(x)
  endfunction
else
  function  y=foo(x)
    y=1
  endfunction
end
if foo(1)<>sin(1)  then pause,end
//
if %t then
  function  y=foo(x)
  if x==0 then
    y=1
  else
    y=sin(x)/x
  end
  endfunction
else
  function  y=foo(x)
    y=1
  endfunction
end
if foo(0)<>1   then pause,end
if foo(2)<>sin(2)/2   then pause,end
//
z=0;
for k=1:2
 function y=foo()
   y=k
 endfunction
 z=z+foo();
end
if z<>3 then pause,end

//
z=0;for k=1:2
 function y=foo(),y=k,endfunction
 z=z+foo();
end
if z<>3 then pause,end
//
z=0;for k=1:2, function y=foo(),y=k,endfunction
 z=z+foo();
end
if z<>3 then pause,end


z=0;
for k=1:2
 function y=foo(k)//qsdsdf
   y=k^2
 endfunction
 z=z+foo();
end
if z<>5 then pause,end

z=0;
for k=1:2
 function y=foo(k)//qsdsdf
   y=k^2 //a comment
 endfunction
 z=z+foo();
end
if z<>5 then pause,end

z=0;
for k=1:2
 function y=foo(k), y=k^2, endfunction
 z=z+foo();
end
if z<>5 then pause,end


z=0;
for k=1:2
 function y=foo(k), y=k^2, endfunction// a comment
 z=z+foo();
end
if z<>5 then pause,end

//bug 1024 non regression test
O=[];
for n= 1:10;
  Fx=rand(1,100);
  Fy=1:100;
  function [f,g,ind]=cout(x,ind)
    f1=(1-exp(-x*Fx) - Fy);
    f= (1/2)*f1*f1';
    g= x*(Fx.*exp(-x*Fx))*f1';
  endfunction
  [fopt,lmopt]=optim(cout,0.4);
  O=[O fopt];
end
if size(O,'*')<>10 then pause,end

// test line count in compiled macros
// 
function a=foo(),a=1,endfunction
L=macr2lst(foo);
if L(4)(1)<>'6' then pause,end

clear foo
function a=foo()
a=1,
endfunction
L=macr2lst(foo);
if L(4)(1)<>'15' then pause,end

clear foo
function a=foo()//xxcxcx
a=1,
endfunction
L=macr2lst(foo);
if L(4)(1)<>'31' then pause,end

clear foo
function a=foo(),
a=1,
endfunction
L=macr2lst(foo);
if L(4)(1)<>'15' then pause,end

clear foo
function a=foo(),a=1//xxcxcx
b=2
endfunction
L=macr2lst(foo);
if L(4)(1)<>'6' then pause,end


clear foo
function a=foo()
a=..
sin..
(..
1..
),
endfunction
//continuation lines are replaced by a sequence of empty lines followed by the logical line
//so the function above is  the same as
function a=foo1()




a=sin(1),
endfunction

L=macr2lst(foo);
t=L(9)(1)<>'6';
for k=4:8,t=t|L(k)(1)<>'15';end
if t then pause,end
if foo<>foo1 then pause,end


clear foo foo1
function a=foo(),a=..
sin..
(..
1..
),
endfunction
//continuation lines are replaced by a sequence of empty lines followed by the logical line
//foo shoud be equal to foo1
function a=foo1(),a=sin(1),
endfunction

L=macr2lst(foo);
if L(4)(1)<>'6'  then pause,end
if foo<>foo1 then pause,end