Skip to content

Commit

Permalink
Feature: add unit-testing building rules for trpc/util/algorithm (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
liucf3995 authored Mar 20, 2024
1 parent f0a78df commit 53be380
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
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

0 comments on commit 53be380

Please sign in to comment.