aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCJentzsch <jentzsch.software@gmail.com>2015-01-02 04:36:02 +0800
committerCJentzsch <jentzsch.software@gmail.com>2015-01-02 04:36:02 +0800
commit0c980d85a551254708b1b1facfa90e070abd2bb1 (patch)
tree7130cc09c4ef613216620f3aaa50f00dfed53628
parenta4cdb78a5fce7acc07ab4466370f86830c51ff2e (diff)
downloaddexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.tar.gz
dexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.tar.zst
dexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.zip
add trie_tests_ordered
-rw-r--r--trie.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/trie.cpp b/trie.cpp
index 2141d5de..59192f47 100644
--- a/trie.cpp
+++ b/trie.cpp
@@ -103,16 +103,31 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered)
string s = asString(contents(testPath + "/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())
{
cnote << i.first;
js::mObject& o = i.second.get_obj();
vector<pair<string, string>> ss;
+ vector<string> keysToBeDeleted;
for (auto& i: o["in"].get_array())
{
vector<string> values;
for (auto& s: i.get_array())
- values.push_back(s.get_str());
+ {
+ if (s.type() == json_spirit::str_type)
+ values.push_back(s.get_str());
+ else if (s.type() == json_spirit::null_type)
+ {
+ // mark entry for deletion
+ values.push_back("");
+ if (!values[0].find("0x"))
+ values[0] = asString(fromHex(values[0].substr(2)));
+ keysToBeDeleted.push_back(values[0]);
+ }
+ else
+ cwarn << "Bad type (expected string): " << s.type();
+ }
assert(values.size() == 2);
ss.push_back(make_pair(values[0], values[1]));
@@ -128,9 +143,13 @@ BOOST_AUTO_TEST_CASE(trie_tests_ordered)
BOOST_REQUIRE(t.check(true));
for (auto const& k: ss)
{
- t.insert(k.first, k.second);
+ if (find(keysToBeDeleted.begin(), keysToBeDeleted.end(), k.first) != keysToBeDeleted.end() && k.second.empty())
+ t.remove(k.first);
+ else
+ t.insert(k.first, k.second);
BOOST_REQUIRE(t.check(true));
}
+
BOOST_REQUIRE(!o["root"].is_null());
BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray()));
}