File: test_structures.pro

package info (click to toggle)
gnudatalanguage 0.9.9-13
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 17,892 kB
  • sloc: cpp: 167,389; ansic: 9,358; sh: 566; python: 472; makefile: 252; f90: 28
file content (93 lines) | stat: -rw-r--r-- 2,726 bytes parent folder | download | duplicates (5)
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
;
; AC 28/01/2013: I found no equivalent tests in the testsuite !
;
; bug reported by Gilles on Jan. 23, 2013
; http://sourceforge.net/tracker/?func=detail&aid=3601949&group_id=97659&atid=618683
;
; Modifications history :
; - 2017-12-14 : AC. updating final message,
;      creating a related test for SIZE (test_size.pro)
; - 2018-01-31 : AC. change of test 0a
;
pro TEST_STRUCTURES, no_exit=no_exit, verbose=verbose, $
                     help=help, test=test, debug=debug
;
if KEYWORD_SET(help) then begin
    print, 'pro TEST_STRUCTURES, no_exit=no_exit, verbose=verbose, $'
    print, '                     help=help, test=test, debug=debug, $'
    return
endif
;
nb_errors=0
;
; the structure we create has a name: "TEST"
;
structarray=REPLICATE({test, value:0.0},10)
;populate values:
structarray.value=FINDGEN(10)
;
HELP, structarray.value
;
; basic tests using SIZE() & co.
;
; this test was change by Alain C., 2018-01-31 because
; different result than in IDL 8.2 & 8.4. 
; C code of "typename" also changed
if (TYPENAME(structarray) NE "STRUCT") then begin
   message,/continue, '(0a) unexpected results in TYPENAME() !' 
   nb_errors=nb_errors+1
endif
;
if (SIZE(structarray,/sname) NE "TEST") then begin
   message,/continue, '(0b) unexpected results in SIZE(... ,/sname) !' 
   nb_errors=nb_errors+1
endif
if (SIZE(structarray,/tname) NE "STRUCT") then begin
   message,/continue, '(0c) unexpected results in SIZE(... ,/tname) !' 
   nb_errors=nb_errors+1
endif
if (SIZE(structarray,/type) NE 8) then begin
   message,/continue, '(0d) unexpected results in SIZE(... ,/type) !' 
   nb_errors=nb_errors+1
endif
if ~ARRAY_EQUAL(SIZE(structarray), [1L,10,8,10]) then begin
   message,/continue, '(0e) unexpected results in SIZE() !' 
   nb_errors=nb_errors+1
endif
;
;get subset:
www=WHERE(structarray.value gt 6)
HELP, www
;
if (ARRAY_EQUAL(www, [7,8,9]) NE 1) then begin
    message,/continue, '(1) unexpected results in <<www>> values !'
    nb_errors=nb_errors+1
endif
;
res1=EXECUTE('HELP, structarray[www].value')
if (res1 NE 1) then begin
    message,/continue, ' unexpected badly interpreted Struct indexing ! (case 1)'
    nb_errors=nb_errors+1
endif
;
tab=0.
res2=EXECUTE('tab=structarray[www].value')
if (res2 NE 1) then begin
    message,/continue, ' unexpected badly interpreted Struct indexing ! (case 2)'
    nb_errors=nb_errors+1
endif
;
if (ARRAY_EQUAL(tab, 1.*[7,8,9]) NE 1) then begin
    message,/continue, '(2) unexpected results in extracted values !'
    nb_errors=nb_errors+1
endif
;
; ----------------- final message ----------
;
BANNER_FOR_TESTSUITE, 'TEST_STRUCTURES', nb_errors
;
if (nb_errors GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
;
if KEYWORD_SET(test) then STOP
;
end