susumu.yata
null+****@clear*****
Fri Apr 5 10:27:31 JST 2013
susumu.yata 2013-04-05 10:27:31 +0900 (Fri, 05 Apr 2013) New Revision: 1a20831368167b0bfc41c206e29990111a752668 https://github.com/groonga/grnxx/commit/1a20831368167b0bfc41c206e29990111a752668 Message: Add tests for grnxx::alpha::Map. Modified files: test/test_alpha_map.cpp Modified: test/test_alpha_map.cpp (+67 -1) =================================================================== --- test/test_alpha_map.cpp 2013-04-04 21:56:32 +0900 (3aa72c9) +++ test/test_alpha_map.cpp 2013-04-05 10:27:31 +0900 (39854e2) @@ -42,6 +42,8 @@ void compare_maps(const std::unique_ptr<grnxx::alpha::Map<T>> &map, template <typename T> void test_map() { + GRNXX_NOTICE() << __PRETTY_FUNCTION__; + std::mt19937_64 rng; grnxx::io::Pool pool; @@ -66,8 +68,72 @@ void test_map() { std::int64_t stored_key_id; assert(map->insert(key, &stored_key_id) == is_new); assert(stored_key_id == key_id); + assert(!map->insert(key, &stored_key_id)); + + T stored_key; + assert(map->get(key_id, &stored_key)); + assert(stored_key == key); + + assert(map->search(key, &stored_key_id)); + assert(stored_key_id == key_id); + } + compare_maps(map, hash_map); + + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->unset(it->second)); + assert(!map->unset(it->second)); + } + + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->insert(it->first)); + } + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->remove(it->first)); + assert(!map->remove(it->first)); + } + + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->insert(it->first)); + } + map->truncate(); + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(!map->get(it->second)); + } - compare_maps(map, hash_map); + map->truncate(); + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->insert(it->first, &it->second)); + } + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + auto old_it = it; + auto new_it = ++it; + assert(map->unset(new_it->second)); + assert(map->reset(old_it->second, new_it->first)); + + T key; + assert(map->get(old_it->second, &key)); + assert(key == new_it->first); + std::int64_t key_id; + assert(map->search(key, &key_id)); + assert(key_id == old_it->second); + } + + map->truncate(); + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + assert(map->insert(it->first, &it->second)); + } + for (auto it = hash_map.begin(); it != hash_map.end(); ++it) { + auto old_it = it; + auto new_it = ++it; + assert(map->remove(new_it->first)); + assert(map->update(old_it->first, new_it->first)); + + T key; + assert(map->get(old_it->second, &key)); + assert(key == new_it->first); + std::int64_t key_id; + assert(map->search(key, &key_id)); + assert(key_id == old_it->second); } } -------------- next part -------------- HTML����������������������������...Download