excit.c 17.4 KB
Newer Older
1 2 3 4 5
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "excit.h"

6 7
#define ES EXCIT_SUCCESS

8 9 10
void test_range_iterator(void)
{
	excit_t it;
11 12 13
	ssize_t dim;
	ssize_t size;
	ssize_t indexes[1];
14 15 16 17
	enum excit_type_e type;
	excit_t its[3];
	int looped;
	int i;
18
	ssize_t ith;
19 20 21

	it = excit_alloc(EXCIT_RANGE);
	assert(it != NULL);
22
	assert(excit_type(it, &type) == ES);
23
	assert(type == EXCIT_RANGE);
24
	assert(excit_dimension(it, &dim) == ES);
25 26
	assert(dim == 0);

27 28
	assert(excit_range_init(it, 0, 3, 1) == ES);
	assert(excit_dimension(it, &dim) == ES);
29
	assert(dim == 1);
30
	assert(excit_size(it, &size) == ES);
31 32 33
	assert(size == 4);

	for (i = 0; i < 4; i++) {
34
		assert(excit_nth(it, i, indexes) == ES);
35
		assert(indexes[0] == i);
36
		assert(excit_n(it, indexes, &ith) == ES);
37 38
		assert(ith == i);
		ith = -1;
39
		assert(excit_pos(it, &ith) == ES);
40
		assert(ith == i);
41
		assert(excit_peek(it, indexes) == ES);
42
		assert(indexes[0] == i);
43
		assert(excit_next(it, indexes) == ES);
44 45
		assert(indexes[0] == i);
	}
Brice Videau's avatar
Brice Videau committed
46 47
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
	assert(excit_peek(it, indexes) == EXCIT_STOPIT);
48

49
	assert(excit_rewind(it) == ES);
50 51 52
	looped = 0;
	i = 0;
	while (!looped) {
53
		assert(excit_cyclic_next(it, indexes, &looped) == ES);
54 55 56
		assert(indexes[0] == i);
		i++;
	}
57
	assert(excit_peek(it, indexes) == ES);
58
	assert(indexes[0] == 0);
59
	assert(excit_cyclic_next(it, indexes, &looped) == ES);
60 61 62 63
	assert(indexes[0] == 0);
	assert(looped == 0);

	for (i = 1; i < 4; i++) {
64
		assert(excit_next(it, indexes) == ES);
65 66
		assert(indexes[0] == i);
	}
Brice Videau's avatar
Brice Videau committed
67 68
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
69
	assert(excit_cyclic_next(it, indexes, &looped) == ES);
70 71 72
	assert(indexes[0] == 0);
	assert(looped == 1);

73 74
	assert(excit_range_init(it, 3, 0, -1) == ES);
	assert(excit_size(it, &size) == ES);
75 76 77
	assert(size == 4);

	for (i = 3; i >= 0; i--) {
78
		assert(excit_next(it, indexes) == ES);
79 80
		assert(indexes[0] == i);
	}
Brice Videau's avatar
Brice Videau committed
81
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
82

83 84
	assert(excit_range_init(it, 3, 0, 1) == ES);
	assert(excit_size(it, &size) == ES);
85 86
	assert(size == 0);

87 88
	assert(excit_range_init(it, 0, 9, 1) == ES);
	assert(excit_size(it, &size) == ES);
89
	assert(size == 10);
90 91
	assert(excit_split(it, 3, its) == ES);
	assert(excit_size(its[0], &size) == ES);
92 93
	assert(size == 4);
	for (int i = 0; i < 4; i++) {
94
		assert(excit_next(its[0], indexes) == ES);
95 96
		assert(indexes[0] == i);
	}
97
	assert(excit_size(its[1], &size) == ES);
98 99
	assert(size == 3);
	for (int i = 4; i < 7; i++) {
100
		assert(excit_next(its[1], indexes) == ES);
101 102
		assert(indexes[0] == i);
	}
103
	assert(excit_size(its[2], &size) == ES);
104 105
	assert(size == 3);
	for (int i = 7; i < 10; i++) {
106
		assert(excit_next(its[2], indexes) == ES);
107 108 109 110 111 112
		assert(indexes[0] == i);
	}
	excit_free(its[0]);
	excit_free(its[1]);
	excit_free(its[2]);

Brice Videau's avatar
Brice Videau committed
113 114 115
	assert(excit_split(it, 24, its) == -EXCIT_EDOM);
	assert(excit_split(it, 0, its) == -EXCIT_EDOM);
	assert(excit_split(it, -1, its) == -EXCIT_EDOM);
116 117 118 119 120 121 122 123 124
	excit_free(it);
}

void test_product_iterators(void)
{
	int i, j, k;
	int looped;
	excit_t it;
	excit_t tmp;
125 126 127 128 129
	ssize_t dim;
	ssize_t count;
	ssize_t size;
	ssize_t indexes[3];
	ssize_t indexes2[3];
130 131
	enum excit_type_e type;
	excit_t its[5];
132
	ssize_t ith;
133 134 135

	it = excit_alloc(EXCIT_PRODUCT);
	assert(it != NULL);
136
	assert(excit_type(it, &type) == ES);
137
	assert(type == EXCIT_PRODUCT);
138
	assert(excit_dimension(it, &dim) == ES);
139
	assert(dim == 0);
140
	assert(excit_product_count(it, &count) == ES);
141
	assert(count == 0);
142
	assert(excit_size(it, &size) == ES);
143
	assert(size == 0);
Brice Videau's avatar
Brice Videau committed
144
	assert(excit_peek(it, indexes) == -EXCIT_EINVAL);
145 146 147

	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 0, 3, 1);
148 149
	assert(excit_product_add(it, tmp) == ES);
	assert(excit_dimension(it, &dim) == ES);
150
	assert(dim == 1);
151
	assert(excit_product_count(it, &count) == ES);
152
	assert(count == 1);
153
	assert(excit_size(it, &size) == ES);
154
	assert(size == 4);
155
	assert(excit_peek(it, indexes) == ES);
156 157 158 159
	assert(indexes[0] == 0);

	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 1, -1, -1);
160 161
	assert(excit_product_add(it, tmp) == ES);
	assert(excit_dimension(it, &dim) == ES);
162
	assert(dim == 2);
163
	assert(excit_product_count(it, &count) == ES);
164
	assert(count == 2);
165
	assert(excit_size(it, &size) == ES);
166
	assert(size == 3 * 4);
167
	assert(excit_peek(it, indexes) == ES);
168 169 170 171 172 173
	assert(indexes[0] == 0);
	assert(indexes[1] == 1);

	k = 0;
	for (i = 0; i <= 3; i++) {
		for (j = 1; j >= -1; j--, k++) {
174
			assert(excit_nth(it, k, indexes) == ES);
175 176
			assert(indexes[0] == i);
			assert(indexes[1] == j);
177
			assert(excit_pos(it, &ith) == ES);
178 179
			assert(ith == k);
			ith = -1;
180
			assert(excit_n(it, indexes, &ith) == ES);
181
			assert(ith == k);
182
			assert(excit_peek(it, indexes) == ES);
183 184
			assert(indexes[0] == i);
			assert(indexes[1] == j);
185
			assert(excit_next(it, indexes) == ES);
186 187 188 189
			assert(indexes[0] == i);
			assert(indexes[1] == j);
		}
	}
Brice Videau's avatar
Brice Videau committed
190 191 192
	assert(excit_peek(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
193
	assert(excit_cyclic_next(it, indexes, &looped) == ES);
194 195 196 197
	assert(looped == 1);
	assert(indexes[0] == 0);
	assert(indexes[1] == 1);

198
	assert(excit_rewind(it) == ES);
199 200 201 202
	for (k = 0; k < 3; k++) {
		for (i = 0; i <= 3; i++) {
			for (j = 1; j >= -1; j--) {
				assert(excit_cyclic_next
203
				       (it, indexes, &looped) == ES);
204 205 206 207 208 209 210 211 212 213 214
				assert(indexes[0] == i);
				assert(indexes[1] == j);
			}
		}
		assert(looped == 1);
	}

	excit_rewind(it);

	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, -5, 5, 1);
215 216
	assert(excit_product_add(it, tmp) == ES);
	assert(excit_dimension(it, &dim) == ES);
217
	assert(dim == 3);
218
	assert(excit_size(it, &size) == ES);
219 220 221
	assert(size == 3 * 4 * 11);

	//split first dimension
222
	assert(excit_product_split_dim(it, 0, 2, its) == ES);
223 224 225
	for (i = 0; i <= 1; i++) {
		for (j = 1; j >= -1; j--) {
			for (k = -5; k <= 5; k++) {
226
				assert(excit_next(its[0], indexes) == ES);
227 228 229 230 231 232
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
233
	assert(excit_next(its[0], indexes) == EXCIT_STOPIT);
234 235 236
	for (i = 2; i <= 3; i++) {
		for (j = 1; j >= -1; j--) {
			for (k = -5; k <= 5; k++) {
237
				assert(excit_next(its[1], indexes) == ES);
238 239 240 241 242 243
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
244
	assert(excit_next(its[1], indexes) == EXCIT_STOPIT);
245 246 247 248
	excit_free(its[0]);
	excit_free(its[1]);

	//split second dimension
249
	assert(excit_product_split_dim(it, 1, 2, its) == ES);
250 251 252
	for (i = 0; i <= 3; i++) {
		for (j = 1; j >= 0; j--) {
			for (k = -5; k <= 5; k++) {
253
				assert(excit_next(its[0], indexes) == ES);
254 255 256 257 258 259
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
260
	assert(excit_next(its[0], indexes) == EXCIT_STOPIT);
261 262 263
	for (i = 0; i <= 3; i++) {
		for (j = -1; j >= -1; j--) {
			for (k = -5; k <= 5; k++) {
264
				assert(excit_next(its[1], indexes) == ES);
265 266 267 268 269 270
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
271
	assert(excit_next(its[1], indexes) == EXCIT_STOPIT);
272 273 274 275
	excit_free(its[0]);
	excit_free(its[1]);

	//split third dimension
276
	assert(excit_product_split_dim(it, 2, 2, its) == ES);
277 278 279
	for (i = 0; i <= 3; i++) {
		for (j = 1; j >= -1; j--) {
			for (k = -5; k <= 0; k++) {
280
				assert(excit_next(its[0], indexes) == ES);
281 282 283 284 285 286
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
287
	assert(excit_next(its[0], indexes) == EXCIT_STOPIT);
288 289 290
	for (i = 0; i <= 3; i++) {
		for (j = 1; j >= -1; j--) {
			for (k = 1; k <= 5; k++) {
291
				assert(excit_next(its[1], indexes) == ES);
292 293 294 295 296 297
				assert(indexes[0] == i);
				assert(indexes[1] == j);
				assert(indexes[2] == k);
			}
		}
	}
Brice Videau's avatar
Brice Videau committed
298
	assert(excit_next(its[1], indexes) == EXCIT_STOPIT);
299 300 301
	excit_free(its[0]);
	excit_free(its[1]);

Brice Videau's avatar
Brice Videau committed
302
	assert(excit_product_split_dim(it, 2, 15, its) == -EXCIT_EDOM);
303

304
	assert(excit_split(it, 5, its) == ES);
305

306
	assert(excit_rewind(it) == ES);
307
	for (i = 0; i < 5; i++) {
308 309
		while (excit_next(its[i], indexes) == ES) {
			assert(excit_next(it, indexes2) == ES);
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
			assert(indexes[0] == indexes2[0]);
			assert(indexes[1] == indexes2[1]);
			assert(indexes[2] == indexes2[2]);
		}
	}

	for (i = 0; i < 5; i++)
		excit_free(its[i]);
	excit_free(it);

}

void test_repeat_iterator(void)
{
	excit_t it;
	excit_t tmp;
326 327
	ssize_t dim;
	ssize_t size;
328
	enum excit_type_e type;
329
	ssize_t indexes[1];
330
	excit_t its[2];
331
	ssize_t ith;
332 333 334

	it = excit_alloc(EXCIT_REPEAT);
	assert(it != NULL);
335
	assert(excit_type(it, &type) == ES);
336
	assert(type == EXCIT_REPEAT);
337
	assert(excit_dimension(it, &dim) == ES);
338 339 340 341 342
	assert(dim == 0);

	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 0, 2, 1);
	excit_repeat_init(it, tmp, 2);
343
	assert(excit_dimension(it, &dim) == ES);
344
	assert(dim == 1);
345
	assert(excit_size(it, &size) == ES);
346 347 348 349
	assert(size == 6);

	for (int i = 0, k = 0; i <= 2; i++) {
		for (int j = 0; j < 2; j++, k++) {
350
			assert(excit_nth(it, k, indexes) == ES);
351
			assert(indexes[0] == i);
352
			assert(excit_pos(it, &ith) == ES);
353
			assert(ith == k);
354
			assert(excit_peek(it, indexes) == ES);
355
			assert(indexes[0] == i);
356
			assert(excit_next(it, indexes) == ES);
357 358 359
			assert(indexes[0] == i);
		}
	}
Brice Videau's avatar
Brice Videau committed
360 361
	assert(excit_peek(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
362

363
	assert(excit_rewind(it) == ES);
364 365
	for (int i = 0; i <= 2; i++) {
		for (int j = 0; j < 2; j++) {
366
			assert(excit_peek(it, indexes) == ES);
367
			assert(indexes[0] == i);
368
			assert(excit_next(it, indexes) == ES);
369 370 371
			assert(indexes[0] == i);
		}
	}
Brice Videau's avatar
Brice Videau committed
372 373
	assert(excit_peek(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
374

375
	assert(excit_split(it, 2, its) == ES);
376 377
	for (int i = 0; i <= 1; i++) {
		for (int j = 0; j < 2; j++) {
378
			assert(excit_peek(its[0], indexes) == ES);
379
			assert(indexes[0] == i);
380
			assert(excit_next(its[0], indexes) == ES);
381 382 383
			assert(indexes[0] == i);
		}
	}
Brice Videau's avatar
Brice Videau committed
384 385
	assert(excit_peek(its[0], indexes) == EXCIT_STOPIT);
	assert(excit_next(its[0], indexes) == EXCIT_STOPIT);
386 387
	for (int i = 2; i <= 2; i++) {
		for (int j = 0; j < 2; j++) {
388
			assert(excit_peek(its[1], indexes) == ES);
389
			assert(indexes[0] == i);
390
			assert(excit_next(its[1], indexes) == ES);
391 392 393
			assert(indexes[0] == i);
		}
	}
Brice Videau's avatar
Brice Videau committed
394 395
	assert(excit_peek(its[1], indexes) == EXCIT_STOPIT);
	assert(excit_next(its[1], indexes) == EXCIT_STOPIT);
396 397 398 399 400 401 402 403 404 405

	excit_free(its[0]);
	excit_free(its[1]);
	excit_free(it);
}

void test_cons_iterator(void)
{
	excit_t it;
	excit_t tmp;
406 407
	ssize_t dim;
	ssize_t size;
408
	enum excit_type_e type;
409
	ssize_t indexes[4];
410
	excit_t its[2];
411
	ssize_t ith;
412 413 414

	it = excit_alloc(EXCIT_CONS);
	assert(it != NULL);
415
	assert(excit_type(it, &type) == ES);
416
	assert(type == EXCIT_CONS);
417
	assert(excit_dimension(it, &dim) == ES);
418 419 420 421
	assert(dim == 0);

	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 0, 4, 1);
422 423
	assert(excit_cons_init(it, tmp, 3) == ES);
	assert(excit_dimension(it, &dim) == ES);
424
	assert(dim == 3);
425
	assert(excit_size(it, &size) == ES);
426 427 428
	assert(size == 3);
	for (int j = 0; j < 2; j++) {
		for (int i = 0, k = 0; i < 3; i++, k++) {
429
			assert(excit_nth(it, k, indexes) == ES);
430 431 432
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
433
			assert(excit_pos(it, &ith) == ES);
434 435
			assert(ith == k);
			ith = -1;
436
			assert(excit_n(it, indexes, &ith) == ES);
437
			assert(ith == k);
438
			assert(excit_peek(it, indexes) == ES);
439 440 441
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
442
			assert(excit_next(it, indexes) == ES);
443 444 445 446
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
		}
Brice Videau's avatar
Brice Videau committed
447 448
		assert(excit_peek(it, indexes) == EXCIT_STOPIT);
		assert(excit_next(it, indexes) == EXCIT_STOPIT);
449
		assert(excit_rewind(it) == ES);
450 451
	}

452
	assert(excit_split(it, 2, its) == ES);
453 454 455

	for (int j = 0; j < 2; j++) {
		for (int i = 0, k = 0; i < 2; i++, k++) {
456
			assert(excit_nth(its[0], k, indexes) == ES);
457 458 459
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
460
			assert(excit_peek(its[0], indexes) == ES);
461 462 463
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
464
			assert(excit_next(its[0], indexes) == ES);
465 466 467 468
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
		}
Brice Videau's avatar
Brice Videau committed
469 470
		assert(excit_peek(its[0], indexes) == EXCIT_STOPIT);
		assert(excit_next(its[0], indexes) == EXCIT_STOPIT);
471
		assert(excit_rewind(its[0]) == ES);
472 473 474 475
	}

	for (int j = 0; j < 2; j++) {
		for (int i = 2, k = 0; i < 3; i++, k++) {
476
			assert(excit_nth(its[1], k, indexes) == ES);
477 478 479
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
480
			assert(excit_peek(its[1], indexes) == ES);
481 482 483
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
484
			assert(excit_next(its[1], indexes) == ES);
485 486 487 488
			assert(indexes[0] == i);
			assert(indexes[1] == i + 1);
			assert(indexes[2] == i + 2);
		}
Brice Videau's avatar
Brice Videau committed
489 490
		assert(excit_peek(its[1], indexes) == EXCIT_STOPIT);
		assert(excit_next(its[1], indexes) == EXCIT_STOPIT);
491
		assert(excit_rewind(its[1]) == ES);
492 493 494 495 496 497 498 499 500 501 502 503 504 505
	}
	excit_free(its[0]);
	excit_free(its[1]);
	excit_free(it);

	it = excit_alloc(EXCIT_PRODUCT);
	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 0, 3, 1);
	excit_product_add(it, tmp);
	tmp = excit_alloc(EXCIT_RANGE);
	excit_range_init(tmp, 1, -1, -1);
	excit_product_add(it, tmp);

	tmp = excit_alloc(EXCIT_CONS);
506 507
	assert(excit_cons_init(tmp, it, 2) == ES);
	assert(excit_dimension(tmp, &dim) == ES);
508
	assert(dim == 4);
509
	assert(excit_size(tmp, &size) == ES);
510
	assert(size == 11);
511
	assert(excit_peek(tmp, indexes) == ES);
512 513 514 515
	assert(indexes[0] == 0);
	assert(indexes[1] == 1);
	assert(indexes[2] == 0);
	assert(indexes[3] == 0);
516 517 518 519 520 521 522 523 524 525
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
	assert(excit_next(tmp, indexes) == ES);
526 527 528 529
	assert(indexes[0] == 3);
	assert(indexes[1] == 1);
	assert(indexes[2] == 3);
	assert(indexes[3] == 0);
530
	assert(excit_next(tmp, indexes) == ES);
531 532 533 534
	assert(indexes[0] == 3);
	assert(indexes[1] == 0);
	assert(indexes[2] == 3);
	assert(indexes[3] == -1);
Brice Videau's avatar
Brice Videau committed
535
	assert(excit_next(tmp, indexes) == EXCIT_STOPIT);
536 537 538 539 540 541 542

	excit_free(tmp);

}

void test_hilbert2d_iterator(void)
{
543 544 545 546
	ssize_t dim;
	ssize_t size;
	ssize_t indexes[2];
	ssize_t indexes2[2];
547 548 549
	enum excit_type_e type;
	excit_t it;
	excit_t its[3];
550
	ssize_t ith;
551 552 553

	it = excit_alloc(EXCIT_HILBERT2D);
	assert(it != NULL);
554
	assert(excit_type(it, &type) == ES);
555
	assert(type == EXCIT_HILBERT2D);
556
	assert(excit_dimension(it, &dim) == ES);
557
	assert(dim == 0);
558 559
	assert(excit_hilbert2d_init(it, 2) == ES);
	assert(excit_dimension(it, &dim) == ES);
560
	assert(dim == 2);
561
	assert(excit_size(it, &size) == ES);
562 563
	assert(size == 16);

564
	assert(excit_peek(it, indexes) == ES);
565 566
	assert(indexes[0] == 0);
	assert(indexes[1] == 0);
567
	assert(excit_next(it, indexes) == ES);
568 569
	assert(indexes[0] == 0);
	assert(indexes[1] == 0);
570
	assert(excit_next(it, indexes) == ES);
571 572
	assert(indexes[0] == 1);
	assert(indexes[1] == 0);
573
	assert(excit_next(it, indexes) == ES);
574 575
	assert(indexes[0] == 1);
	assert(indexes[1] == 1);
576
	assert(excit_pos(it, &ith) == ES);
577
	assert(ith == 3);
578
	assert(excit_next(it, indexes) == ES);
579 580
	assert(indexes[0] == 0);
	assert(indexes[1] == 1);
581
	assert(excit_next(it, indexes) == ES);
582 583
	assert(indexes[0] == 0);
	assert(indexes[1] == 2);
584
	assert(excit_next(it, indexes) == ES);
585 586
	assert(indexes[0] == 0);
	assert(indexes[1] == 3);
587
	assert(excit_next(it, indexes) == ES);
588 589
	assert(indexes[0] == 1);
	assert(indexes[1] == 3);
590
	assert(excit_next(it, indexes) == ES);
591 592
	assert(indexes[0] == 1);
	assert(indexes[1] == 2);
593
	assert(excit_next(it, indexes) == ES);
594 595
	assert(indexes[0] == 2);
	assert(indexes[1] == 2);
596
	assert(excit_next(it, indexes) == ES);
597 598
	assert(indexes[0] == 2);
	assert(indexes[1] == 3);
599
	assert(excit_next(it, indexes) == ES);
600 601
	assert(indexes[0] == 3);
	assert(indexes[1] == 3);
602
	assert(excit_next(it, indexes) == ES);
603 604
	assert(indexes[0] == 3);
	assert(indexes[1] == 2);
605
	assert(excit_next(it, indexes) == ES);
606 607
	assert(indexes[0] == 3);
	assert(indexes[1] == 1);
608
	assert(excit_next(it, indexes) == ES);
609 610
	assert(indexes[0] == 2);
	assert(indexes[1] == 1);
611
	assert(excit_next(it, indexes) == ES);
612 613
	assert(indexes[0] == 2);
	assert(indexes[1] == 0);
614
	assert(excit_next(it, indexes) == ES);
615 616
	assert(indexes[0] == 3);
	assert(indexes[1] == 0);
Brice Videau's avatar
Brice Videau committed
617 618
	assert(excit_peek(it, indexes) == EXCIT_STOPIT);
	assert(excit_next(it, indexes) == EXCIT_STOPIT);
619 620
	assert(excit_rewind(it) == ES);
	assert(excit_peek(it, indexes) == ES);
621 622
	assert(indexes[0] == 0);
	assert(indexes[1] == 0);
623 624 625
	assert(excit_peek(it, NULL) == ES);
	assert(excit_skip(it) == ES);
	assert(excit_peek(it, indexes) == ES);
626 627 628
	assert(indexes[0] == 1);
	assert(indexes[1] == 0);

629
	assert(excit_rewind(it) == ES);
630 631
	int j = 0;

632 633
	while (excit_next(it, indexes) == ES) {
		assert(excit_nth(it, j, indexes2) == ES);
634 635
		assert(indexes[0] == indexes2[0]);
		assert(indexes[1] == indexes2[1]);
636
		assert(excit_n(it, indexes, &ith) == ES);
637 638 639 640
		assert(j == ith);
		j++;
	}

641 642
	assert(excit_split(it, 3, its) == ES);
	assert(excit_rewind(it) == ES);
643
	for (int i = 0; i < 3; i++) {
644 645
		while (excit_next(its[i], indexes) == ES) {
			assert(excit_next(it, indexes2) == ES);
646 647 648 649 650 651 652 653 654
			assert(indexes[0] == indexes2[0]);
			assert(indexes[1] == indexes2[1]);
		}
	}

	excit_free(its[0]);
	excit_free(its[1]);
	excit_free(its[2]);

Brice Videau's avatar
Brice Videau committed
655
	assert(excit_split(it, 17, its) == -EXCIT_EDOM);
656 657 658 659 660 661 662 663 664 665 666 667 668

	excit_free(it);
}

int main(int argc, char *argv[])
{
	test_range_iterator();
	test_product_iterators();
	test_cons_iterator();
	test_repeat_iterator();
	test_hilbert2d_iterator();
	return 0;
}