commit 9c11749ab9ad18b91a459dbe46ef920a55201985
parent 9000cccded657cc3713869fd9643efbc4cf3effe
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 4 May 2018 15:50:23 +0200
Push further the for_each_leaf test on binary trees
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/test_svx_bintree.c b/src/test_svx_bintree.c
@@ -18,7 +18,6 @@
#include "test_svx_utils.h"
#include <rsys/math.h>
-
struct leaves_context {
double lower;
double upper;
@@ -26,7 +25,8 @@ struct leaves_context {
size_t depth;
enum svx_axis axis;
- size_t count;
+ char* leaves;
+ size_t nleaves;
};
static void
@@ -94,7 +94,9 @@ check_leaves
CHK(eq_eps(lower+delta, leaf->upper[ctx->axis], 1.e-6));
CHK(leaf->depth == ctx->depth - 1);
- ctx->count += 1;
+ CHK(ctx->leaves[ileaf] == 0);
+ ctx->leaves[ileaf] = 1;
+ ctx->nleaves += 1;
}
int
@@ -169,9 +171,12 @@ main(int argc, char** argv)
ctx.nvoxels = nvxls;
ctx.depth = 4;
ctx.axis = SVX_AXIS_Y;
- ctx.count = 0;
+
+ ctx.nleaves = 0;
+ CHK(ctx.leaves = MEM_CALLOC(&allocator, 5, 1));
CHK(svx_tree_for_each_leaf(tree, check_leaves, &ctx) == RES_OK);
- CHK(ctx.count == 5);
+ CHK(ctx.nleaves == 5);
+ MEM_RM(&allocator, ctx.leaves);
CHK(svx_tree_get_desc(NULL, &tree_desc) == RES_BAD_ARG);
CHK(svx_tree_get_desc(tree, NULL) == RES_BAD_ARG);