aboutsummaryrefslogtreecommitdiffstats
path: root/trie.cpp
diff options
context:
space:
mode:
authorCarl Allendorph <callendorph@gmail.com>2014-04-20 01:52:08 +0800
committerCarl Allendorph <callendorph@gmail.com>2014-04-20 01:52:08 +0800
commitb8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a (patch)
tree38572e704e6dfda0a4641af75607dd0f32bce876 /trie.cpp
parentcd132eae5e12f98410a62b06dd7abfd0eee9722d (diff)
downloaddexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar.gz
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar.bz2
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar.lz
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar.xz
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.tar.zst
dexon-solidity-b8ce26d9f9d0a079ccfdb39f2e225b63dbe5f10a.zip
Broke trie tests out as separate boost auto test case.
Diffstat (limited to 'trie.cpp')
-rw-r--r--trie.cpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/trie.cpp b/trie.cpp
index 5e3cfcb6..785bcc72 100644
--- a/trie.cpp
+++ b/trie.cpp
@@ -26,56 +26,56 @@
#include <TrieDB.h>
#include "TrieHash.h"
#include "MemTrie.h"
+#include <boost/test/unit_test.hpp>
+
using namespace std;
using namespace eth;
namespace js = json_spirit;
-namespace eth
-{
+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>
+
+BOOST_AUTO_TEST_CASE(trie_tests)
{
-public:
- int operator()()
+ 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);
+ for (auto& i: v.get_obj())
{
- js::mValue v;
- string s = asString(contents("../../tests/trietest.json"));
- js::read_string(s, v);
- bool passed = true;
- for (auto& i: v.get_obj())
+ js::mObject& o = i.second.get_obj();
+ cnote << i.first;
+ 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 < eth::test::fac((unsigned)ss.size()); ++j)
{
- js::mObject& o = i.second.get_obj();
- cnote << i.first;
- 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)
- {
- next_permutation(ss.begin(), ss.end());
- BasicMap m;
- GenericTrieDB<BasicMap> t(&m);
- 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;
- }
- }
+ next_permutation(ss.begin(), ss.end());
+ BasicMap m;
+ GenericTrieDB<BasicMap> t(&m);
+ t.init();
+ for (auto const& k: ss)
+ t.insert(k.first, k.second);
+ 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)
{
return hash256(_s);
@@ -83,8 +83,6 @@ inline h256 stringMapHash256(StringMap const& _s)
int trieTest()
{
- cnote << "Testing Trie...";
- return UnitTest<4>()();
// More tests...
{