Commit 711bc674 authored by Nicolas Denoyelle's avatar Nicolas Denoyelle

Merge branch 'master' into tleaf

parents b98f68c0 e7610669
...@@ -47,6 +47,7 @@ stamp-h1 ...@@ -47,6 +47,7 @@ stamp-h1
/install-sh /install-sh
/missing /missing
/stamp-h1 /stamp-h1
libexcit.pc
# autotest # autotest
tests/*.trs tests/*.trs
......
#include "dev/excit.h" #include "dev/excit.h"
#include "hilbert2d.h" #include "hilbert2d.h"
/* Helper functions from: https://en.wikipedia.org/wiki/Hilbert_curve */
//rotate/flip a quadrant appropriately
static void rot(ssize_t n, ssize_t *x, ssize_t *y, ssize_t rx, ssize_t ry) static void rot(ssize_t n, ssize_t *x, ssize_t *y, ssize_t rx, ssize_t ry)
{ {
if (ry == 0) { if (ry == 0) {
......
...@@ -126,7 +126,7 @@ static int slice_it_split(const excit_t data, ssize_t n, excit_t *results) ...@@ -126,7 +126,7 @@ static int slice_it_split(const excit_t data, ssize_t n, excit_t *results)
err = -EXCIT_ENOMEM; err = -EXCIT_ENOMEM;
goto error; goto error;
} }
err = excit_slice_init(results[i], tmp, tmp2); err = excit_slice_init(results[i], tmp2, tmp);
if (err) { if (err) {
excit_free(tmp); excit_free(tmp);
excit_free(tmp2); excit_free(tmp2);
......
...@@ -11,8 +11,10 @@ excit_product_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_product.c ...@@ -11,8 +11,10 @@ excit_product_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_product.c
excit_repeat_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_repeat.c excit_repeat_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_repeat.c
excit_cons_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_cons.c excit_cons_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_cons.c
excit_tleaf_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_tleaf.c excit_tleaf_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_tleaf.c
excit_hilbert2d_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_hilbert2d.c
excit_slice_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_slice.c
UNIT_TESTS = excit_range excit_product excit_repeat excit_cons excit_tleaf UNIT_TESTS = excit_range excit_product excit_repeat excit_cons excit_hilbert2d excit_slice excit_tleaf
# all tests # all tests
check_PROGRAMS = $(UNIT_TESTS) check_PROGRAMS = $(UNIT_TESTS)
......
...@@ -39,6 +39,7 @@ void test_alloc_init_cons(int window, excit_t sit) ...@@ -39,6 +39,7 @@ void test_alloc_init_cons(int window, excit_t sit)
excit_t create_test_cons(int window, excit_t sit) excit_t create_test_cons(int window, excit_t sit)
{ {
excit_t it; excit_t it;
it = excit_alloc_test(EXCIT_CONS); it = excit_alloc_test(EXCIT_CONS);
assert(excit_cons_init(it, excit_dup(sit), window) == ES); assert(excit_cons_init(it, excit_dup(sit), window) == ES);
return it; return it;
...@@ -54,19 +55,20 @@ void test_next_cons(int window, excit_t sit) ...@@ -54,19 +55,20 @@ void test_next_cons(int window, excit_t sit)
for (int i = 0; i < window; i++) { for (int i = 0; i < window; i++) {
new_sit[i] = excit_dup(sit); new_sit[i] = excit_dup(sit);
assert(new_sit[i] != NULL); assert(new_sit[i] != NULL);
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++)
assert(excit_skip(new_sit[i]) == ES); assert(excit_skip(new_sit[i]) == ES);
}
} }
assert(excit_dimension(it, &dim) == ES); assert(excit_dimension(it, &dim) == ES);
assert(excit_dimension(sit, &sdim) == ES); assert(excit_dimension(sit, &sdim) == ES);
indexes1 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes1 = (ssize_t *) malloc(dim * sizeof(ssize_t));
indexes2 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes2 = (ssize_t *) malloc(dim * sizeof(ssize_t));
while (excit_next(new_sit[window - 1], indexes2 + (window - 1) * sdim) == ES) { while (excit_next(new_sit[window - 1], indexes2 + (window - 1) * sdim)
== ES) {
for (int i = 0; i < window - 1; i++) { for (int i = 0; i < window - 1; i++) {
assert(excit_next(new_sit[i], indexes2 + i * sdim) == ES); assert(excit_next(new_sit[i], indexes2 + i * sdim) ==
ES);
} }
assert(excit_next(it, indexes1) == ES); assert(excit_next(it, indexes1) == ES);
assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t)) == 0); assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t)) == 0);
...@@ -88,10 +90,11 @@ void test_cons_iterator(int window, excit_t sit) ...@@ -88,10 +90,11 @@ void test_cons_iterator(int window, excit_t sit)
test_next_cons(window, sit); test_next_cons(window, sit);
int i = 0; int i = 0;
while (synthetic_tests[i]) { while (synthetic_tests[i]) {
excit_t it = create_test_cons(window, sit); excit_t it = create_test_cons(window, sit);
synthetic_tests[i](it); synthetic_tests[i] (it);
excit_free(it); excit_free(it);
i++; i++;
} }
...@@ -114,6 +117,6 @@ int main(int argc, char *argv[]) ...@@ -114,6 +117,6 @@ int main(int argc, char *argv[])
excit_free(it1); excit_free(it1);
excit_free(it2); excit_free(it2);
excit_free(it3); excit_free(it3);
return 0; return 0;
} }
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "excit.h"
#include "excit_test.h"
/* Helper functions from: https://en.wikipedia.org/wiki/Hilbert_curve */
//rotate/flip a quadrant appropriately
static void rot(ssize_t n, ssize_t *x, ssize_t *y, ssize_t rx, ssize_t ry)
{
if (ry == 0) {
if (rx == 1) {
*x = n - 1 - *x;
*y = n - 1 - *y;
}
//Swap x and y
ssize_t t = *x;
*x = *y;
*y = t;
}
}
//convert d to (x,y)
static void d2xy(ssize_t n, ssize_t d, ssize_t *x, ssize_t *y)
{
ssize_t rx, ry, s, t = d;
*x = *y = 0;
for (s = 1; s < n; s *= 2) {
rx = 1 & (t / 2);
ry = 1 & (t ^ rx);
rot(s, x, y, rx, ry);
*x += s * rx;
*y += s * ry;
t /= 4;
}
}
/* End helper functions */
void test_alloc_init_hilbert2d(int order)
{
excit_t it;
ssize_t dim, size;
it = excit_alloc_test(EXCIT_HILBERT2D);
assert(excit_dimension(it, &dim) == ES);
assert(dim == 0);
assert(excit_hilbert2d_init(it, order) == ES);
assert(excit_dimension(it, &dim) == ES);
assert(dim == 2);
assert(excit_size(it, &size) == ES);
assert(size == (1 << order) * (1 << order));
excit_free(it);
}
excit_t create_test_hilbert2d(int order)
{
excit_t it;
it = excit_alloc_test(EXCIT_HILBERT2D);
assert(excit_hilbert2d_init(it, order) == ES);
return it;
}
void test_next_hilbert2d(int order)
{
excit_t it = create_test_hilbert2d(order);
ssize_t indexes1[2], indexes2[2];
for (int i = 0; i < (1 << order) * (1 << order); i++) {
assert(excit_next(it, indexes1) == ES);
d2xy(1 << order, i, indexes2, indexes2 + 1);
assert(indexes1[0] == indexes2[0]);
assert(indexes1[1] == indexes2[1]);
}
excit_free(it);
}
void test_hilbert2d_iterator(int order)
{
test_alloc_init_hilbert2d(order);
test_next_hilbert2d(order);
int i = 0;
while (synthetic_tests[i]) {
excit_t it = create_test_hilbert2d(order);
synthetic_tests[i] (it);
excit_free(it);
i++;
}
}
int main(int argc, char *argv[])
{
test_hilbert2d_iterator(3);
test_hilbert2d_iterator(4);
}
...@@ -37,7 +37,7 @@ void test_alloc_init_prod(int count, excit_t *its) ...@@ -37,7 +37,7 @@ void test_alloc_init_prod(int count, excit_t *its)
expected_size *= size; expected_size *= size;
assert(excit_product_add_copy(it, its[i]) == ES); assert(excit_product_add_copy(it, its[i]) == ES);
assert(excit_product_count(it, &c) == ES); assert(excit_product_count(it, &c) == ES);
assert(c == i+1); assert(c == i + 1);
assert(excit_dimension(it, &dim) == ES); assert(excit_dimension(it, &dim) == ES);
assert(expected_dim == dim); assert(expected_dim == dim);
assert(excit_size(it, &size) == ES); assert(excit_size(it, &size) == ES);
...@@ -49,10 +49,10 @@ void test_alloc_init_prod(int count, excit_t *its) ...@@ -49,10 +49,10 @@ void test_alloc_init_prod(int count, excit_t *its)
excit_t create_test_product(int count, excit_t *its) excit_t create_test_product(int count, excit_t *its)
{ {
excit_t it; excit_t it;
it = excit_alloc_test(EXCIT_PRODUCT); it = excit_alloc_test(EXCIT_PRODUCT);
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++)
assert(excit_product_add_copy(it, its[i]) == ES); assert(excit_product_add_copy(it, its[i]) == ES);
}
return it; return it;
} }
...@@ -62,7 +62,9 @@ void test_next_product_helper(int count, excit_t it, excit_t *its, ...@@ -62,7 +62,9 @@ void test_next_product_helper(int count, excit_t it, excit_t *its,
{ {
if (count == 0) { if (count == 0) {
assert(excit_next(it, indexes1) == ES); assert(excit_next(it, indexes1) == ES);
assert(memcmp(indexes1, indexes2, (intptr_t)cindexes2 - (intptr_t)indexes2) == 0); assert(memcmp
(indexes1, indexes2,
(intptr_t) cindexes2 - (intptr_t) indexes2) == 0);
} else { } else {
excit_t cit; excit_t cit;
ssize_t dim; ssize_t dim;
...@@ -70,8 +72,8 @@ void test_next_product_helper(int count, excit_t it, excit_t *its, ...@@ -70,8 +72,8 @@ void test_next_product_helper(int count, excit_t it, excit_t *its,
cit = excit_dup(*its); cit = excit_dup(*its);
assert(cit != NULL); assert(cit != NULL);
assert( excit_dimension(cit, &dim) == ES); assert(excit_dimension(cit, &dim) == ES);
while(excit_next(cit, cindexes2) == ES) { while (excit_next(cit, cindexes2) == ES) {
test_next_product_helper(count - 1, it, its + 1, test_next_product_helper(count - 1, it, its + 1,
indexes1, indexes2, indexes1, indexes2,
cindexes2 + dim); cindexes2 + dim);
...@@ -89,8 +91,8 @@ void test_next_product(int count, excit_t *its) ...@@ -89,8 +91,8 @@ void test_next_product(int count, excit_t *its)
it = create_test_product(count, its); it = create_test_product(count, its);
assert(excit_dimension(it, &dim) == ES); assert(excit_dimension(it, &dim) == ES);
indexes1 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes1 = (ssize_t *) malloc(dim * sizeof(ssize_t));
indexes2 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes2 = (ssize_t *) malloc(dim * sizeof(ssize_t));
test_next_product_helper(count, it, its, indexes1, indexes2, indexes2); test_next_product_helper(count, it, its, indexes1, indexes2, indexes2);
assert(excit_next(it, NULL) == EXCIT_STOPIT); assert(excit_next(it, NULL) == EXCIT_STOPIT);
...@@ -108,10 +110,11 @@ void test_product_iterator(int count, excit_t *its) ...@@ -108,10 +110,11 @@ void test_product_iterator(int count, excit_t *its)
test_next_product(count, its); test_next_product(count, its);
int i = 0; int i = 0;
while (synthetic_tests[i]) { while (synthetic_tests[i]) {
excit_t it = create_test_product(count, its); excit_t it = create_test_product(count, its);
synthetic_tests[i](it); synthetic_tests[i] (it);
excit_free(it); excit_free(it);
i++; i++;
} }
...@@ -123,7 +126,7 @@ void test_product_split_dim(void) ...@@ -123,7 +126,7 @@ void test_product_split_dim(void)
excit_t its[3]; excit_t its[3];
excit_t new_its[3]; excit_t new_its[3];
ssize_t indexes[3]; ssize_t indexes[3];
its[0] = create_test_range(0, 3, 1); its[0] = create_test_range(0, 3, 1);
its[1] = create_test_range(1, -1, -1); its[1] = create_test_range(1, -1, -1);
its[2] = create_test_range(-5, 5, 1); its[2] = create_test_range(-5, 5, 1);
...@@ -213,13 +216,14 @@ void test_product_split_dim(void) ...@@ -213,13 +216,14 @@ void test_product_split_dim(void)
excit_free(its[0]); excit_free(its[0]);
excit_free(its[1]); excit_free(its[1]);
excit_free(its[2]); excit_free(its[2]);
excit_free(it); excit_free(it);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
excit_t its[4]; excit_t its[4];
its[0] = create_test_range(0, 3, 1); its[0] = create_test_range(0, 3, 1);
test_product_iterator(1, its); test_product_iterator(1, its);
its[1] = create_test_range(1, -1, -1); its[1] = create_test_range(1, -1, -1);
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "excit.h" #include "excit.h"
#include "excit_test.h" #include "excit_test.h"
void test_alloc_init_range(ssize_t start, ssize_t stop, ssize_t step) { void test_alloc_init_range(ssize_t start, ssize_t stop, ssize_t step)
{
excit_t it; excit_t it;
ssize_t dim; ssize_t dim;
...@@ -18,7 +19,8 @@ void test_alloc_init_range(ssize_t start, ssize_t stop, ssize_t step) { ...@@ -18,7 +19,8 @@ void test_alloc_init_range(ssize_t start, ssize_t stop, ssize_t step) {
excit_free(it); excit_free(it);
} }
excit_t create_test_range(ssize_t start, ssize_t stop, ssize_t step) { excit_t create_test_range(ssize_t start, ssize_t stop, ssize_t step)
{
excit_t it; excit_t it;
it = excit_alloc_test(EXCIT_RANGE); it = excit_alloc_test(EXCIT_RANGE);
...@@ -39,8 +41,7 @@ void test_next_range(ssize_t start, ssize_t stop, ssize_t step) ...@@ -39,8 +41,7 @@ void test_next_range(ssize_t start, ssize_t stop, ssize_t step)
for (int i = start; i >= stop; i += step) { for (int i = start; i >= stop; i += step) {
assert(excit_next(it, indexes) == ES); assert(excit_next(it, indexes) == ES);
assert(indexes[0] == i); assert(indexes[0] == i);
} } else
else
for (int i = start; i <= stop; i += step) { for (int i = start; i <= stop; i += step) {
assert(excit_next(it, indexes) == ES); assert(excit_next(it, indexes) == ES);
assert(indexes[0] == i); assert(indexes[0] == i);
...@@ -49,7 +50,6 @@ void test_next_range(ssize_t start, ssize_t stop, ssize_t step) ...@@ -49,7 +50,6 @@ void test_next_range(ssize_t start, ssize_t stop, ssize_t step)
excit_free(it); excit_free(it);
} }
void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step) void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step)
{ {
test_alloc_init_range(start, stop, step); test_alloc_init_range(start, stop, step);
...@@ -57,10 +57,11 @@ void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step) ...@@ -57,10 +57,11 @@ void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step)
test_next_range(start, stop, step); test_next_range(start, stop, step);
int i = 0; int i = 0;
while (synthetic_tests[i]) { while (synthetic_tests[i]) {
excit_t it = create_test_range(start, stop, step); excit_t it = create_test_range(start, stop, step);
synthetic_tests[i](it); synthetic_tests[i] (it);
excit_free(it); excit_free(it);
i++; i++;
} }
...@@ -68,6 +69,7 @@ void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step) ...@@ -68,6 +69,7 @@ void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
test_range_iterator(4, 12, 3);
test_range_iterator(0, 3, 1); test_range_iterator(0, 3, 1);
test_range_iterator(0, 6, 2); test_range_iterator(0, 6, 2);
test_range_iterator(-15, 14, 2); test_range_iterator(-15, 14, 2);
......
...@@ -38,6 +38,7 @@ void test_alloc_init_repeat(int repeat, excit_t sit) ...@@ -38,6 +38,7 @@ void test_alloc_init_repeat(int repeat, excit_t sit)
excit_t create_test_repeat(int repeat, excit_t sit) excit_t create_test_repeat(int repeat, excit_t sit)
{ {
excit_t it; excit_t it;
it = excit_alloc_test(EXCIT_REPEAT); it = excit_alloc_test(EXCIT_REPEAT);
assert(excit_repeat_init(it, excit_dup(sit), repeat) == ES); assert(excit_repeat_init(it, excit_dup(sit), repeat) == ES);
return it; return it;
...@@ -53,14 +54,15 @@ void test_next_repeat(int repeat, excit_t sit) ...@@ -53,14 +54,15 @@ void test_next_repeat(int repeat, excit_t sit)
new_sit = excit_dup(sit); new_sit = excit_dup(sit);
assert(excit_dimension(it, &dim) == ES); assert(excit_dimension(it, &dim) == ES);
indexes1 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes1 = (ssize_t *) malloc(dim * sizeof(ssize_t));
indexes2 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes2 = (ssize_t *) malloc(dim * sizeof(ssize_t));
while (excit_next(new_sit, indexes1) == ES) while (excit_next(new_sit, indexes1) == ES)
for (int i = 0; i < repeat; i++) { for (int i = 0; i < repeat; i++) {
assert(excit_next(it, indexes2) == ES); assert(excit_next(it, indexes2) == ES);
assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t)) == 0); assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t))
== 0);
} }
assert(excit_next(it, indexes2) == EXCIT_STOPIT); assert(excit_next(it, indexes2) == EXCIT_STOPIT);
...@@ -79,16 +81,18 @@ void test_repeat_split(int repeat, excit_t sit) ...@@ -79,16 +81,18 @@ void test_repeat_split(int repeat, excit_t sit)
ssize_t dim; ssize_t dim;
assert(excit_dimension(it, &dim) == ES); assert(excit_dimension(it, &dim) == ES);
indexes1 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes1 = (ssize_t *) malloc(dim * sizeof(ssize_t));
indexes2 = (ssize_t *)malloc(dim * sizeof(ssize_t)); indexes2 = (ssize_t *) malloc(dim * sizeof(ssize_t));
assert( excit_split(sit, 3, new_sits) == ES ); assert(excit_split(sit, 3, new_sits) == ES);
assert( excit_repeat_split(it, 3, new_its) == ES ); assert(excit_repeat_split(it, 3, new_its) == ES);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
while (excit_next(new_sits[i], indexes1) == ES) { while (excit_next(new_sits[i], indexes1) == ES) {
for (int j = 0; j < repeat; j++) { for (int j = 0; j < repeat; j++) {
assert(excit_next(new_its[i], indexes2) == ES); assert(excit_next(new_its[i], indexes2) == ES);
assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t)) == 0); assert(memcmp
(indexes1, indexes2,
dim * sizeof(ssize_t)) == 0);
} }
} }
assert(excit_next(new_its[i], indexes2) == EXCIT_STOPIT); assert(excit_next(new_its[i], indexes2) == EXCIT_STOPIT);
...@@ -111,10 +115,11 @@ void test_repeat_iterator(int repeat, excit_t sit) ...@@ -111,10 +115,11 @@ void test_repeat_iterator(int repeat, excit_t sit)
test_repeat_split(repeat, sit); test_repeat_split(repeat, sit);
int i = 0; int i = 0;
while (synthetic_tests[i]) { while (synthetic_tests[i]) {
excit_t it = create_test_repeat(repeat, sit); excit_t it = create_test_repeat(repeat, sit);
synthetic_tests[i](it); synthetic_tests[i] (it);
excit_free(it); excit_free(it);
i++; i++;
} }
......
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "excit.h"
#include "excit_test.h"
excit_t create_test_range(ssize_t start, ssize_t stop, ssize_t step)
{
excit_t it;
it = excit_alloc_test(EXCIT_RANGE);
assert(excit_range_init(it, start, stop, step) == ES);
return it;
}
void test_alloc_init_slice(excit_t source, excit_t indexer)
{
excit_t it;
ssize_t dim, expected_dim, size, expected_size;
it = excit_alloc_test(EXCIT_SLICE);
assert(excit_dimension(it, &dim) == ES);
assert(dim == 0);
assert(excit_slice_init(it, excit_dup(source), excit_dup(indexer)) ==
ES);
assert(excit_dimension(it, &dim) == ES);
assert(excit_dimension(source, &expected_dim) == ES);
assert(dim == expected_dim);
assert(excit_size(it, &size) == ES);
assert(excit_size(indexer, &expected_size) == ES);
assert(size == expected_size);
excit_free(it);
}
excit_t create_test_slice(excit_t source, excit_t indexer)
{
excit_t it;
it = excit_alloc_test(EXCIT_SLICE);
assert(excit_slice_init(it, excit_dup(source), excit_dup(indexer)) ==
ES);
return it;
}
void test_next_slice(excit_t source, excit_t indexer)
{
excit_t it = create_test_slice(source, indexer);
excit_t iit = excit_dup(indexer);
ssize_t *indexes1, *indexes2;
ssize_t index;
ssize_t dim;
assert(excit_dimension(source, &dim) == ES);
indexes1 = (ssize_t *) malloc(dim * sizeof(ssize_t));
indexes2 = (ssize_t *) malloc(dim * sizeof(ssize_t));
while (excit_next(iit, &index) == ES) {
assert(excit_nth(source, index, indexes2) == ES);
assert(excit_next(it, indexes1) == ES);
assert(memcmp(indexes1, indexes2, dim * sizeof(ssize_t)) == 0);
}
assert(excit_next(it, indexes1) == EXCIT_STOPIT);
free(indexes1);
free(indexes2);
excit_free(it);
excit_free(iit);
}
void test_slice_iterator(excit_t source, excit_t indexer)
{
test_alloc_init_slice(source, indexer);
test_next_slice(source, indexer);
int i = 0;
while (synthetic_tests[i]) {
excit_t it = create_test_slice(source, indexer);
synthetic_tests[i] (it);
excit_free(it);
i++;
}
}
int main(int argc, char *argv[])
{
excit_t source, indexer, source2, indexer2;
source = create_test_range(-15, 14, 2);
indexer = create_test_range(4, 12, 3);
test_slice_iterator(source, indexer);
source2 = excit_alloc_test(EXCIT_PRODUCT);
assert(excit_product_add(source2, create_test_range(-15, 14, 2)) == ES);
assert(excit_product_add(source2, create_test_range(4, 12, 3)) == ES);
indexer2 = create_test_range(4, 35, 2);
test_slice_iterator(source2, indexer2);
excit_free(source);
excit_free(source2);
excit_free(indexer);
excit_free(indexer2);
}
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
excit_t excit_alloc_test(enum excit_type_e type) { excit_t excit_alloc_test(enum excit_type_e type)
{
excit_t it; excit_t it;
enum excit_type_e newtype; enum excit_type_e newtype;
...@@ -16,23 +17,29 @@ excit_t excit_alloc_test(enum excit_type_e type) { ...@@ -16,23 +17,29 @@ excit_t excit_alloc_test(enum excit_type_e type) {
return it; return it;
} }
static inline excit_t excit_dup_test(const excit_t it) { static inline excit_t excit_dup_test(const excit_t it)
{
excit_t newit = excit_dup(it); excit_t newit = excit_dup(it);
assert(newit != NULL); assert(newit != NULL);
return newit; return newit;
} }
static inline void excit_dimension_test(excit_t it, ssize_t *dim) { static inline void excit_dimension_test(excit_t it, ssize_t *dim)
assert( excit_dimension(it, dim) == ES ); {
assert(excit_dimension(it, dim) == ES);
} }
static inline void deplete_iterator(excit_t it) { static inline void deplete_iterator(excit_t it)
while(excit_next(it, NULL) == ES) {
while (excit_next(it, NULL) == ES)
; ;
} }
static void test_iterator_result_equal(excit_t it1, excit_t it2) { static void test_iterator_result_equal(excit_t it1, excit_t it2)
{
ssize_t dim1, dim2; ssize_t dim1, dim2;
excit_dimension_test(it1, &dim1); excit_dimension_test(it1, &dim1);
excit_dimension_test(it2, &dim2); excit_dimension_test(it2, &dim2);
assert(dim1 == dim2);