From 52312fcd1d0c9a579a13aaa37c8b24032af82c8b Mon Sep 17 00:00:00 2001 From: Evangelos Voyiatzis Date: Fri, 14 Feb 2025 06:22:29 +0000 Subject: [PATCH] test for extract() in improper class --- unittest/force-styles/test_improper_style.cpp | 41 +++++++++++++++++++ .../tests/improper-sqdistharm.yaml | 1 - 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/unittest/force-styles/test_improper_style.cpp b/unittest/force-styles/test_improper_style.cpp index e272033e85..f390850358 100644 --- a/unittest/force-styles/test_improper_style.cpp +++ b/unittest/force-styles/test_improper_style.cpp @@ -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(); +} \ No newline at end of file diff --git a/unittest/force-styles/tests/improper-sqdistharm.yaml b/unittest/force-styles/tests/improper-sqdistharm.yaml index 74ff07bb9a..7e08c86fc7 100644 --- a/unittest/force-styles/tests/improper-sqdistharm.yaml +++ b/unittest/force-styles/tests/improper-sqdistharm.yaml @@ -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-