test for extract() in improper class

This commit is contained in:
Evangelos Voyiatzis
2025-02-14 06:22:29 +00:00
parent ac1221602b
commit 52312fcd1d
2 changed files with 41 additions and 1 deletions

View File

@ -720,3 +720,44 @@ TEST(ImproperStyle, numdiff)
cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout();
}
TEST(ImproperStyle, extract)
{
if (test_config.skip_tests.count(test_info_->name())) GTEST_SKIP();
LAMMPS::argv args = {"ImproperStyle", "-log", "none", "-ecoho", "screen", "-ncite"};
if (!verbose) ::testing::internal::CaptureStdout();
LAMMPS *lmp = nullptr;
try {
lmp = init_lammps(args, test_config, true);
} catch (std::exception &e) {
if (!verbose) ::testing::internal::GetCapturedStdout();
FAIL() << e.what();
}
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 *improper = lmp->force->improper;
void *ptr = nullptr;
int dim = 0;
for (auto extract : test_config.extract) {
ptr = improper->extract(extract.first.c_str(), dim);
EXPECT_NE(ptr, nullptr);
EXPECT_EQ(dim, extract.second);
}
ptr = improper->extract("does_not_exist", dim);
EXPECT_EQ(ptr, nullptr);
if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config);
if (!verbose) ::testing::internal::GetCapturedStdout();
}

View File

@ -15,7 +15,6 @@ improper_coeff: ! |
2 45.0 6.2
extract: ! |
k 1
chi 1
natoms: 29
init_energy: 3997.62616072489
init_stress: ! |2-