From 9ab90be6d42d75117972eff195edb7a4c9a03d2c Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 9 May 2022 20:12:55 +0200 Subject: [PATCH] Add check of B+Tree / Set --- tests/check-bptree-set.cpp | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/check-bptree-set.cpp diff --git a/tests/check-bptree-set.cpp b/tests/check-bptree-set.cpp new file mode 100644 index 00000000..c0c827db --- /dev/null +++ b/tests/check-bptree-set.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021-2022-2022, Patrick Pelissier + * All rights reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +#include +#include "m-bptree.h" + +BPTREE_DEF(tree_int, 5, int) + +// Transform an integer 'i' into a M*LIB base item 'a' +#define TYPE_SET_INT(a, i) (a) = (i) + +// Container OPLIST +#define CONT_OPL BPTREE_OPLIST(tree_int, M_OPL_int()) + +// C++ Base class of the item in the container +#define BASE_CLASS int + +// Transform an integer 'i' into a C++ base item 'a' +#define CLASS_SET_INT(a, i) (a) = (i) + +// C++ Container class +#define CONT_CLASS std::set + +// Compare the M*LIB container a to the C++ container b +#define CMP_CONT(a, b) cmp_cont(a, b) + +// Compate the M*LIB base object to the C++ base object +#define CMP_BASE(a, b) assert( (a) == (b) ) + +void cmp_cont(const tree_int_t a, const std::set &b) +{ + tree_int_it_t ita; + tree_int_it(ita, a); + auto itb = b.begin(); + while (itb != b.end()) { + assert(!tree_int_end_p(ita)); + const int *b0 = tree_int_cref(ita); + const int &b1 = *itb; + CMP_BASE(*b0, b1); + itb++; + tree_int_next(ita); + } + assert(tree_int_end_p(ita)); +} + +#define DEFAULT_NUMBER 1000000 + +#define push_back insert +#include "check-generic.hpp"