From f9e17d5e791dc15f4d284e8165b66a7d706ef4fc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 23 Dec 2022 16:18:18 -0500 Subject: [PATCH] add unit test for the extract method of angle styles --- unittest/force-styles/test_angle_style.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/unittest/force-styles/test_angle_style.cpp b/unittest/force-styles/test_angle_style.cpp index 36e281e100..d9f541df96 100644 --- a/unittest/force-styles/test_angle_style.cpp +++ b/unittest/force-styles/test_angle_style.cpp @@ -667,3 +667,44 @@ TEST(AngleStyle, single) cleanup_lammps(lmp, test_config); if (!verbose) ::testing::internal::GetCapturedStdout(); } + +TEST(AngleStyle, extract) +{ + if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP(); + + const char *args[] = {"AngleStyle", "-log", "none", "-echo", "screen", "-nocite"}; + + char **argv = (char **)args; + int argc = sizeof(args) / sizeof(char *); + + if (!verbose) ::testing::internal::CaptureStdout(); + LAMMPS *lmp = init_lammps(argc, argv, test_config, true); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + if (!lmp) { + std::cerr << "One or more prerequisite styles are not available " + "in this LAMMPS configuration:\n"; + for (auto prerequisite : test_config.prerequisites) { + std::cerr << prerequisite.first << "_style " << prerequisite.second << "\n"; + } + GTEST_SKIP(); + } + + auto angle = lmp->force->angle; + void *ptr = nullptr; + int dim = 0; + for (auto extract : test_config.extract) { + ptr = angle->extract(extract.first.c_str(), dim); + EXPECT_NE(ptr, nullptr); + EXPECT_EQ(dim, extract.second); + } + ptr = angle->extract("does_not_exist", dim); + EXPECT_EQ(ptr, nullptr); + + for (int i = 1; i <= lmp->atom->nangletypes; ++i) + EXPECT_GE(angle->equilibrium_angle(i), 0.0); + + if (!verbose) ::testing::internal::CaptureStdout(); + cleanup_lammps(lmp, test_config); + if (!verbose) ::testing::internal::GetCapturedStdout(); +}