Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add unit-testing building rules for trpc/util/algorithm #120

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions trpc/util/algorithm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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",
],
)
30 changes: 30 additions & 0 deletions trpc/util/algorithm/hash_test.cc
Original file line number Diff line number Diff line change
@@ -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
Loading