more tests for properties and configuration

This commit is contained in:
Axel Kohlmeyer
2020-09-14 14:25:17 -04:00
parent f5e9804557
commit b455812434
2 changed files with 104 additions and 15 deletions

View File

@ -1,7 +1,7 @@
// unit tests for checking LAMMPS configuration settings through the library interface
#include "library.h"
#include "lammps.h"
#include "library.h"
#include <string>
#include "gmock/gmock.h"
@ -14,14 +14,15 @@
using ::testing::HasSubstr;
using ::testing::StartsWith;
using ::testing::StrEq;
class LAMMPS_config : public ::testing::Test {
class LibraryConfig : public ::testing::Test {
protected:
void *lmp;
std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER);
LAMMPS_config(){};
~LAMMPS_config() override{};
LibraryConfig(){};
~LibraryConfig() override{};
void SetUp() override
{
@ -49,13 +50,70 @@ protected:
}
};
TEST(LAMMPS_config, package_count)
TEST(LAMMPSConfig, package_count)
{
EXPECT_EQ(lammps_config_package_count(), NUM_LAMMPS_PACKAGES);
};
TEST(LAMMPS_config, has_package)
TEST(LAMMPSConfig, has_package)
{
EXPECT_EQ(lammps_config_has_package("MANYBODY"), LAMMPS_HAS_MANYBODY);
};
TEST(LAMMPSConfig, package_name)
{
char buf[128];
int numpkgs = lammps_config_package_count();
if (numpkgs > 0) {
EXPECT_EQ(lammps_config_package_name(0, buf, 128), 1);
EXPECT_EQ(lammps_config_package_name(numpkgs + 10, buf, 128), 0);
EXPECT_THAT(buf, StrEq(""));
} else {
EXPECT_EQ(lammps_config_package_name(0, buf, 128), 1);
EXPECT_THAT(buf, StrEq(""));
}
};
TEST_F(LibraryConfig, has_style)
{
EXPECT_EQ(lammps_has_style(lmp, "atom", "atomic"), 1);
EXPECT_EQ(lammps_has_style(lmp, "compute", "temp"), 1);
EXPECT_EQ(lammps_has_style(lmp, "fix", "nve"), 1);
EXPECT_EQ(lammps_has_style(lmp, "pair", "lj/cut"), 1);
EXPECT_EQ(lammps_has_style(lmp, "bond", "zero"), 1);
EXPECT_EQ(lammps_has_style(lmp, "dump", "custom"), 1);
EXPECT_EQ(lammps_has_style(lmp, "region", "sphere"), 1);
EXPECT_EQ(lammps_has_style(lmp, "xxxxx", "lj/cut"), 0);
EXPECT_EQ(lammps_has_style(lmp, "pair", "xxxxxx"), 0);
#if LAMMPS_HAS_MANYBODY
EXPECT_EQ(lammps_has_style(lmp, "pair", "sw"), 1);
#else
EXPECT_EQ(lammps_has_style(lmp, "pair", "sw"), 0);
#endif
};
TEST_F(LibraryConfig, style_count)
{
EXPECT_GT(lammps_style_count(lmp, "atom"), 1);
EXPECT_GT(lammps_style_count(lmp, "bond"), 1);
EXPECT_GT(lammps_style_count(lmp, "angle"), 1);
EXPECT_GT(lammps_style_count(lmp, "dihedral"), 1);
EXPECT_GT(lammps_style_count(lmp, "improper"), 1);
EXPECT_GT(lammps_style_count(lmp, "pair"), 1);
EXPECT_GT(lammps_style_count(lmp, "kspace"), 1);
EXPECT_GT(lammps_style_count(lmp, "compute"), 1);
EXPECT_GT(lammps_style_count(lmp, "fix"), 1);
EXPECT_GT(lammps_style_count(lmp, "region"), 1);
EXPECT_GT(lammps_style_count(lmp, "dump"), 1);
EXPECT_GT(lammps_style_count(lmp, "integrate"), 1);
EXPECT_GT(lammps_style_count(lmp, "minimize"), 1);
};
TEST_F(LibraryConfig, style_name)
{
char buf[128];
int numstyles = lammps_style_count(lmp, "atom");
EXPECT_EQ(lammps_style_name(lmp, "atom", 0, buf, 128), 1);
EXPECT_EQ(lammps_style_name(lmp, "atom", numstyles + 10, buf, 128), 0);
EXPECT_THAT(buf, StrEq(""));
};

View File

@ -1,7 +1,7 @@
// unit tests for checking and changing simulation properties through the library interface
#include "library.h"
#include "lammps.h"
#include "library.h"
#include <string>
#include "gmock/gmock.h"
@ -15,13 +15,13 @@
using ::testing::HasSubstr;
using ::testing::StartsWith;
class LAMMPS_properties : public ::testing::Test {
class LibraryProperties : public ::testing::Test {
protected:
void *lmp;
std::string INPUT_DIR = STRINGIFY(TEST_INPUT_FOLDER);
LAMMPS_properties(){};
~LAMMPS_properties() override{};
LibraryProperties(){};
~LibraryProperties() override{};
void SetUp() override
{
@ -49,12 +49,12 @@ protected:
}
};
TEST_F(LAMMPS_properties, version)
TEST_F(LibraryProperties, version)
{
EXPECT_GE(20200824, lammps_version(lmp));
};
TEST_F(LAMMPS_properties, get_mpi_comm)
TEST_F(LibraryProperties, get_mpi_comm)
{
int f_comm = lammps_get_mpi_comm(lmp);
if (lammps_config_has_mpi_support())
@ -63,8 +63,9 @@ TEST_F(LAMMPS_properties, get_mpi_comm)
EXPECT_EQ(f_comm, -1);
};
TEST_F(LAMMPS_properties, natoms)
TEST_F(LibraryProperties, natoms)
{
if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP();
std::string input = INPUT_DIR + PATH_SEP + "in.fourmol";
if (!verbose) ::testing::internal::CaptureStdout();
lammps_file(lmp, input.c_str());
@ -72,9 +73,9 @@ TEST_F(LAMMPS_properties, natoms)
EXPECT_EQ(lammps_get_natoms(lmp), 29);
};
TEST_F(LAMMPS_properties, thermo)
TEST_F(LibraryProperties, thermo)
{
if (!lammps_has_style(lmp,"atom","full")) GTEST_SKIP();
if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP();
std::string input = INPUT_DIR + PATH_SEP + "in.fourmol";
if (!verbose) ::testing::internal::CaptureStdout();
lammps_file(lmp, input.c_str());
@ -86,3 +87,33 @@ TEST_F(LAMMPS_properties, thermo)
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695);
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0);
};
TEST_F(LibraryProperties, box)
{
if (!lammps_has_style(lmp, "atom", "full")) GTEST_SKIP();
std::string input = INPUT_DIR + PATH_SEP + "in.fourmol";
if (!verbose) ::testing::internal::CaptureStdout();
lammps_file(lmp, input.c_str());
lammps_command(lmp, "run 2 post no");
if (!verbose) ::testing::internal::GetCapturedStdout();
double boxlo[3], boxhi[3], xy, yz, xz;
int pflags[3], boxflag;
lammps_extract_box(lmp, boxlo, boxhi, &xy, &yz, &xz, pflags, &boxflag);
EXPECT_DOUBLE_EQ(boxlo[0], -6.024572);
EXPECT_DOUBLE_EQ(boxlo[1], -7.692866);
EXPECT_DOUBLE_EQ(boxlo[2], -8.086924);
EXPECT_DOUBLE_EQ(boxhi[0], 8.975428);
EXPECT_DOUBLE_EQ(boxhi[1], 7.307134);
EXPECT_DOUBLE_EQ(boxhi[2], 6.913076);
EXPECT_DOUBLE_EQ(xy, 0.0);
EXPECT_DOUBLE_EQ(yz, 0.0);
EXPECT_DOUBLE_EQ(xz, 0.0);
EXPECT_EQ(pflags[0], 1);
EXPECT_EQ(pflags[1], 1);
EXPECT_EQ(pflags[2], 1);
EXPECT_EQ(boxflag, 0);
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "vol"), 3375.0);
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "density"), 0.12211250945013695);
EXPECT_DOUBLE_EQ(lammps_get_thermo(lmp, "cellalpha"), 90.0);
};