File: testexamples.sci

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (268 lines) | stat: -rw-r--r-- 7,684 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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2005-2008 - INRIA - Serge STEER <serge.steer@inria.fr>
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function r=load_ref(name)
	if exists(name)==0 then r=%f;return,end
	v=evstr(name)
	if type(v) == 9 then   v = ghdl2tree(v);end,
	if type(v) == 128 then v=128,end //lu handle
	load(%U,name+'_ref');
	if exists(name+'_ref')==0 then
		disp(msprintf(gettext("No variable %s_ref in reference file"),name))
		r=%t
		return
	end
	execstr('r=%CMP(v,'+name+'_ref);')
endfunction

function r=load_ref_nocheck(name)
	
	if exists(name)==0 then r=%f;return,end
	v=evstr(name)
	if type(v) == 9 then   v = ghdl2tree(v);end,
	if type(v) == 128 then v=128,end //lu handle
	load(%U,name+'_ref');
	if exists(name+'_ref')==0 then
		disp(msprintf(gettext("No variable %s_ref in reference file"),name))
		r=%t
		return
	end
	r=%f
	
endfunction



function reinit_for_test()
	
	//reinitialize some Scilab state to be able to reproduce the same tests
	sdf();sda()
	xdel(winsid())
	grand('setgen','clcg4');grand('setall',11111111,22222222,33333333,44444444);
	grand('setgen','kiss');grand('setsd',362436069,521288629,123456789,380116160);
	grand('setgen','clcg2');grand('setsd',1234567890,123456789);
	grand('setgen','urand');grand('setsd',0);
	grand('setgen','fsultra');grand('setsd',1234567,7654321);
	grand('setgen','mt');grand('setsd',5489);
	rand('seed',0);
	format('v',10);
	clearglobal()
	
endfunction



function r=xdel_run(w,opt)

	//Author : Serge Steer, april 2005, Copyright INRIA
	//
	//Compare the graphic windows to be cleared with the reference given in a Scilab  binary file. 
	// This function must mirror the  xdel_build one.
	
	r=%f
	if winsid()==[] then return,end
	cur=xget('window')
	//  
	if argn(2)==1 then
		ids_=[]
		for k=1:size(w,'*')
			xset('window',w(k))
			if get('figure_style')=='new' then ids_=[ids_,w(k)],end
		end
		load(%U,'ids_ref')
		if or(ids_ref<>ids_) then r=%t,return,end
		for k=ids_ref
			%wins_=ghdl2tree(scf(k));
			load(%U,'%wins_ref');
			if %CMP(%wins_, %wins_ref) then r=%t,return,end
		end
		xdel(w)
	else
		if get('figure_style')=='old' then return,end
		ids_=xget('window')
		load(%U,'ids_ref')
		if or(ids_ref<>ids_) then r=%t,return,end
		%wins_=ghdl2tree(gcf());
		load(%U,'%wins_ref');
		if %CMP(%wins_,%wins_ref) then r=%t,return,end
		xdel()
	end
	if or(winsid()==cur) then xset('window',cur),end
	
endfunction



function r=clf_run(w,opt)

	//Author : Serge Steer, april 2005, Copyright INRIA
	//
	//Compare the graphic windows to be cleared with the reference given in  a Scilab  binary file. 
	// This function must mirror the  clf_build one.
	
	r=%f
	if winsid()==[] then return,end
	cur=xget('window')
	rhs=argn(2)
	if rhs==1&type(w)==10 then opt=w;rhs=0,end
	if winsid()==[] then return,end
	//
	if rhs==1 then
		ids_=[]
		if type(w)==9 then 
			H=w;w=[]
			for h=H,w=[w,h.figure_id],end
		end
		for k=1:size(w,'*')
			xset('window',w(k))
			if get('figure_style')=='new' then ids_=[ids_,w(k)],end
		end
		load(%U,'ids_ref')
		if or(ids_ref<>ids_) then r=%t,return,end
		for k=ids_ref
			%wins_=ghdl2tree(scf(k));
			load(%U,'%wins_ref');
			if %CMP(%wins_, %wins_ref) then r=%t,return,end
		end
		if rhs==1 then clf(w),else clf(w,opt),end
	else
		if get('figure_style')=='old' then return,end
		ids_=xget('window')
		load(%U,'ids_ref')
		if or(ids_ref<>ids_) then r=%t,return,end
		%wins_=ghdl2tree(gcf());
		load(%U,'%wins_ref');
		if %CMP(%wins_,%wins_ref) then r=%t,return,end
		clf()
	end
	if or(winsid()==cur) then xset('window',cur),end
	
endfunction



function r=xbasc_run(w)

//Author : Serge Steer, april 2005, Copyright INRIA
//
//Compare the graphic windows to be cleared with the reference given in  a Scilab  binary file. 
// This function must mirror the  xbasc_build one.
  r=%f
  if winsid()==[] then return,end
  cur=xget('window')
  //
  if argn(2)==1 then
    ids_=[]
    for k=1:size(w,'*')
      xset('window',w(k))
      if get('figure_style')=='new' then ids_=[ids_,w(k)],end
    end
    load(%U,'ids_ref')
    if or(ids_ref<>ids_) then r=%t,return,end
    for k=ids_ref
      %wins_=ghdl2tree(scf(k));
      load(%U,'%wins_ref');
      %wins_ref.figure_position=%wins_.figure_position
      if %CMP(%wins_, %wins_ref) then r=%t,return,end
    end

    clf(w)
  else
    if get('figure_style')=='old' then return,end
    ids_=xget('window');
    load(%U,'ids_ref')
    if or(ids_ref<>ids_) then r=%t,return,end
    %wins_=ghdl2tree(gcf());
    load(%U,'%wins_ref');
    %wins_ref.figure_position=%wins_.figure_position
    if %CMP(%wins_, %wins_ref) then r=%t,return,end
    clf()
  end
  if or(winsid()==cur) then xset('window',cur),end
  
endfunction



function r=%CMP(%A,%B)

//Author : Serge Steer, april 2005, Copyright INRIA
//
// this function compares two variables, floating points data are
// compared using a relative tolerance

  r=%f
  tol=0.00001
  if type(%A)<>type(%B) then r=%t,return,end
  select type(%A)
  case 1 then //float
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    %ka=~isnan(%A);%kb=~isnan(%B);
    if or(%ka<>%kb)  then  r=%t,return,end
    if isreal(%A)<>isreal(%A)  then  r=%t,return,end
    if or(clean(%A(%ka)-%B(%kb))<>0) then  r=%t,return,end
  case 2 then //polynomial
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    if or(degree(%A)<>degree(%B)) then r=%t,return,end
    if or(clean(%A-%B)<>0) then  r=%t,return,end
  case 4 then //boolean
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    if or(%A<>%B) then  r=%t,return,end
  case 5 then //sparse
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    [ija,%A]=spget(%A);[ijb,%B]=spget(%B);
    if or(ija<>ijb) then  r=%t,return,end
    %ka=~isnan(%A);%kb=~isnan(%B);
    if or(%ka<>%kb)  then  r=%t,return,end
    if or(clean(%A(%ka)-%B(%kb))<>0) then  r=%t,return,end
  case 6 then //boolean sparse
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    if or(%A<>%B) then  r=%t,return,end
  case 8 then //int
    if or(inttype(%A)<>inttype(%B)) then  r=%t,return,end
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    if or(%A<>%B) then  r=%t,return,end
  case 9 then //handle
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    //    if or(%A<>%B) then  r=%t,return,end
  case 10 then //string
    if or(size(%A)<>size(%B)) then  r=%t,return,end
    if or(%A<>%B) then  r=%t,return,end
  case 13 then //compiled function
    if %A<>%B then  r=%t,return,end
  case 14 then //library
    if or(gsort(string(%A))<>gsort(string(%B))) then  r=%t,return,end
  case 15 then //list
    if or(lstsize(%A)<>lstsize(%B)) then  r=%t,return,end
    if or(definedfields(%A)<>definedfields(%B)) then r=%t,return,end
    for k = definedfields(%A)
      if %CMP(%A(k),%B(k)) then r=%t,return,end
    end
  case 16 then //tlist
    if or(lstsize(%A)<>lstsize(%B)) then  r=%t,return,end
    if or(definedfields(%A)<>definedfields(%B)) then r=%t,return,end
    if typeof(%A)=='rational' then
      if or(clean(%A-%B)<>0) then r=%t,end
      return
    end
    for k = definedfields(%A)
      if %CMP(%A(k),%B(k)) then r=%t,return,end
    end
  case 17 then //mlist
    if or(lstsize(%A)<>lstsize(%B)) then  r=%t,return,end
    if or(definedfields(%A)<>definedfields(%B)) then r=%t,return,end
    for k = definedfields(%A)
      if %CMP(getfield(k,%A),getfield(k,%B)) then r=%t,return,end
    end
  case 130 then
    if %A<>%B then  r=%t,return,end
  else
    r=%f
  end
endfunction