Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
excit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
excit
Commits
711bc674
Commit
711bc674
authored
Jan 10, 2019
by
Nicolas Denoyelle
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into tleaf
parents
b98f68c0
e7610669
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
359 additions
and
107 deletions
+359
-107
.gitignore
.gitignore
+1
-0
src/hilbert2d.c
src/hilbert2d.c
+3
-0
src/slice.c
src/slice.c
+1
-1
tests/Makefile.am
tests/Makefile.am
+3
-1
tests/excit_cons.c
tests/excit_cons.c
+11
-8
tests/excit_hilbert2d.c
tests/excit_hilbert2d.c
+107
-0
tests/excit_product.c
tests/excit_product.c
+15
-11
tests/excit_range.c
tests/excit_range.c
+8
-6
tests/excit_repeat.c
tests/excit_repeat.c
+15
-10
tests/excit_slice.c
tests/excit_slice.c
+111
-0
tests/excit_test.c
tests/excit_test.c
+83
-68
tests/excit_test.h
tests/excit_test.h
+1
-2
No files found.
.gitignore
View file @
711bc674
...
...
@@ -47,6 +47,7 @@ stamp-h1
/install-sh
/missing
/stamp-h1
libexcit.pc
# autotest
tests/*.trs
...
...
src/hilbert2d.c
View file @
711bc674
#include "dev/excit.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
)
{
if
(
ry
==
0
)
{
...
...
src/slice.c
View file @
711bc674
...
...
@@ -126,7 +126,7 @@ static int slice_it_split(const excit_t data, ssize_t n, excit_t *results)
err
=
-
EXCIT_ENOMEM
;
goto
error
;
}
err
=
excit_slice_init
(
results
[
i
],
tmp
,
tmp2
);
err
=
excit_slice_init
(
results
[
i
],
tmp
2
,
tmp
);
if
(
err
)
{
excit_free
(
tmp
);
excit_free
(
tmp2
);
...
...
tests/Makefile.am
View file @
711bc674
...
...
@@ -11,8 +11,10 @@ excit_product_SOURCES = $(LIBHSOURCES) $(LIBCSOURCES) excit_product.c
excit_repeat_SOURCES
=
$(LIBHSOURCES)
$(LIBCSOURCES)
excit_repeat.c
excit_cons_SOURCES
=
$(LIBHSOURCES)
$(LIBCSOURCES)
excit_cons.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
check_PROGRAMS
=
$(UNIT_TESTS)
...
...
tests/excit_cons.c
View file @
711bc674
...
...
@@ -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
it
;
it
=
excit_alloc_test
(
EXCIT_CONS
);
assert
(
excit_cons_init
(
it
,
excit_dup
(
sit
),
window
)
==
ES
);
return
it
;
...
...
@@ -54,19 +55,20 @@ void test_next_cons(int window, excit_t sit)
for
(
int
i
=
0
;
i
<
window
;
i
++
)
{
new_sit
[
i
]
=
excit_dup
(
sit
);
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_dimension
(
it
,
&
dim
)
==
ES
);
assert
(
excit_dimension
(
sit
,
&
sdim
)
==
ES
);
indexes1
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes2
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes1
=
(
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
++
)
{
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
(
memcmp
(
indexes1
,
indexes2
,
dim
*
sizeof
(
ssize_t
))
==
0
);
...
...
@@ -88,10 +90,11 @@ void test_cons_iterator(int window, excit_t sit)
test_next_cons
(
window
,
sit
);
int
i
=
0
;
while
(
synthetic_tests
[
i
])
{
excit_t
it
=
create_test_cons
(
window
,
sit
);
synthetic_tests
[
i
](
it
);
synthetic_tests
[
i
]
(
it
);
excit_free
(
it
);
i
++
;
}
...
...
@@ -114,6 +117,6 @@ int main(int argc, char *argv[])
excit_free
(
it1
);
excit_free
(
it2
);
excit_free
(
it3
);
return
0
;
}
tests/excit_hilbert2d.c
0 → 100644
View file @
711bc674
#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
);
}
tests/excit_product.c
View file @
711bc674
...
...
@@ -37,7 +37,7 @@ void test_alloc_init_prod(int count, excit_t *its)
expected_size
*=
size
;
assert
(
excit_product_add_copy
(
it
,
its
[
i
])
==
ES
);
assert
(
excit_product_count
(
it
,
&
c
)
==
ES
);
assert
(
c
==
i
+
1
);
assert
(
c
==
i
+
1
);
assert
(
excit_dimension
(
it
,
&
dim
)
==
ES
);
assert
(
expected_dim
==
dim
);
assert
(
excit_size
(
it
,
&
size
)
==
ES
);
...
...
@@ -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
it
;
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
);
}
return
it
;
}
...
...
@@ -62,7 +62,9 @@ void test_next_product_helper(int count, excit_t it, excit_t *its,
{
if
(
count
==
0
)
{
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
{
excit_t
cit
;
ssize_t
dim
;
...
...
@@ -70,8 +72,8 @@ void test_next_product_helper(int count, excit_t it, excit_t *its,
cit
=
excit_dup
(
*
its
);
assert
(
cit
!=
NULL
);
assert
(
excit_dimension
(
cit
,
&
dim
)
==
ES
);
while
(
excit_next
(
cit
,
cindexes2
)
==
ES
)
{
assert
(
excit_dimension
(
cit
,
&
dim
)
==
ES
);
while
(
excit_next
(
cit
,
cindexes2
)
==
ES
)
{
test_next_product_helper
(
count
-
1
,
it
,
its
+
1
,
indexes1
,
indexes2
,
cindexes2
+
dim
);
...
...
@@ -89,8 +91,8 @@ void test_next_product(int count, excit_t *its)
it
=
create_test_product
(
count
,
its
);
assert
(
excit_dimension
(
it
,
&
dim
)
==
ES
);
indexes1
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes2
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes1
=
(
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
);
assert
(
excit_next
(
it
,
NULL
)
==
EXCIT_STOPIT
);
...
...
@@ -108,10 +110,11 @@ void test_product_iterator(int count, excit_t *its)
test_next_product
(
count
,
its
);
int
i
=
0
;
while
(
synthetic_tests
[
i
])
{
excit_t
it
=
create_test_product
(
count
,
its
);
synthetic_tests
[
i
](
it
);
synthetic_tests
[
i
]
(
it
);
excit_free
(
it
);
i
++
;
}
...
...
@@ -123,7 +126,7 @@ void test_product_split_dim(void)
excit_t
its
[
3
];
excit_t
new_its
[
3
];
ssize_t
indexes
[
3
];
its
[
0
]
=
create_test_range
(
0
,
3
,
1
);
its
[
1
]
=
create_test_range
(
1
,
-
1
,
-
1
);
its
[
2
]
=
create_test_range
(
-
5
,
5
,
1
);
...
...
@@ -213,13 +216,14 @@ void test_product_split_dim(void)
excit_free
(
its
[
0
]);
excit_free
(
its
[
1
]);
excit_free
(
its
[
2
]);
excit_free
(
it
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
excit_t
its
[
4
];
its
[
0
]
=
create_test_range
(
0
,
3
,
1
);
test_product_iterator
(
1
,
its
);
its
[
1
]
=
create_test_range
(
1
,
-
1
,
-
1
);
...
...
tests/excit_range.c
View file @
711bc674
...
...
@@ -4,7 +4,8 @@
#include "excit.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
;
ssize_t
dim
;
...
...
@@ -18,7 +19,8 @@ void test_alloc_init_range(ssize_t start, ssize_t stop, ssize_t step) {
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
;
it
=
excit_alloc_test
(
EXCIT_RANGE
);
...
...
@@ -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
)
{
assert
(
excit_next
(
it
,
indexes
)
==
ES
);
assert
(
indexes
[
0
]
==
i
);
}
else
}
else
for
(
int
i
=
start
;
i
<=
stop
;
i
+=
step
)
{
assert
(
excit_next
(
it
,
indexes
)
==
ES
);
assert
(
indexes
[
0
]
==
i
);
...
...
@@ -49,7 +50,6 @@ void test_next_range(ssize_t start, ssize_t stop, ssize_t step)
excit_free
(
it
);
}
void
test_range_iterator
(
ssize_t
start
,
ssize_t
stop
,
ssize_t
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)
test_next_range
(
start
,
stop
,
step
);
int
i
=
0
;
while
(
synthetic_tests
[
i
])
{
excit_t
it
=
create_test_range
(
start
,
stop
,
step
);
synthetic_tests
[
i
](
it
);
synthetic_tests
[
i
]
(
it
);
excit_free
(
it
);
i
++
;
}
...
...
@@ -68,6 +69,7 @@ void test_range_iterator(ssize_t start, ssize_t stop, ssize_t step)
int
main
(
int
argc
,
char
*
argv
[])
{
test_range_iterator
(
4
,
12
,
3
);
test_range_iterator
(
0
,
3
,
1
);
test_range_iterator
(
0
,
6
,
2
);
test_range_iterator
(
-
15
,
14
,
2
);
...
...
tests/excit_repeat.c
View file @
711bc674
...
...
@@ -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
it
;
it
=
excit_alloc_test
(
EXCIT_REPEAT
);
assert
(
excit_repeat_init
(
it
,
excit_dup
(
sit
),
repeat
)
==
ES
);
return
it
;
...
...
@@ -53,14 +54,15 @@ void test_next_repeat(int repeat, excit_t sit)
new_sit
=
excit_dup
(
sit
);
assert
(
excit_dimension
(
it
,
&
dim
)
==
ES
);
indexes1
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes2
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes1
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes2
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
while
(
excit_next
(
new_sit
,
indexes1
)
==
ES
)
for
(
int
i
=
0
;
i
<
repeat
;
i
++
)
{
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
);
...
...
@@ -79,16 +81,18 @@ void test_repeat_split(int repeat, excit_t sit)
ssize_t
dim
;
assert
(
excit_dimension
(
it
,
&
dim
)
==
ES
);
indexes1
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes2
=
(
ssize_t
*
)
malloc
(
dim
*
sizeof
(
ssize_t
));
indexes1
=
(
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_repeat_split
(
it
,
3
,
new_its
)
==
ES
);
assert
(
excit_split
(
sit
,
3
,
new_sits
)
==
ES
);
assert
(
excit_repeat_split
(
it
,
3
,
new_its
)
==
ES
);
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
while
(
excit_next
(
new_sits
[
i
],
indexes1
)
==
ES
)
{
for
(
int
j
=
0
;
j
<
repeat
;
j
++
)
{
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
);
...
...
@@ -111,10 +115,11 @@ void test_repeat_iterator(int repeat, excit_t sit)
test_repeat_split
(
repeat
,
sit
);
int
i
=
0
;
while
(
synthetic_tests
[
i
])
{
excit_t
it
=
create_test_repeat
(
repeat
,
sit
);
synthetic_tests
[
i
](
it
);
synthetic_tests
[
i
]
(
it
);
excit_free
(
it
);
i
++
;
}
...
...
tests/excit_slice.c
0 → 100644
View file @
711bc674
#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
);
}
tests/excit_test.c
View file @
711bc674
...
...
@@ -5,7 +5,8 @@
#include <string.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
;
enum
excit_type_e
newtype
;
...
...
@@ -16,23 +17,29 @@ excit_t excit_alloc_test(enum excit_type_e type) {
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
);
assert
(
newit
!=
NULL
);
return
newit
;
}
static
inline
void
excit_dimension_test
(
excit_t
it
,
ssize_t
*
dim
)
{
assert
(
excit_dimension
(
it
,
dim
)
==
ES
);
static
inline
void
excit_dimension_test
(
excit_t
it
,
ssize_t
*
dim
)
{
assert
(
excit_dimension
(
it
,
dim
)
==
ES
);
}
static
inline
void
deplete_iterator
(
excit_t
it
)
{
while
(
excit_next
(
it
,
NULL
)
==
ES
)
static
inline
void
deplete_iterator
(
excit_t
it
)
{
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
;
excit_dimension_test
(
it1
,
&
dim1
);
excit_dimension_test
(
it2
,
&
dim2
);
assert
(
dim1
==
dim2
);
...
...
@@ -40,40 +47,42 @@ static void test_iterator_result_equal(excit_t it1, excit_t it2) {
ssize_t
*
indexes1
,
*
indexes2
;
ssize_t
buff_dim
=
dim1
*
sizeof
(
ssize_t
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
while
(
excit_next
(
it1
,
indexes1
)
==
ES
)
{
assert
(
excit_next
(
it2
,
indexes2
)
==
ES
);
assert
(
memcmp
(
indexes1
,
indexes2
,
buff_dim
)
==
0
);
}
assert
(
excit_next
(
it2
,
indexes2
)
==
EXCIT_STOPIT
);
assert
(
excit_next
(
it2
,
indexes2
)
==
EXCIT_STOPIT
);
free
(
indexes1
);
free
(
indexes2
);
}
void
test_dup
(
excit_t
it1
)
{
void
test_dup
(
excit_t
it1
)
{
excit_t
it2
,
it3
;
it2
=
excit_dup_test
(
it1
);
it2
=
excit_dup_test
(
it1
);
it3
=
excit_dup_test
(
it1
);
test_iterator_result_equal
(
it1
,
it2
);
excit_free
(
it2
);
excit_free
(
it2
);
/* Check that the state is correctly copied */
assert
(
excit_next
(
it3
,
NULL
)
==
ES
);
/* Check that the state is correctly copied */
assert
(
excit_next
(
it3
,
NULL
)
==
ES
);
it2
=
excit_dup
(
it3
);
test_iterator_result_equal
(
it3
,
it2
);
excit_free
(
it2
);
excit_free
(
it3
);
}
void
test_rewind
(
excit_t
it1
)
{
void
test_rewind
(
excit_t
it1
)
{
excit_t
it2
,
it3
;
it2
=
excit_dup_test
(
it1
);
it2
=
excit_dup_test
(
it1
);
it3
=
excit_dup_test
(
it1
);
assert
(
excit_next
(
it1
,
NULL
)
==
ES
);
...
...
@@ -88,18 +97,21 @@ void test_rewind(excit_t it1) {
excit_free
(
it3
);
}
void
test_peek
(
excit_t
it1
)
{
void
test_peek
(
excit_t
it1
)
{
excit_t
it2
;
it2
=
excit_dup_test
(
it1
);
ssize_t
dim1
;
excit_dimension_test
(
it1
,
&
dim1
);
ssize_t
*
indexes1
,
*
indexes2
;
ssize_t
buff_dim
=
dim1
*
sizeof
(
ssize_t
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
while
(
excit_next
(
it1
,
indexes1
)
==
ES
)
{
assert
(
excit_peek
(
it2
,
indexes2
)
==
ES
);
...
...
@@ -108,14 +120,15 @@ void test_peek(excit_t it1) {
assert
(
memcmp
(
indexes1
,
indexes2
,
buff_dim
)
==
0
);
}
assert
(
excit_peek
(
it2
,
indexes2
)
==
EXCIT_STOPIT
);
assert
(
excit_next
(
it2
,
indexes2
)
==
EXCIT_STOPIT
);
assert
(
excit_next
(
it2
,
indexes2
)
==
EXCIT_STOPIT
);
free
(
indexes1
);
free
(
indexes2
);
excit_free
(
it2
);
}
void
test_size
(
excit_t
it
)
{
void
test_size
(
excit_t
it
)
{
ssize_t
size
;
ssize_t
count
=
0
;
int
err
;
...
...
@@ -125,27 +138,28 @@ void test_size(excit_t it) {
return
;
assert
(
err
==
ES
);
while
(
excit_next
(
it
,
NULL
)
==
ES
)
{
while
(
excit_next
(
it
,
NULL
)
==
ES
)
count
++
;
}
assert
(
size
==
count
);
assert
(
size
==
count
);
}
void
test_cyclic_next
(
excit_t
it1
)
{
void
test_cyclic_next
(
excit_t
it1
)
{
excit_t
it2
,
it3
;
int
looped
=
0
;
it2
=
excit_dup_test
(
it1
);
it2
=
excit_dup_test
(
it1
);
it3
=
excit_dup_test
(
it1
);
ssize_t
dim1
;
excit_dimension_test
(
it1
,
&
dim1
);
ssize_t
*
indexes1
,
*
indexes2
;
ssize_t
buff_dim
=
dim1
*
sizeof
(
ssize_t
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes1
=
(
ssize_t
*
)
malloc
(
buff_dim
);
indexes2
=
(
ssize_t
*
)
malloc
(
buff_dim
);
while
(
excit_next
(
it1
,
indexes1
)
==
ES
)
{
assert
(
looped
==
0
);
...
...
@@ -162,20 +176,21 @@ void test_cyclic_next(excit_t it1) {
excit_free
(
it3
);
}
void
test_skip
(
excit_t
it1
)
{
void
test_skip
(
excit_t
it1
)
{
excit_t
it2
;
it2
=
excit_dup_test
(
it1
);
it2
=
excit_dup_test
(
it1
);
while
(
excit_next
(
it1
,
NULL
)
==
ES
)
{
assert
(
excit_skip
(
it2
)
==
ES
);
}
assert
(
excit_skip
(
it2
)
==
EXCIT_STOPIT
);
while
(
excit_next
(
it1
,
NULL
)
==
ES
)