From 958f2ae58b6018445822f671b2dbdf87d077653b Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Fri, 20 Sep 2024 03:57:12 -0400 Subject: [PATCH] add tests for library interface and python --- unittest/c-library/test_library_objects.cpp | 20 ++++++++++++++++++++ unittest/python/python-commands.py | 10 ++++++++++ 2 files changed, 30 insertions(+) diff --git a/unittest/c-library/test_library_objects.cpp b/unittest/c-library/test_library_objects.cpp index 9d30492be3..a175952dfd 100644 --- a/unittest/c-library/test_library_objects.cpp +++ b/unittest/c-library/test_library_objects.cpp @@ -213,3 +213,23 @@ TEST_F(LibraryObjects, variables) LAMMPS_NS::platform::unlink("test_variable.file"); } + +TEST_F(LibraryObjects, expand) +{ + ::testing::internal::CaptureStdout(); + lammps_command(lmp, "variable one index 1 2 3 4"); + lammps_command(lmp, "variable two equal 2"); + lammps_command(lmp, "variable three string three"); + std::string output = ::testing::internal::GetCapturedStdout(); + if (verbose) std::cout << output; + + char *ptr = lammps_expand(lmp, "xx_$(4+5)_$(PI) ${one}-${two}-${three}"); + EXPECT_NE(ptr, nullptr); + EXPECT_THAT((char *)ptr, StrEq("xx_9_3.141592653589793116 1-2-three")); + lammps_free(ptr); + + ptr = lammps_expand(lmp, "'xx_$(4+5)_$(PI) ${one}-${two}-${three}'"); + EXPECT_NE(ptr, nullptr); + EXPECT_THAT((char *)ptr, StrEq("'xx_$(4+5)_$(PI) ${one}-${two}-${three}'")); + lammps_free(ptr); +} diff --git a/unittest/python/python-commands.py b/unittest/python/python-commands.py index b1432e67b9..2066514318 100644 --- a/unittest/python/python-commands.py +++ b/unittest/python/python-commands.py @@ -528,6 +528,16 @@ create_atoms 1 single & self.assertEqual(a[0], x[0]*x[0]+x[1]*x[1]+x[2]*x[2]) self.assertEqual(a[1], x[3]*x[3]+x[4]*x[4]+x[5]*x[5]) + def test_expand(self): + self.lmp.command("variable one index 1 2 3 4"); + self.lmp.command("variable two equal 2"); + self.lmp.command("variable three string three"); + + expanded = self.lmp.expand("xx_$(4+5)_$(PI) ${one}-${two}-${three}") + self.assertEqual(expanded, "xx_9_3.141592653589793116 1-2-three") + expanded = self.lmp.expand("'xx_$(4+5)_$(PI) ${one}-${two}-${three}'") + self.assertEqual(expanded, "'xx_$(4+5)_$(PI) ${one}-${two}-${three}'") + def test_get_thermo(self): self.lmp.command("units lj") self.lmp.command("atom_style atomic")