~ubuntu-branches/ubuntu/saucy/gnudatalanguage/saucy-proposed

« back to all changes in this revision

Viewing changes to testsuite/test_moment.pro

  • Committer: Package Import Robot
  • Author(s): Axel Beckert
  • Date: 2013-05-15 02:23:58 UTC
  • mfrom: (15.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130515022358-rziznpf225zn9lv9
Tags: 0.9.3-2
* Upload to unstable.
* Revamp debian/rules
  - Allow parallel builds
  - Use debian/manpages instead of dh_installman parameter
  - Switch to dh7 style debian/rules file
* Bump debhelper compatibility to 9
  - Update versioned debhelper build-dependency
* Bump Standards-Version to 3.9.4 (no changes)
* Apply wrap-and-sort

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
;
6
6
; ToDo: testing /NaN ?!
7
7
;
 
8
; Since 16 June 2012, we also have DIMENSION for MOMENT() (Mathieu Pinter)
 
9
; Since 14 July 2012, we also have DIMENSION for related codes:
 
10
;                     MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()
 
11
;
 
12
; -------------------------------------------------------------
 
13
;
8
14
function ERREUR, x1, x2
9
15
return, SQRT(TOTAL((x1-x2)^2))
10
16
end
11
17
;
12
 
pro TEST_MOMENT, test=test
 
18
; -------------------------------------------------------------
 
19
;
 
20
function CHECK_DIMENSION_CAPABILITY, verbose=verbose
 
21
;
 
22
; IDL before version 8 cannot manage DIMENSION keyword
 
23
;
 
24
; Since 16 June 2012, we also have DIMENSION for MOMENT()
 
25
; Since 14 July 2012, we also have DIMENSION for related codes:
 
26
;    MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()
 
27
;
 
28
if KEYWORD_SET(verbose) then begin
 
29
   txt1='dimension keyword is available in MOMENT() and related codes:'
 
30
   txt2='MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()'
 
31
endif
 
32
;
 
33
DEFSYSV, '!gdl', exists=isGDL
 
34
;
 
35
check_dim=0
 
36
;
 
37
if (isGDL) then begin
 
38
   check_dim=1
 
39
   if KEYWORD_SET(verbose) then begin
 
40
      MESSAGE,/cont, 'in GDL, '+txt1
 
41
      MESSAGE,/cont, txt2
 
42
   endif
 
43
endif else begin
 
44
   ;; when IDL, which major version ? we assume "." is the separator !
 
45
   version=!version.release
 
46
   if (FIX(STRMID(version,0, STRPOS(version,'.'))) GE 8) then check_dim=1
 
47
   if KEYWORD_SET(verbose) then begin
 
48
      if (check_dim EQ 0) then begin
 
49
         MESSAGE,/cont, 'in IDL, before 8.0, dimension keyword not available !'
 
50
      endif else begin
 
51
         MESSAGE,/cont, 'in IDL, since 8.0, '+txt1
 
52
         MESSAGE,/cont, txt2
 
53
      endelse
 
54
   endif
 
55
endelse
 
56
;
 
57
return, check_dim
 
58
;
 
59
end
 
60
;
 
61
; -------------------------------------------------------------
 
62
;
 
63
pro CHECK_VISUAL_MOMENT, data, force_dim=force_dim, no_exit=no_exit, $
 
64
                         help=help, test=test, verbose=verbose
 
65
;
 
66
if KEYWORD_SET(help) then begin
 
67
   print, 'pro CHECK_VISUAL_MOMENT, data, force_dim=force_dim, no_exit=no_exit, $'
 
68
   print, '                         help=help, test=test, verbose=verbose'
 
69
   return
 
70
endif
 
71
;
 
72
; do we have the dimension keyword capability ?
 
73
;
 
74
if ~KEYWORD_SET(force_dim) then begin
 
75
   check_dim=CHECK_DIMENSION_CAPABILITY()
 
76
endif else check_dim=1
 
77
;
 
78
if (check_dim EQ 0) then begin
 
79
   MESSAGE, 'this test requires Dimension keyword capability'
 
80
endif
 
81
;
 
82
if N_PARAMS() EQ 0 then data=DIST(115, 128)
 
83
;
 
84
nb_nan=N_ELEMENTS(data)/10
 
85
pos=FIX(RANDOMU(seed,nb_nan)*N_ELEMENTS(data))
 
86
data_NaN=data
 
87
data_NaN[pos]=!values.f_nan
 
88
;
 
89
for ii=0,1 do begin
 
90
   if ii EQ 0 then begin
 
91
      tmp=data 
 
92
      title='no NaN'
 
93
   endif else begin
 
94
      tmp=data_NaN
 
95
      title='with 10% NaN'
 
96
   endelse
 
97
   WINDOW, ii, xsize=400, ysize=750, title=title
 
98
   !p.multi=[0,2,4]
 
99
   ;;
 
100
   plot, MEAN(tmp, dim=1,/nan), title='MEAN, dim=1'
 
101
   plot, MEAN(tmp, dim=2,/nan), title='MEAN, dim=1'
 
102
   plot, STDDEV(tmp, dim=1,/nan), title='STDDEV, dim=1'
 
103
   plot, STDDEV(tmp, dim=2,/nan), title='STDDEV, dim=2'
 
104
   plot, SKEWNESS(tmp, dim=1,/nan), title='SKEWNESS, dim=1'
 
105
   plot, SKEWNESS(tmp, dim=2,/nan), title='SKEWNESS, dim=2'
 
106
   plot, KURTOSIS(tmp, dim=1,/nan), title='KURTOSIS, dim=1'
 
107
   plot, KURTOSIS(tmp, dim=2,/nan), title='KURTOSIS, dim=2'
 
108
endfor
 
109
;
 
110
!p.multi=0
 
111
;
 
112
end
 
113
;
 
114
pro TEST_NUMERICAL_MOMENT, force_dim=force_dim, no_exit=no_exit, $
 
115
                           help=help, test=test, verbose=verbose
 
116
;
 
117
if KEYWORD_SET(help) then begin
 
118
    print, 'pro TEST_NUMERICAL_MOMENT, force_dim=force_dim, no_exit=no_exit, $'
 
119
    print, '                           help=help, test=test, verbose=verbose'
 
120
    return
 
121
endif
 
122
;
 
123
; do we have the dimension keyword capability ?
 
124
;
 
125
if ~KEYWORD_SET(force_dim) then begin
 
126
   check_dim=CHECK_DIMENSION_CAPABILITY(/verbose)
 
127
endif else check_dim=1
13
128
;
14
129
nb_pb=0
15
130
;
27
142
e2=ERREUR(expected_resu2, resu2)
28
143
if (e2 GT 1e-5) then nb_pb=nb_pb+1
29
144
;
30
 
if KEYWORD_SET(test) then STOP
 
145
; -----
 
146
;
 
147
a=FINDGEN(3, 2, 3)^2
 
148
expected_resu3=[[[60.0000, 73.0000, 88.0000], $
 
149
                 [105.000, 124.000, 145.000]], $
 
150
                [[5616.00, 7488.00, 9648.00], $
 
151
                 [12096.0, 14832.0, 17856.0]], $
 
152
                [[0.287409, 0.256015, 0.229751], $
 
153
                 [0.207827, 0.189413, 0.173812]], $
 
154
                [[-2.33333, -2.33333, -2.33333], $
 
155
                 [-2.33333, -2.33333, -2.33333]]]
 
156
if (check_dim) then begin
 
157
    resu3=MOMENT(a, DIMENSION=3)
 
158
    e3=ERREUR(expected_resu3, resu3)
 
159
    if (e3 GT 1e-5) then nb_pb=nb_pb+1
 
160
endif else MESSAGE, /continue, 'skipping /DIM test'
 
161
;
 
162
; -----
 
163
;
 
164
a=[1,4,5,!VALUES.F_NAN]
 
165
expected_resu4=[3.33333, 4.33333, -0.28741, -2.33333]
 
166
resu4=MOMENT(a, /NAN)
 
167
e4=ERREUR(expected_resu4, resu4)
 
168
if (e4 GT 1e-5) then nb_pb=nb_pb+1
 
169
;
 
170
; -----
 
171
;
 
172
a=[[1,4,5,!VALUES.F_NAN],[6,8,!VALUES.F_NAN, 9]]
 
173
expected_resu5=[[3.33333,7.66667], $
 
174
                [4.33333,2.33333],[-0.28741,-0.20783], $
 
175
                [-2.33333,-2.33333]]
 
176
if (check_dim) then begin
 
177
    resu5=MOMENT(a, DIMENSION=1, /NAN)
 
178
    e5=ERREUR(expected_resu5, resu5)
 
179
    if (e5 GT 1e-5) then nb_pb=nb_pb+1
 
180
endif else MESSAGE, /continue, 'skipping /DIM test'
 
181
;
 
182
; -----------------
31
183
;
32
184
if (nb_pb EQ 0) then begin 
33
185
   MESSAGE, 'No problem found in TEST_MOMENT', /continue
34
186
endif else begin
35
187
   MESSAGE, STRING(nb_pb)+' problem(s) found in TEST_MOMENT', /continue
36
 
   EXIT, status=1
37
188
endelse
38
189
;
39
 
end
 
190
if KEYWORD_SET(test) then STOP
 
191
;
 
192
if (nb_pb GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
 
193
;
 
194
end
 
195
;
 
196
; ------------------------------------
 
197
;
 
198
pro TEST_MOMENT, force_dim=force_dim, $
 
199
                 help=help, test=test, no_exit=no_exit, verbose=verbose
 
200
;
 
201
TEST_NUMERICAL_MOMENT, force_dim=force_dim, help=help, $
 
202
                       test=test, no_exit=no_exit, verbose=verbose
 
203
;
 
204
CHECK_VISUAL_MOMENT, force_dim=force_dim, help=help, $
 
205
                     test=test, no_exit=no_exit, verbose=verbose
 
206
;
 
207
end
 
208