diff options
author | CJentzsch <jentzsch.software@gmail.com> | 2015-01-02 04:36:02 +0800 |
---|---|---|
committer | CJentzsch <jentzsch.software@gmail.com> | 2015-01-02 04:36:02 +0800 |
commit | 0c980d85a551254708b1b1facfa90e070abd2bb1 (patch) | |
tree | 7130cc09c4ef613216620f3aaa50f00dfed53628 | |
parent | a4cdb78a5fce7acc07ab4466370f86830c51ff2e (diff) | |
download | dexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.tar.gz dexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.tar.zst dexon-solidity-0c980d85a551254708b1b1facfa90e070abd2bb1.zip |
add trie_tests_ordered
-rw-r--r-- | trie.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
@@ -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())); } |