|
|
@ -26,6 +26,8 @@ |
|
|
|
#include <TrieDB.h> |
|
|
|
#include "TrieHash.h" |
|
|
|
#include "MemTrie.h" |
|
|
|
#include <boost/test/unit_test.hpp> |
|
|
|
|
|
|
|
using namespace std; |
|
|
|
using namespace eth; |
|
|
|
|
|
|
@ -33,18 +35,25 @@ namespace js = json_spirit; |
|
|
|
|
|
|
|
namespace eth |
|
|
|
{ |
|
|
|
namespace test |
|
|
|
{ |
|
|
|
static unsigned fac(unsigned _i) |
|
|
|
{ |
|
|
|
return _i > 2 ? _i * fac(_i - 1) : _i; |
|
|
|
} |
|
|
|
|
|
|
|
unsigned fac(unsigned _i) { return _i > 2 ? _i * fac(_i - 1) : _i; } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
template <> class UnitTest<4> |
|
|
|
{ |
|
|
|
public: |
|
|
|
int operator()() |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(trie_tests) |
|
|
|
{ |
|
|
|
cnote << "Testing Trie..."; |
|
|
|
|
|
|
|
js::mValue v; |
|
|
|
string s = asString(contents("../../tests/trietest.json")); |
|
|
|
BOOST_REQUIRE_MESSAGE( s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?"); |
|
|
|
js::read_string(s, v); |
|
|
|
bool passed = true; |
|
|
|
for (auto& i: v.get_obj()) |
|
|
|
{ |
|
|
|
js::mObject& o = i.second.get_obj(); |
|
|
@ -52,7 +61,7 @@ public: |
|
|
|
vector<pair<string, string>> ss; |
|
|
|
for (auto& i: o["in"].get_obj()) |
|
|
|
ss.push_back(make_pair(i.first, i.second.get_str())); |
|
|
|
for (unsigned j = 0; j < fac((unsigned)ss.size()); ++j) |
|
|
|
for (unsigned j = 0; j < eth::test::fac((unsigned)ss.size()); ++j) |
|
|
|
{ |
|
|
|
next_permutation(ss.begin(), ss.end()); |
|
|
|
BasicMap m; |
|
|
@ -60,21 +69,12 @@ public: |
|
|
|
t.init(); |
|
|
|
for (auto const& k: ss) |
|
|
|
t.insert(k.first, k.second); |
|
|
|
if (!o["root"].is_null() && o["root"].get_str() != toHex(t.root().asArray())) |
|
|
|
{ |
|
|
|
cwarn << "Test failed on permutation " << j; |
|
|
|
cwarn << "Test says:" << o["root"].get_str(); |
|
|
|
cwarn << "Impl says:" << toHex(t.root().asArray()); |
|
|
|
passed = false; |
|
|
|
} |
|
|
|
BOOST_REQUIRE(!o["root"].is_null()); |
|
|
|
BOOST_CHECK(o["root"].get_str() == toHex(t.root().asArray()) ); |
|
|
|
} |
|
|
|
} |
|
|
|
return passed ? 0 : 1; |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
inline h256 stringMapHash256(StringMap const& _s) |
|
|
|
{ |
|
|
@ -83,8 +83,6 @@ inline h256 stringMapHash256(StringMap const& _s) |
|
|
|
|
|
|
|
int trieTest() |
|
|
|
{ |
|
|
|
cnote << "Testing Trie..."; |
|
|
|
return UnitTest<4>()(); |
|
|
|
|
|
|
|
// More tests...
|
|
|
|
{ |
|
|
|