-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_all_tests.gml
More file actions
367 lines (277 loc) · 7.51 KB
/
for_all_tests.gml
File metadata and controls
367 lines (277 loc) · 7.51 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#define test_for_all_array
/**
* test_for_all_array()
* Called by the GmUnit test framework to initiate
* a simple hello world assertion to test array support
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'Concatenating each value in the array should yield the expected result';
test[1] = 'Hello world!';
var parts;
parts[0] = 'Hello';
parts[1] = ' ';
parts[2] = 'world';
parts[3] = '!';
repeat for_all(parts) {
actual += this_one();
}
test[0] = actual;
return test;
#define test_for_all_list
/**
* test_for_all_list()
* Called by the GmUnit test framework to initiate
* a simple hello world assertion to test ds_list support
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'Concatenating each value in the ds_list should yield the expected result';
test[1] = 'Hello world!';
var parts = ds_list_create();
ds_list_add(parts, 'Hello');
ds_list_add(parts, ' ');
ds_list_add(parts, 'world');
ds_list_add(parts, '!');
repeat for_all(parts) {
actual += this_one();
}
ds_list_destroy(parts);
test[0] = actual;
return test;
#define test_for_all_map
/**
* test_for_all_map()
* Called by the GmUnit test framework to initiate
* a simple summing assertion to test ds_map support
*
* @return array; The expected value and actual result
*/
var test, actual = 0;
test[2] = 'Summing each value in the ds_map should yield the expected result';
test[1] = 115;
var items = ds_map_create();
ds_map_add(items, 'health potion', 10);
ds_map_add(items, 'mana potion', 5);
ds_map_add(items, 'gold', 100);
repeat for_all(items, treat_as.map) {
actual += this_one();
}
ds_map_destroy(items);
test[0] = actual;
return test;
#define test_for_all_key_value
/**
* test_for_all_key_value()
* Called by the GmUnit test framework to initiate
* a simple concatenation assertion to test key/value support
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'Concatenating each key and value in the array should yield the expected result';
test[1] = '0?1a2b3c';
var parts;
parts[0] = '?';
parts[1] = 'a';
parts[2] = 'b';
parts[3] = 'c';
repeat for_all(parts) {
actual += string(this_key()) + this_value();
}
test[0] = actual;
return test;
#define test_for_all_grid
/**
* test_for_all_grid()
* Called by the GmUnit test framework to initiate
* a simple summing assertion to test ds_grid support
*
* @return array; The expected value and actual result
*/
var test, actual = 0;
test[2] = 'Summing each value in the ds_grid should yield the expected result';
test[1] = 36;
var cases = ds_grid_create(3, 3);
ds_grid_clear(cases, 4);
repeat for_all(cases, treat_as.grid) {
actual += this_one();
}
ds_grid_destroy(cases);
test[0] = actual;
return test;
#define test_for_all_grid_column
/**
* test_for_all_grid_column()
* Called by the GmUnit test framework to initiate
* a simple summing assertion to test ds_grid column support
*
* @return array; The expected value and actual result
*/
var test, actual = 0;
test[2] = 'Summing each value in the ds_grid column should yield the expected result';
test[1] = 16;
var cases = ds_grid_create(3, 4);
ds_grid_clear(cases, 4);
repeat for_all(cases, treat_as.grid_column, 1) {
actual += this_one();
}
ds_grid_destroy(cases);
test[0] = actual;
return test;
#define test_for_all_grid_row
/**
* test_for_all_grid_column()
* Called by the GmUnit test framework to initiate
* a simple summing assertion to test ds_grid row support
*
* @return array; The expected value and actual result
*/
var test, actual = 0;
test[2] = 'Summing each value in the ds_grid row should yield the expected result';
test[1] = 12;
var cases = ds_grid_create(3, 4);
ds_grid_clear(cases, 4);
repeat for_all(cases, treat_as.grid_row, 1) {
actual += this_one();
}
ds_grid_destroy(cases);
test[0] = actual;
return test;
#define test_for_all_grid_key_value
/**
* test_for_all_grid_key_value()
* Called by the GmUnit test framework to initiate
* a test asserting grid keys yield the expected array
*
* @return array; The expected value and actual result
*/
var test, expected_key, actual = 0;
test[2] = 'The key of a ds_grid loop should yield the expected (array) result';
expected_key[0] = 2;
expected_key[1] = 3;
test[1] = expected_key;
var cases = ds_grid_create(3, 4);
ds_grid_clear(cases, 4);
ds_grid_set(cases, 2, 3, 5)
repeat for_all(cases, treat_as.grid) {
if (this_one() == 5) {
actual = this_key(false);
}
}
ds_grid_destroy(cases);
test[0] = actual;
return test;
#define test_for_all_is_first
/**
* test_for_all_is_first()
* Called by the GmUnit test framework to initiate
* a test asserting that the this_is_first function works correctly
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'The this_is_first function should return true in the first iteration of a loop';
test[1] = 'first!';
var posts;
posts[0] = 'first!';
posts[1] = 'second!';
posts[2] = 'third!';
repeat for_all(posts) {
if (this_is_first(true)) {
actual = this_value();
}
}
test[0] = actual;
return test;
#define test_for_all_is_last
/**
* test_for_all_is_last()
* Called by the GmUnit test framework to initiate
* a test asserting that the this_is_last function works correctly
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'The this_is_last function should return true in the last iteration of a loop';
test[1] = 'third!';
var posts;
posts[0] = 'first!';
posts[1] = 'second!';
posts[2] = 'third!';
repeat for_all(posts) {
if (this_is_last(true)) {
actual = this_value();
}
}
test[0] = actual;
return test;
#define test_for_all_stop
/**
* test_for_all_stop()
* Called by the GmUnit test framework to initiate
* a test asserting that the stop_here function works correctly
*
* @return array; The expected value and actual result
*/
var test, actual = 0;
test[2] = 'The stop_here function should clear the current loop (and the current loop only)';
test[1] = 3;
var lists;
lists[0] = ds_list_create();
lists[1] = ds_list_create();
ds_list_add(lists[0], 'ok');
ds_list_add(lists[0], 'ok');
ds_list_add(lists[0], 'not ok');
ds_list_add(lists[0], 'ok');
ds_list_add(lists[1], 'ok');
ds_list_add(lists[1], 'not ok');
ds_list_add(lists[1], 'ok');
repeat for_all(lists) {
repeat for_all(this_one()) {
if (this_one() == 'ok') {
++actual;
} else {
stop_here();
break;
}
}
}
test[0] = actual;
return test;
#define test_for_all_custom
/**
* test_for_all_custom()
* Called by the GmUnit test framework to initiate
* a test asserting that the treat_as.custom feature works correctly
*
* @return array; The expected value and actual result
*/
var test, actual = '';
test[2] = 'The for_all loop should be extensible through treat_as.custom';
test[1] = 'eeeeee';
repeat for_all('The for_all loop should be extensible through treat_as.custom', treat_as.custom, testscript_for_all_e) {
actual += this_one();
}
test[0] = actual;
return test;
#define testscript_for_all_e
/**
* testscript_for_all_e(input)
* Test script that enables for_all to loop over all occurences of "e" in the input string
*
* @param string input; The string whose e's to loop over
*
* @return real; The amount of loops
*/
var size = string_count('e', argument0);
var values = global.for_all_values;
var keys = global.for_all_keys;
var i = size;
repeat (size) {
for_all_push(i, 'e');
i--;
}
return size;