Add copyright and licence notices to files which lack them.
[pspp] / tests / language / control / do-repeat.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl 
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl 
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl 
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl AT_BANNER([DO REPEAT])
17
18 AT_SETUP([DO REPEAT -- simple])
19 AT_DATA([do-repeat.sps], [dnl
20 INPUT PROGRAM.
21 STRING y(A1).
22 DO REPEAT xval = 1 2 3 / yval = 'a' 'b' 'c' / var = a b c.
23 COMPUTE x=xval.
24 COMPUTE y=yval.
25 COMPUTE var=xval.
26 END CASE.
27 END REPEAT.
28 END FILE.
29 END INPUT PROGRAM.
30 LIST.
31 ])
32 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
33 AT_CHECK([cat pspp.csv], [0], [dnl
34 Table: Data List
35 y,x,a,b,c
36 a,1.00,1.00,.  ,.  @&t@
37 b,2.00,.  ,2.00,.  @&t@
38 c,3.00,.  ,.  ,3.00
39 ])
40 AT_CLEANUP
41
42 AT_SETUP([DO REPEAT -- containing BEGIN DATA])
43 AT_DATA([do-repeat.sps], [dnl
44 DO REPEAT offset = 1 2 3.
45 DATA LIST NOTABLE /x 1-2.
46 BEGIN DATA.
47 10
48 20
49 30
50 END DATA.
51 COMPUTE x = x + offset.
52 LIST.
53 END REPEAT.
54 ])
55 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
56 AT_CHECK([cat pspp.csv], [0], [dnl
57 Table: Data List
58 x
59 11
60 21
61 31
62
63 Table: Data List
64 x
65 12
66 22
67 32
68
69 Table: Data List
70 x
71 13
72 23
73 33
74 ])
75 AT_CLEANUP
76
77 AT_SETUP([DO REPEAT -- dummy vars not expanded in include files])
78 AT_DATA([include.sps], [dnl
79 COMPUTE y = y + x + 10.
80 ])
81 AT_DATA([do-repeat.sps], [dnl
82 INPUT PROGRAM.
83 COMPUTE x = 0.
84 COMPUTE y = 0.
85 END CASE.
86 END FILE.
87 END INPUT PROGRAM.
88
89 DO REPEAT x = 1 2 3.
90 INCLUDE 'include.sps'.
91 END REPEAT.
92
93 LIST.
94 ])
95 AT_CHECK([pspp -o pspp.csv do-repeat.sps], [0], [dnl
96 do-repeat.sps:8: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
97 ])
98 AT_CHECK([cat pspp.csv], [0], [dnl
99 do-repeat.sps:8: warning: DO REPEAT: Dummy variable name `x' hides dictionary variable `x'.
100
101 Table: Data List
102 x,y
103 .00,30.00
104 ])
105 AT_CLEANUP
106
107 AT_SETUP([DO REPEAT -- nested])
108 AT_DATA([do-repeat.sps], [dnl
109 DATA LIST NOTABLE /a 1.
110 BEGIN DATA.
111 0
112 END DATA.
113
114 DO REPEAT h = h0 TO h3 / x = 0 TO 3 / y = 8, 7.5, 6, 5.
115         COMPUTE h = x + y.
116 END REPEAT.
117
118 VECTOR v(6).
119 COMPUTE #idx = 0.
120 DO REPEAT i = 1 TO 2.
121         DO REPEAT j = 3 TO 5.
122                 COMPUTE #x = i + j.
123                 COMPUTE #idx = #idx + 1.
124                 COMPUTE v(#idx) = #x.
125         END REPEAT.
126 END REPEAT.
127
128 LIST.
129 ])
130 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
131 AT_CHECK([cat pspp.csv], [0], [dnl
132 Table: Data List
133 a,h0,h1,h2,h3,v1,v2,v3,v4,v5,v6
134 0,8.00,8.50,8.00,8.00,4.00,5.00,6.00,5.00,6.00,7.00
135 ])
136 AT_CLEANUP
137
138 dnl This program tests for a bug that crashed PSPP given an empty DO
139 dnl REPEAT...END REPEAT block.  See bug #18407.
140 AT_SETUP([DO REPEAT -- empty])
141 AT_DATA([do-repeat.sps], [dnl
142 DATA LIST NOTABLE /a 1.
143 BEGIN DATA.
144 0
145 END DATA.
146
147 DO REPEAT h = a.
148 END REPEAT.
149 ])
150 AT_CHECK([pspp -o pspp.csv do-repeat.sps])
151 AT_CHECK([cat pspp.csv], [0], [dnl
152 ])
153 AT_CLEANUP
154
155 dnl This program tests for a bug that crashed PSPP when END REPEAT
156 dnl was missing.  See bug #31016.
157 AT_SETUP([DO REPEAT -- missing END REPEAT])
158 AT_DATA([do-repeat.sps], [dnl
159 DATA LIST NOTABLE /x 1.
160 DO REPEAT y = 1 TO 10.
161 ])
162 AT_CHECK([pspp -O format=csv do-repeat.sps], [1], [dnl
163 error: DO REPEAT: Syntax error at end of input: expecting END.
164 ])
165 AT_CLEANUP