diff --git a/trpc/util/algorithm/BUILD b/trpc/util/algorithm/BUILD index e514845f..140af945 100644 --- a/trpc/util/algorithm/BUILD +++ b/trpc/util/algorithm/BUILD @@ -12,6 +12,15 @@ cc_library( ], ) +cc_test( + name = "power_of_two_test", + srcs = ["power_of_two_test.cc"], + deps = [ + ":power_of_two", + "@com_google_googletest//:gtest_main", + ], +) + cc_library( name = "random", hdrs = ["random.h"], @@ -25,3 +34,12 @@ cc_library( "//trpc/util/log:logging", ], ) + +cc_test( + name = "hash_test", + srcs = ["hash_test.cc"], + deps = [ + ":hash", + "@com_google_googletest//:gtest_main", + ], +) diff --git a/trpc/util/algorithm/hash_test.cc b/trpc/util/algorithm/hash_test.cc new file mode 100644 index 00000000..4250e345 --- /dev/null +++ b/trpc/util/algorithm/hash_test.cc @@ -0,0 +1,30 @@ +// +// +// Tencent is pleased to support the open source community by making tRPC available. +// +// Copyright (C) 2023 THL A29 Limited, a Tencent company. +// All rights reserved. +// +// If you have downloaded a copy of the tRPC source code from Tencent, +// please note that tRPC source code is licensed under the Apache 2.0 License, +// A copy of the Apache 2.0 License is included in this file. +// +// + +#include "trpc/util/algorithm/hash.h" + +#include "gtest/gtest.h" + +namespace trpc::testing { + +TEST(GetHashIndex, All) { + std::uint64_t key = 10; + std::uint64_t mod = 8; + std::size_t ret = GetHashIndex(key, mod); + ASSERT_LE(ret, mod); + // Test case: mod is 0. + mod = 0; + ASSERT_DEATH(GetHashIndex(key, mod), ""); +} + +} // namespace trpc::testing