From 236982c2b6de619f0744c9c17ea7208b64a4afb3 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 29 Jun 2014 15:26:58 +0200 Subject: Add skiplist unit tests --- src/test/skiplist_tests.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/test/skiplist_tests.cpp (limited to 'src/test/skiplist_tests.cpp') diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp new file mode 100644 index 0000000000..ea301685c9 --- /dev/null +++ b/src/test/skiplist_tests.cpp @@ -0,0 +1,45 @@ +// Copyright (c) 2014 The Bitcoin Core developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include "main.h" +#include "util.h" + + +#define SKIPLIST_LENGTH 300000 + +BOOST_AUTO_TEST_SUITE(skiplist_tests) + +BOOST_AUTO_TEST_CASE(skiplist_test) +{ + std::vector vIndex(SKIPLIST_LENGTH); + + for (int i=0; i 0) { + BOOST_CHECK(vIndex[i].pskip == &vIndex[vIndex[i].pskip->nHeight]); + BOOST_CHECK(vIndex[i].pskip->nHeight < i); + } else { + BOOST_CHECK(vIndex[i].pskip == NULL); + } + } + + for (int i=0; i < 1000; i++) { + int from = insecure_rand() % (SKIPLIST_LENGTH - 1); + int to = insecure_rand() % (from + 1); + + BOOST_CHECK(vIndex[SKIPLIST_LENGTH - 1].GetAncestor(from) == &vIndex[from]); + BOOST_CHECK(vIndex[from].GetAncestor(to) == &vIndex[to]); + BOOST_CHECK(vIndex[from].GetAncestor(0) == &vIndex[0]); + } +} + +BOOST_AUTO_TEST_SUITE_END() + -- cgit v1.2.3