Skip to content

Commit 24a935a

Browse files
committed
refactor util tests: improve naming consistency for test cases and enhance clarity with updated comments in OpenMP thread control tests
1 parent 5b87e70 commit 24a935a

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

modules/util/tests/util.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,24 @@ namespace my::nested {
1111
struct Type {};
1212
} // namespace my::nested
1313

14-
TEST(util_tests, extracts_correct_namespace) {
14+
TEST(UtilTest, GetNamespace_WithNestedType_ReturnsCorrectNamespace) {
1515
std::string k_ns = ppc::util::GetNamespace<my::nested::Type>();
1616
EXPECT_EQ(k_ns, "my::nested");
1717
}
1818

19-
TEST(util_tests, threads_control_check_openmp_disabled_valgrind) {
19+
TEST(UtilTest, GetNumThreads_WithOpenMPEnvironment_HandlesThreadControlCorrectly) {
2020
const auto num_threads_env_var = env::get<int>("PPC_NUM_THREADS");
2121

2222
if (num_threads_env_var.has_value()) {
23+
// When PPC_NUM_THREADS is set, GetNumThreads() should return that value
24+
EXPECT_EQ(ppc::util::GetNumThreads(), num_threads_env_var.value());
25+
26+
// And after setting OpenMP threads, it should match
2327
omp_set_num_threads(num_threads_env_var.value());
2428
EXPECT_EQ(ppc::util::GetNumThreads(), omp_get_max_threads());
2529
} else {
30+
// When PPC_NUM_THREADS is not set, GetNumThreads() should return 1
31+
// This is independent of OpenMP's thread count
2632
EXPECT_EQ(ppc::util::GetNumThreads(), 1);
2733
}
2834
}
@@ -33,17 +39,17 @@ struct TypeInNamespace {};
3339

3440
struct PlainType {};
3541

36-
TEST(GetNamespaceTest, ReturnsExpectedNamespace) {
42+
TEST(GetNamespaceTest, GetNamespace_WithNamespacedType_ReturnsExpectedNamespace) {
3743
std::string k_ns = ppc::util::GetNamespace<test_ns::TypeInNamespace>();
3844
EXPECT_EQ(k_ns, "test_ns");
3945
}
4046

41-
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PrimitiveType) {
47+
TEST(GetNamespaceTest, GetNamespace_WithPrimitiveType_ReturnsEmptyString) {
4248
std::string k_ns = ppc::util::GetNamespace<int>();
4349
EXPECT_EQ(k_ns, "");
4450
}
4551

46-
TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespace_PlainStruct) {
52+
TEST(GetNamespaceTest, GetNamespace_WithPlainStruct_ReturnsEmptyString) {
4753
std::string k_ns = ppc::util::GetNamespace<PlainType>();
4854
EXPECT_EQ(k_ns, "");
4955
}
@@ -52,22 +58,22 @@ namespace test_ns {
5258
struct Nested {};
5359
} // namespace test_ns
5460

55-
TEST(GetNamespaceTest, ReturnsNamespaceCorrectly) {
61+
TEST(GetNamespaceTest, GetNamespace_WithNestedStruct_ReturnsNamespaceCorrectly) {
5662
std::string k_ns = ppc::util::GetNamespace<test_ns::Nested>();
5763
EXPECT_EQ(k_ns, "test_ns");
5864
}
5965

6066
struct NoNamespaceType {};
6167

62-
TEST(GetNamespaceTest, NoNamespaceInType) {
68+
TEST(GetNamespaceTest, GetNamespace_WithNoNamespaceType_ReturnsEmptyString) {
6369
std::string k_ns = ppc::util::GetNamespace<NoNamespaceType>();
6470
EXPECT_EQ(k_ns, "");
6571
}
6672

6773
template <typename T>
6874
struct NotATemplate {};
6975

70-
TEST(GetNamespaceTest, NoKeyInPrettyFunction) {
76+
TEST(GetNamespaceTest, GetNamespace_WithTemplateType_ReturnsEmptyString) {
7177
std::string k_ns = ppc::util::GetNamespace<NotATemplate<void>>();
7278
EXPECT_EQ(k_ns, "");
7379
}
@@ -76,7 +82,7 @@ namespace crazy {
7682
struct VeryLongTypeNameWithOnlyLettersAndUnderscores {};
7783
} // namespace crazy
7884

79-
TEST(GetNamespaceTest, NoTerminatorCharactersInPrettyFunction) {
85+
TEST(GetNamespaceTest, GetNamespace_WithLongTypeName_ReturnsCorrectNamespace) {
8086
std::string k_ns = ppc::util::GetNamespace<crazy::VeryLongTypeNameWithOnlyLettersAndUnderscores>();
8187
EXPECT_EQ(k_ns, "crazy");
8288
}

0 commit comments

Comments
 (0)