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 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);
};