Debian Codegraph @

tests/macro_processor/example1_macro.mod

raw
1 // Various tests for the macroprocessor
2
3 var y, c, k, a, h, b;
4 varexo e, u;
5
6 @#ifndef NOTDEFINED
7 parameters beta, rho, alpha, delta, theta, psi, tau;
8 @#else
9 @#error "IFNDEF PROBLEM"
10 @#endif
11
12 @#ifdef NOTDEFINED
13 @#error "IFDEF PROBLEM"
14 @#else
15 alpha = 0.36;
16 rho = 0.95;
17 tau = 0.025;
18 beta = 0.99;
19 delta = 0.025;
20 psi = 0;
21 theta = 2.95;
22 phi = 0.1;
23 @#endif
24
25 @#define a = 5
26 @#define b = 2*(a + 3)/4-1
27 @#if b != 3
28 @#error "Arithmetic problem"
29 @#endif
30
31 @#define v = [ "a", 1, 2:3]
32 @#define empty = []
33 @#define z = v[2:3]
34 @#if z != [ 1, [ 2, 3 ]] || length(v) != 3 || 5 in v || !("a" in v) || length(empty) != 0
35 @#error "Array problem"
36 @#endif
37
38 @#define w = [ 1 ]
39 @#for elt in v
40 @#define w = w + [ elt ]
41 @#endfor
42 @#if w != [ 1, "a", 1, 2:3]
43 @#error "For loop problem 1"
44 @#endif
45
46 @#define w = [ ]
47 @#for (i,j) in [(1,2),(1,3),(1,4)]
48 @#define w = w + [i, j]
49 @#endfor
50 @#if w != [ 1, 2, 1, 3, 1, 4]
51 @#error "For loop problem 2"
52 @#endif
53
54 @#define s = "abcde"
55 @#if length(s) != 5 || s[3:4] != "cd"
56 @#error "String problem"
57 @#endif
58
59 @#define f(y, z) = y + "bar" + z
60 @#if f("foo", "baz") != "foobarbaz"
61 @#error "Function problem"
62 @#endif
63
64
65 @#define x = 1:3
66
67 @#define y = [ i in x when i > 1 ]
68 @#if y != [ 2, 3 ]
69 @# error "One-dimensional comprehension problem"
70 @#endif
71
72 @#define z = [ (i,j) in x^2 when i != j ]
73 @#if z != [ (1,2), (1,3), (2,1), (2,3), (3,1), (3,2) ]
74 @# error "Two-dimensional comprehension problem"
75 @#endif
76
77 @#define t = 2:4
78 @#define tt = [ (i,j) in t^2 when (i,j) in [ (k,l) in x^2 when k != l ] ]
79 @#if tt != [ (2,3), (3,2) ]
80 @# error "Nested comprehension problem"
81 @#endif
82
83
84
85 model;
86 c*theta*h^(1+psi)=(1-alpha)*y;
87 k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
88 *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
89 y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
90 k = exp(b)*(y-c)+(1-delta)*k(-1);
91 a = rho*a(-1)+tau*b(-1) + e;
92 b = tau*a(-1)+rho*b(-1) + u;
93 end;
94
95 initval;
96 y = 1.08068253095672;
97 c = 0.80359242014163;
98 h = 0.29175631001732;
99 k = 11.08360443260358;
100 a = 0;
101 b = 0;
102 e = 0;
103 u = 0;
104 end;
105
106 @#define DEFINEDvar
107
108 // See preprocessor#43
109 @#if !(DEFINEDvar == true)
110 @#error "A variable defined without a value should be equal to logical true"
111 @#endif
112
113 @#ifndef DEFINEDvar
114 @#error "IFNDEF PROBLEM"
115 @#else
116 shocks;
117 var e; stderr 0.009;
118 var u; stderr 0.009;
119 var e, u = phi*0.009*0.009;
120 end;
121 @#endif
122
123 @#ifdef DEFINEDvar
124 stoch_simul;
125 @#elseif true
126 @#error "ELSEIF PROBLEM"
127 @#else
128 @#error "IFDEF PROBLEM"
129 @#endif
130
131 @#if false
132 @#error "IF ERROR"
133 @#elseif false
134 @#error "ELSEIF ERROR"
135 @#elseif defined(DEFINEDvar)
136 @#echo "Good"
137 @#else
138 @#error "ELSE ERROR"
139 @#endif
140
141 @#define a = 1
142 @#define f(x) = x + a
143 @#define a = 2
144 @#define g(a) = f(1) + a
145 @#define a = 3
146 @#define h(a) = g(2) + a
147
148 @#if f(1) != 4
149 @#error "Problem with functions 1"
150 @#endif
151
152 @#if g(2) != 6
153 @#error "Problem with functions 2"
154 @#endif
155
156 @#if h(1) != 7
157 @#error "Problem with functions 3"
158 @#endif
159
160 @#if h(g(f(1))+1) != 15
161 @#error "Problem with functions 4"
162 @#endif
163
164 @#define zerotol = 1e-15
165 @#if exp(ln(5)) <= 5-zerotol && exp(ln(5)) >= 5+zerotol
166 @#error "Problem with math functions"
167 @#endif
168
169 @#if log(0) != -inf || 1/0 != inf
170 @#error "Problem with inf"
171 @#endif
172
173 @#if 5 < nan
174 @#error "Problem with NaN comparison"
175 @#endif
176
177 @#if 5 >= inf
178 @#error "Problem with inf comparison"
179 @#endif
180
181 @#if "Aaaaaaaa" > "B" || "AA" != "AA"
182 @#error "String comparison"
183 @#endif
184
185 @#define A = "La crise economique"
186 @#if A[1,8,3,7,4,10,13,2,5,16,12,9,11,14,15,6,17:19] != "Le scenario comique"
187 @#error "Problem with string indexing/comparison"
188 @#endif
189
190 @#define f(x) = x + "C"
191 @#if "A" + f("B") != "ABC"
192 @#error "Problem with String concatenation"
193 @#endif
194
195 @#define z = [[i,"A",i:j,j] for (i,j) in (1:3)^2 when i < j]
196 @#if z != [[1, "A", [1, 2], 2], [1, "A", [1, 2, 3], 3], [2, "A", [2, 3], 3]]
197 @#error "Problem with array comprehension"
198 @#endif
199
200 @#if [(i,j) in (1:2)^2 when i<j] != [(1, 2)]
201 @#error "Problem with set comprehension"
202 @#endif
203
204 @#define f(x) = [(j,i+1) for (i,j) in x^2]
205 @#if f(1:2) != [(1, 2), (2, 2), (1, 3), (2, 3)]
206 @#error "Problem with functional comprehension"
207 @#endif
208
209 @#if [(j,i+1) for (i,j) in (1:2)*(1:2) when i < j] != [(2, 2)]
210 @#error "Problem with functional comprehension"
211 @#endif
212
213 @#if exp(log(5)) > 5-1e-14 && exp(log(5)) < 5+1e-14
214
215 @#else
216 @#error "Numeric comparison incorrect"
217 @#endif
218
219 @#if ([1] + (array)(real) "2") != [1, 2]
220 @#error "Cast error"
221 @#endif
222
223 @#if -3:-1.5:3 != [] || 3:-1:-0.1 != [3, 2, 1, 0] \\
224 || 1:1 != [1] || 1:0:1 != [] \\
225 || -1:5:-1 != [-1] || -1:-5:-1 != [-1] \\ // Inline comment
226 || 0:0:0 != [] || 0:0 != [0]
227 @#error "Range error"
228 @#endif
229
230 @#if (bool)"FaLse" || !(bool)"TRUE" || (bool)"0" || !(bool)"-3"
231 @#error "Error in cast of string to bool"
232 @#endif
233
234 @#if !(true || "A") || (0 && "A")
235 @#error "problem with short circuit || or && operator"
236 @#endif
237
238 @#echomacrovars(save)
239 @#echomacrovars