/*
* Copyright (C) 2015 ScyllaDB
*/
/*
* This file is part of Scylla.
*
* Scylla is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Scylla is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Scylla. If not, see .
*/
#include
#include "tests/test-utils.hh"
#include "utils/hash.hh"
#include "disk-error-handler.hh"
thread_local disk_error_signal_type commit_error;
thread_local disk_error_signal_type general_disk_error;
SEASTAR_TEST_CASE(test_pair_hash){
auto hash_compare = [](auto p) {
auto h1 = utils::tuple_hash()(p);
auto h2 = utils::hash_combine(std::hash()(p.first), std::hash()(p.second));
BOOST_CHECK_EQUAL(h1, h2);
};
hash_compare(std::make_pair(1, 2));
hash_compare(std::make_pair(1.5, 2.1));
hash_compare(std::make_pair("gris", "bacon"));
hash_compare(std::make_pair(666, "bacon"));
return make_ready_future<>();
}
SEASTAR_TEST_CASE(test_tuple_hash){
auto hash_compare = [](auto p, auto h2) {
auto h1 = utils::tuple_hash()(p);
BOOST_CHECK_EQUAL(h1, h2);
};
hash_compare(std::make_tuple(1, 2), utils::hash_combine(
std::hash()(1)
, std::hash()(2)
));
hash_compare(std::make_tuple(1, 2, 3), utils::hash_combine(
std::hash()(1)
, utils::hash_combine(std::hash()(2)
, std::hash()(3))
));
hash_compare(std::make_tuple("apa", "ko"), utils::hash_combine(
std::hash()("apa")
, std::hash()("ko")
));
hash_compare(std::make_tuple("olof", 2, "kung"), utils::hash_combine(
std::hash()("olof")
, utils::hash_combine(std::hash()(2)
, std::hash()("kung"))
));
return make_ready_future<>();
}