From 0c980d85a551254708b1b1facfa90e070abd2bb1 Mon Sep 17 00:00:00 2001 From: CJentzsch Date: Thu, 1 Jan 2015 21:36:02 +0100 Subject: [PATCH] add trie_tests_ordered --- trie.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/trie.cpp b/trie.cpp index 2141d5de9..59192f470 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> ss; + vector keysToBeDeleted; for (auto& i: o["in"].get_array()) { vector 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())); }