From 17b11428c135203342aff38cabc8047e673f38ac Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 28 Apr 2015 10:27:16 -0700 Subject: Cache transaction validation successes --- src/test/mruset_tests.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/test/mruset_tests.cpp') diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp index 2b68f8899..3c0668916 100644 --- a/src/test/mruset_tests.cpp +++ b/src/test/mruset_tests.cpp @@ -78,4 +78,68 @@ BOOST_AUTO_TEST_CASE(mruset_test) } } +BOOST_AUTO_TEST_CASE(mrumap_test) +{ + // The mrumap being tested. + mrumap mru(5000); + + // Run the test 10 times. + for (int test = 0; test < 10; test++) { + // Reset mru. + mru.clear(5000); + + // A deque + set to simulate the mruset. + std::deque rep; + std::map all; + + // Insert 10000 random integers below 15000. + for (int j=0; j<10000; j++) { + int add = GetRandInt(15000); + char val = (char)GetRandInt(256); + mru.insert(add, val); + + // Add the number to rep/all as well. + if (all.count(add) == 0) { + all.insert(std::make_pair(add, val)); + rep.push_back(add); + if (all.size() == 5001) { + all.erase(rep.front()); + rep.pop_front(); + } + } + + if (GetRandInt(5) == 0) { + // With 20% chance: remove an item + int pos = GetRandInt(rep.size()); + std::deque::iterator it = rep.begin(); + while (pos--) { it++; } + int delval = *it; + mru.erase(delval); + all.erase(delval); + rep.erase(it); + } + + // Do a full comparison between mru and the simulated mru every 1000 and every 5001 elements. + if (j % 1000 == 0 || j % 5001 == 0) { + // Check that all elements that should be in there, are in there. + BOOST_FOREACH(int x, rep) { + BOOST_CHECK(mru.count(x)); + BOOST_CHECK(mru.find(x)->second == all[x]); + } + + // Check that all elements that are in there, should be in there. + for (mrumap::iterator it = mru.begin(); it != mru.end(); it++) { + BOOST_CHECK(all.count(it->first)); + BOOST_CHECK(all[it->first] == it->second); + } + + for (int t = 0; t < 10; t++) { + int r = GetRandInt(15000); + BOOST_CHECK(all.count(r) == mru.count(r)); + } + } + } + } +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From eddaba7b5692288087a926da5733e86b47274e4e Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Tue, 28 Jul 2015 20:14:43 +0200 Subject: Revert "Cache transaction validation successes" This reverts commit 17b11428c135203342aff38cabc8047e673f38ac. --- src/test/mruset_tests.cpp | 64 ----------------------------------------------- 1 file changed, 64 deletions(-) (limited to 'src/test/mruset_tests.cpp') diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp index 3c0668916..2b68f8899 100644 --- a/src/test/mruset_tests.cpp +++ b/src/test/mruset_tests.cpp @@ -78,68 +78,4 @@ BOOST_AUTO_TEST_CASE(mruset_test) } } -BOOST_AUTO_TEST_CASE(mrumap_test) -{ - // The mrumap being tested. - mrumap mru(5000); - - // Run the test 10 times. - for (int test = 0; test < 10; test++) { - // Reset mru. - mru.clear(5000); - - // A deque + set to simulate the mruset. - std::deque rep; - std::map all; - - // Insert 10000 random integers below 15000. - for (int j=0; j<10000; j++) { - int add = GetRandInt(15000); - char val = (char)GetRandInt(256); - mru.insert(add, val); - - // Add the number to rep/all as well. - if (all.count(add) == 0) { - all.insert(std::make_pair(add, val)); - rep.push_back(add); - if (all.size() == 5001) { - all.erase(rep.front()); - rep.pop_front(); - } - } - - if (GetRandInt(5) == 0) { - // With 20% chance: remove an item - int pos = GetRandInt(rep.size()); - std::deque::iterator it = rep.begin(); - while (pos--) { it++; } - int delval = *it; - mru.erase(delval); - all.erase(delval); - rep.erase(it); - } - - // Do a full comparison between mru and the simulated mru every 1000 and every 5001 elements. - if (j % 1000 == 0 || j % 5001 == 0) { - // Check that all elements that should be in there, are in there. - BOOST_FOREACH(int x, rep) { - BOOST_CHECK(mru.count(x)); - BOOST_CHECK(mru.find(x)->second == all[x]); - } - - // Check that all elements that are in there, should be in there. - for (mrumap::iterator it = mru.begin(); it != mru.end(); it++) { - BOOST_CHECK(all.count(it->first)); - BOOST_CHECK(all[it->first] == it->second); - } - - for (int t = 0; t < 10; t++) { - int r = GetRandInt(15000); - BOOST_CHECK(all.count(r) == mru.count(r)); - } - } - } - } -} - BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From e20672479ef7f2048c2e27494397641d47a4d88d Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sat, 28 Nov 2015 13:19:59 +0000 Subject: Remove mruset as it is no longer used. --- src/test/mruset_tests.cpp | 81 ----------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 src/test/mruset_tests.cpp (limited to 'src/test/mruset_tests.cpp') diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp deleted file mode 100644 index 2b68f8899..000000000 --- a/src/test/mruset_tests.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) 2012-2013 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "mruset.h" - -#include "random.h" -#include "util.h" -#include "test/test_bitcoin.h" - -#include - -#include - -#define NUM_TESTS 16 -#define MAX_SIZE 100 - -using namespace std; - -BOOST_FIXTURE_TEST_SUITE(mruset_tests, BasicTestingSetup) - -BOOST_AUTO_TEST_CASE(mruset_test) -{ - // The mruset being tested. - mruset mru(5000); - - // Run the test 10 times. - for (int test = 0; test < 10; test++) { - // Reset mru. - mru.clear(); - - // A deque + set to simulate the mruset. - std::deque rep; - std::set all; - - // Insert 10000 random integers below 15000. - for (int j=0; j<10000; j++) { - int add = GetRandInt(15000); - mru.insert(add); - - // Add the number to rep/all as well. - if (all.count(add) == 0) { - all.insert(add); - rep.push_back(add); - if (all.size() == 5001) { - all.erase(rep.front()); - rep.pop_front(); - } - } - - // Do a full comparison between mru and the simulated mru every 1000 and every 5001 elements. - if (j % 1000 == 0 || j % 5001 == 0) { - mruset mru2 = mru; // Also try making a copy - - // Check that all elements that should be in there, are in there. - BOOST_FOREACH(int x, rep) { - BOOST_CHECK(mru.count(x)); - BOOST_CHECK(mru2.count(x)); - } - - // Check that all elements that are in there, should be in there. - BOOST_FOREACH(int x, mru) { - BOOST_CHECK(all.count(x)); - } - - // Check that all elements that are in there, should be in there. - BOOST_FOREACH(int x, mru2) { - BOOST_CHECK(all.count(x)); - } - - for (int t = 0; t < 10; t++) { - int r = GetRandInt(15000); - BOOST_CHECK(all.count(r) == mru.count(r)); - BOOST_CHECK(all.count(r) == mru2.count(r)); - } - } - } - } -} - -BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3