Skip to content

Commit

Permalink
Added an unit test for SkipSet
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Nov 29, 2022
1 parent 73bd4c9 commit d2e9e20
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/test/evo_assetlocks_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <test/util/setup_common.h>

#include <evo/assetlocktx.h>
#include <evo/creditpool.h> // to test SkipSet
#include <policy/settings.h>
#include <script/signingprovider.h>
#include <consensus/tx_check.h>
Expand All @@ -14,6 +15,8 @@

#include <boost/test/unit_test.hpp>

#include <random>
#include <unordered_set>

//
// Helper: create two dummy transactions, each with
Expand Down Expand Up @@ -333,4 +336,31 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup)

}

BOOST_FIXTURE_TEST_CASE(evo_skipset, TestChain100Setup)
{
std::mt19937 gen;
std::uniform_int_distribution<int64_t> dist_action(0, 1);
for (size_t test = 0; test < 20; ++test) {
std::uniform_int_distribution<int64_t> dist_value(0, (1 << test));
SkipSet set_1;
std::unordered_set<int64_t> set_2;
for (size_t iter = 0; iter < (1 << test) * 2; ++iter) {
int action = dist_action(gen);
int64_t value = dist_value(gen);
BOOST_CHECK(set_1.contains(value) == !!set_2.count(value));
if (action == 0 && !set_1.contains(value)) {
set_1.add(value);
set_2.insert(value);
}
if (action == 1 && set_1.contains(value)) {
set_1.remove(value);
set_2.erase(value);
}
BOOST_CHECK(set_1.contains(value) == !!set_2.count(value));
BOOST_CHECK(set_1.size() == set_2.size());
}
}
}


BOOST_AUTO_TEST_SUITE_END()

0 comments on commit d2e9e20

Please sign in to comment.