aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-04-28 10:27:16 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-07-27 15:28:43 +0200
commit17b11428c135203342aff38cabc8047e673f38ac (patch)
tree9a4634eaa35696916ead713371895bddef9acddf /src/test
parentca37e0f33980a1fe96ac4ed08fd7d692a7a592a5 (diff)
downloadbitcoin-17b11428c135203342aff38cabc8047e673f38ac.tar.xz
Cache transaction validation successes
Diffstat (limited to 'src/test')
-rw-r--r--src/test/mruset_tests.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp
index 2b68f8899e..3c06689168 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<int, char> 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<int> rep;
+ std::map<int, char> 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<int, char>(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<int>::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<int, char>::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()