aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2015-03-02 00:47:27 +0800
committerGav Wood <i@gavwood.com>2015-03-06 19:45:23 +0800
commit23f10dae8a8e95cd5302b60ceb70b43cb9e60063 (patch)
tree50959bab6f99c184daefa13bd02fac6b02a93013
parent2f91e1f9b54a27aa3f4b8d8bbb87b2c219df3e96 (diff)
downloaddexon-solidity-23f10dae8a8e95cd5302b60ceb70b43cb9e60063.tar.gz
dexon-solidity-23f10dae8a8e95cd5302b60ceb70b43cb9e60063.tar.zst
dexon-solidity-23f10dae8a8e95cd5302b60ceb70b43cb9e60063.zip
Fat Trie and tests for it.
-rw-r--r--trie.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/trie.cpp b/trie.cpp
index dd335b4a..18e115da 100644
--- a/trie.cpp
+++ b/trie.cpp
@@ -50,6 +50,8 @@ static unsigned fac(unsigned _i)
}
}
+using dev::operator <<;
+
BOOST_AUTO_TEST_SUITE(TrieTests)
BOOST_AUTO_TEST_CASE(trie_test_anyorder)
@@ -81,15 +83,35 @@ BOOST_AUTO_TEST_CASE(trie_test_anyorder)
next_permutation(ss.begin(), ss.end());
MemoryDB m;
GenericTrieDB<MemoryDB> t(&m);
+ MemoryDB hm;
+ HashedGenericTrieDB<MemoryDB> ht(&hm);
+ MemoryDB fm;
+ FatGenericTrieDB<MemoryDB> ft(&fm);
t.init();
+ ht.init();
+ ft.init();
BOOST_REQUIRE(t.check(true));
+ BOOST_REQUIRE(ht.check(true));
+ BOOST_REQUIRE(ft.check(true));
for (auto const& k: ss)
{
t.insert(k.first, k.second);
+ ht.insert(k.first, k.second);
+ ft.insert(k.first, k.second);
BOOST_REQUIRE(t.check(true));
+ BOOST_REQUIRE(ht.check(true));
+ BOOST_REQUIRE(ft.check(true));
+ for (auto i = ft.begin(), j = t.begin(); i != ft.end() && j != t.end(); ++i, ++j)
+ {
+ BOOST_CHECK_EQUAL(i == ft.end(), j == t.end());
+ BOOST_REQUIRE((*i).first.toBytes() == (*j).first.toBytes());
+ BOOST_REQUIRE((*i).second.toBytes() == (*j).second.toBytes());
+ }
+ BOOST_CHECK_EQUAL(ht.root(), ft.root());
}
BOOST_REQUIRE(!o["root"].is_null());
BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray()));
+ BOOST_CHECK_EQUAL(ht.root(), ft.root());
}
}
}
@@ -141,15 +163,33 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered)
MemoryDB m;
GenericTrieDB<MemoryDB> t(&m);
+ MemoryDB hm;
+ HashedGenericTrieDB<MemoryDB> ht(&hm);
+ MemoryDB fm;
+ FatGenericTrieDB<MemoryDB> ft(&fm);
t.init();
+ ht.init();
+ ft.init();
BOOST_REQUIRE(t.check(true));
+ BOOST_REQUIRE(ht.check(true));
+ BOOST_REQUIRE(ft.check(true));
+
for (auto const& k: ss)
{
if (find(keysToBeDeleted.begin(), keysToBeDeleted.end(), k.first) != keysToBeDeleted.end() && k.second.empty())
- t.remove(k.first);
+ t.remove(k.first), ht.remove(k.first), ft.remove(k.first);
else
- t.insert(k.first, k.second);
+ t.insert(k.first, k.second), ht.insert(k.first, k.second), ft.insert(k.first, k.second);
BOOST_REQUIRE(t.check(true));
+ BOOST_REQUIRE(ht.check(true));
+ BOOST_REQUIRE(ft.check(true));
+ for (auto i = ft.begin(), j = t.begin(); i != ft.end() && j != t.end(); ++i, ++j)
+ {
+ BOOST_CHECK_EQUAL(i == ft.end(), j == t.end());
+ BOOST_REQUIRE((*i).first.toBytes() == (*j).first.toBytes());
+ BOOST_REQUIRE((*i).second.toBytes() == (*j).second.toBytes());
+ }
+ BOOST_CHECK_EQUAL(ht.root(), ft.root());
}
BOOST_REQUIRE(!o["root"].is_null());