reformat unittest sources with clang-format

This commit is contained in:
Axel Kohlmeyer
2020-11-18 18:27:20 -05:00
committed by Richard Berger
parent a8b60848c3
commit 569a000e6b
32 changed files with 2022 additions and 2071 deletions

View File

@ -1,31 +1,26 @@
// unit tests for issuing command to a LAMMPS instance through the Input class // unit tests for issuing command to a LAMMPS instance through the Input class
#include "lammps.h"
#include "input.h"
#include "atom.h" #include "atom.h"
#include "input.h"
#include "lammps.h"
#include "memory.h" #include "memory.h"
#include <cstring>
#include <mpi.h> #include <mpi.h>
#include <string> #include <string>
#include <cstring>
#include "gtest/gtest.h" #include "gtest/gtest.h"
const char *demo_input[] = { const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box",
"region box block 0 $x 0 2 0 2",
"create_box 1 box",
"create_atoms 1 single 1.0 1.0 ${zpos}"}; "create_atoms 1 single 1.0 1.0 ${zpos}"};
const char *cont_input[] = { const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"};
"create_atoms 1 single &",
"0.2 0.1 0.1" };
namespace LAMMPS_NS namespace LAMMPS_NS {
{
class Input_commands : public ::testing::Test class Input_commands : public ::testing::Test {
{
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
Input_commands() { Input_commands()
{
const char *args[] = {"LAMMPS_test"}; const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -36,13 +31,10 @@ namespace LAMMPS_NS
} }
~Input_commands() override {} ~Input_commands() override {}
void SetUp() override { void SetUp() override
const char *args[] = {"LAMMPS_test", {
"-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite",
"-echo", "screen", "-var", "zpos", "1.5", "-var", "x", "2"};
"-nocite",
"-var", "zpos", "1.5",
"-var","x","2"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -51,7 +43,8 @@ namespace LAMMPS_NS
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS ("); EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS (");
} }
void TearDown() override { void TearDown() override
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
delete lmp; delete lmp;
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
@ -60,7 +53,8 @@ namespace LAMMPS_NS
} }
}; };
TEST_F(Input_commands, from_file) { TEST_F(Input_commands, from_file)
{
FILE *fp; FILE *fp;
const char demo_file[] = "in.test"; const char demo_file[] = "in.test";
const char cont_file[] = "in.cont"; const char cont_file[] = "in.cont";
@ -87,7 +81,8 @@ namespace LAMMPS_NS
unlink(cont_file); unlink(cont_file);
}; };
TEST_F(Input_commands, from_line) { TEST_F(Input_commands, from_line)
{
EXPECT_EQ(lmp->atom->natoms, 0); EXPECT_EQ(lmp->atom->natoms, 0);
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) { for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
lmp->input->one(demo_input[i]); lmp->input->one(demo_input[i]);
@ -95,7 +90,8 @@ namespace LAMMPS_NS
EXPECT_EQ(lmp->atom->natoms, 1); EXPECT_EQ(lmp->atom->natoms, 1);
}; };
TEST_F(Input_commands, substitute) { TEST_F(Input_commands, substitute)
{
char *string, *scratch; char *string, *scratch;
int nstring = 100, nscratch = 100; int nstring = 100, nscratch = 100;
@ -111,4 +107,4 @@ namespace LAMMPS_NS
lmp->memory->destroy(string); lmp->memory->destroy(string);
lmp->memory->destroy(scratch); lmp->memory->destroy(scratch);
}; };
} } // namespace LAMMPS_NS

View File

@ -1,8 +1,8 @@
// unit tests for the LAMMPS base class // unit tests for the LAMMPS base class
#include "lammps.h" #include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout #include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string> #include <string>
#include "gmock/gmock.h" #include "gmock/gmock.h"
@ -10,13 +10,13 @@
using ::testing::StartsWith; using ::testing::StartsWith;
namespace LAMMPS_NS namespace LAMMPS_NS {
{
// test fixture for regular tests // test fixture for regular tests
class LAMMPS_plain : public ::testing::Test { class LAMMPS_plain : public ::testing::Test {
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_plain() : lmp(nullptr) { LAMMPS_plain() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"}; const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -26,15 +26,11 @@ namespace LAMMPS_NS
if (!flag) MPI_Init(&argc, &argv); if (!flag) MPI_Init(&argc, &argv);
} }
~LAMMPS_plain() override { ~LAMMPS_plain() override { lmp = nullptr; }
lmp = nullptr;
}
void SetUp() override { void SetUp() override
const char *args[] = {"LAMMPS_test", {
"-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"};
"-echo", "both",
"-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -44,7 +40,8 @@ namespace LAMMPS_NS
EXPECT_THAT(output, StartsWith("LAMMPS (")); EXPECT_THAT(output, StartsWith("LAMMPS ("));
} }
void TearDown() override { void TearDown() override
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
delete lmp; delete lmp;
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
@ -106,23 +103,21 @@ namespace LAMMPS_NS
if (lmp == nullptr) return; if (lmp == nullptr) return;
const char *found; const char *found;
const char *atom_styles[] = { const char *atom_styles[] = {"atomic", "body", "charge", "ellipsoid", "hybrid",
"atomic", "body", "charge", "ellipsoid", "hybrid",
"line", "sphere", "tri", NULL}; "line", "sphere", "tri", NULL};
for (int i = 0; atom_styles[i] != NULL; ++i) { for (int i = 0; atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom", atom_styles[i]); found = lmp->match_style("atom", atom_styles[i]);
EXPECT_STREQ(found, NULL); EXPECT_STREQ(found, NULL);
} }
const char *molecule_atom_styles[] = { const char *molecule_atom_styles[] = {"angle", "bond", "full", "molecular", "template", NULL};
"angle", "bond", "full", "molecular", "template", NULL };
for (int i = 0; molecule_atom_styles[i] != NULL; ++i) { for (int i = 0; molecule_atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom", molecule_atom_styles[i]); found = lmp->match_style("atom", molecule_atom_styles[i]);
EXPECT_STREQ(found, "MOLECULE"); EXPECT_STREQ(found, "MOLECULE");
} }
const char *kokkos_atom_styles[] = { const char *kokkos_atom_styles[] = {"angle/kk", "bond/kk", "full/kk",
"angle/kk", "bond/kk", "full/kk", "molecular/kk", "hybrid/kk", NULL }; "molecular/kk", "hybrid/kk", NULL};
for (int i = 0; kokkos_atom_styles[i] != NULL; ++i) { for (int i = 0; kokkos_atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom", kokkos_atom_styles[i]); found = lmp->match_style("atom", kokkos_atom_styles[i]);
EXPECT_STREQ(found, "KOKKOS"); EXPECT_STREQ(found, "KOKKOS");
@ -157,7 +152,8 @@ namespace LAMMPS_NS
class LAMMPS_omp : public ::testing::Test { class LAMMPS_omp : public ::testing::Test {
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_omp() : lmp(nullptr) { LAMMPS_omp() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"}; const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -167,18 +163,12 @@ namespace LAMMPS_NS
if (!flag) MPI_Init(&argc, &argv); if (!flag) MPI_Init(&argc, &argv);
} }
~LAMMPS_omp() override { ~LAMMPS_omp() override { lmp = nullptr; }
lmp = nullptr;
}
void SetUp() override { void SetUp() override
const char *args[] = {"LAMMPS_test", {
"-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen",
"-screen", "none", "-pk", "omp", "2", "neigh", "yes", "-sf", "omp"};
"-echo", "screen",
"-pk", "omp","2", "neigh", "yes",
"-sf", "omp"
};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -186,12 +176,11 @@ namespace LAMMPS_NS
if (LAMMPS::is_installed_pkg("USER-OMP")) if (LAMMPS::is_installed_pkg("USER-OMP"))
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
else GTEST_SKIP(); else
GTEST_SKIP();
} }
void TearDown() override { void TearDown() override { delete lmp; }
delete lmp;
}
}; };
TEST_F(LAMMPS_omp, InitMembers) TEST_F(LAMMPS_omp, InitMembers)
@ -246,7 +235,8 @@ namespace LAMMPS_NS
class LAMMPS_kokkos : public ::testing::Test { class LAMMPS_kokkos : public ::testing::Test {
protected: protected:
LAMMPS *lmp; LAMMPS *lmp;
LAMMPS_kokkos() : lmp(nullptr) { LAMMPS_kokkos() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"}; const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -256,18 +246,12 @@ namespace LAMMPS_NS
if (!flag) MPI_Init(&argc, &argv); if (!flag) MPI_Init(&argc, &argv);
} }
~LAMMPS_kokkos() override { ~LAMMPS_kokkos() override { lmp = nullptr; }
lmp = nullptr;
}
void SetUp() override { void SetUp() override
const char *args[] = {"LAMMPS_test", {
"-log", "none", const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none",
"-echo", "none", "-k", "on", "t", "2", "-sf", "kk"};
"-screen", "none",
"-k", "on","t", "2",
"-sf", "kk"
};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -279,12 +263,11 @@ namespace LAMMPS_NS
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::")); EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::"));
} else GTEST_SKIP(); } else
GTEST_SKIP();
} }
void TearDown() override { void TearDown() override { delete lmp; }
delete lmp;
}
}; };
TEST_F(LAMMPS_kokkos, InitMembers) TEST_F(LAMMPS_kokkos, InitMembers)
@ -336,7 +319,8 @@ namespace LAMMPS_NS
} }
// check help message printing // check help message printing
TEST(LAMMPS_help, HelpMessage) { TEST(LAMMPS_help, HelpMessage)
{
const char *args[] = {"LAMMPS_test", "-h"}; const char *args[] = {"LAMMPS_test", "-h"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
@ -348,4 +332,4 @@ namespace LAMMPS_NS
StartsWith("\nLarge-scale Atomic/Molecular Massively Parallel Simulator -")); StartsWith("\nLarge-scale Atomic/Molecular Massively Parallel Simulator -"));
delete lmp; delete lmp;
} }
} } // namespace LAMMPS_NS

View File

@ -519,8 +519,8 @@ TEST(FixTimestep, plain)
// rigid fixes need work to test properly with r-RESPA. // rigid fixes need work to test properly with r-RESPA.
// fix nve/limit cannot work with r-RESPA // fix nve/limit cannot work with r-RESPA
ifix = lmp->modify->find_fix("test"); ifix = lmp->modify->find_fix("test");
if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") &&
&& !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) { !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) {
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config); cleanup_lammps(lmp, test_config);

View File

@ -12,9 +12,9 @@
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "test_main.h" #include "test_main.h"
#include "pointers.h"
#include "test_config.h" #include "test_config.h"
#include "test_config_reader.h" #include "test_config_reader.h"
#include "pointers.h"
#include "utils.h" #include "utils.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"

View File

@ -209,7 +209,6 @@ struct AtomState {
int eff_plastic_strain_rate_flag = 0; int eff_plastic_strain_rate_flag = 0;
double pdscale = 1.0; double pdscale = 1.0;
int maxspecial = 1; int maxspecial = 1;
int nmolecule = 0; int nmolecule = 0;
@ -258,7 +257,8 @@ struct AtomState {
ASSERT_EQ(ptr, nullptr); \ ASSERT_EQ(ptr, nullptr); \
} }
void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) { void ASSERT_ATOM_STATE_EQ(Atom *atom, const AtomState &expected)
{
ASSERT_THAT(std::string(atom->atom_style), Eq(expected.atom_style)); ASSERT_THAT(std::string(atom->atom_style), Eq(expected.atom_style));
ASSERT_NE(atom->avec, nullptr); ASSERT_NE(atom->avec, nullptr);
@ -3407,7 +3407,6 @@ TEST_F(AtomStyleTest, template_charge)
ASSERT_EQ(lmp->atom->tag_consecutive(), 1); ASSERT_EQ(lmp->atom->tag_consecutive(), 1);
ASSERT_EQ(lmp->atom->map_tag_max, 16); ASSERT_EQ(lmp->atom->map_tag_max, 16);
type = lmp->atom->type; type = lmp->atom->type;
molecule = lmp->atom->molecule; molecule = lmp->atom->molecule;
molindex = lmp->atom->molindex; molindex = lmp->atom->molindex;

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string> #include <string>
@ -27,14 +27,17 @@ char * BINARY2TXT_BINARY = nullptr;
class DumpAtomTest : public MeltTest { class DumpAtomTest : public MeltTest {
std::string dump_style = "atom"; std::string dump_style = "atom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,9 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string dump_modify_options, int ntimesteps) { void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file)); command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file));
@ -60,7 +65,8 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_binary_to_text(std::string binary_file) { std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str()); system(cmdline.c_str());
@ -501,8 +507,7 @@ TEST_F(DumpAtomTest, dump_modify_scale_invalid)
command("dump id all atom 1 dump.txt"); command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*", TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id scale true"););
command("dump_modify id scale true"););
} }
TEST_F(DumpAtomTest, dump_modify_image_invalid) TEST_F(DumpAtomTest, dump_modify_image_invalid)
@ -511,8 +516,7 @@ TEST_F(DumpAtomTest, dump_modify_image_invalid)
command("dump id all atom 1 dump.txt"); command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*", TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id image true"););
command("dump_modify id image true"););
} }
TEST_F(DumpAtomTest, dump_modify_invalid) TEST_F(DumpAtomTest, dump_modify_invalid)
@ -521,8 +525,7 @@ TEST_F(DumpAtomTest, dump_modify_invalid)
command("dump id all atom 1 dump.txt"); command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*", TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id true"););
command("dump_modify id true"););
} }
TEST_F(DumpAtomTest, write_dump) TEST_F(DumpAtomTest, write_dump)

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string> #include <string>
@ -27,14 +27,17 @@ using ::testing::Eq;
class DumpAtomGZTest : public MeltTest { class DumpAtomGZTest : public MeltTest {
std::string dump_style = "atom"; std::string dump_style = "atom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) { void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -60,17 +66,18 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
} }
}; };
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// GZ compressed files // GZ compressed files
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
@ -106,7 +113,8 @@ TEST_F(DumpAtomGZTest, compressed_with_units_run0)
auto text_file = "dump_gz_text_with_units_run0.melt"; auto text_file = "dump_gz_text_with_units_run0.melt";
auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz"; auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes",
0);
TearDown(); TearDown();
@ -129,7 +137,8 @@ TEST_F(DumpAtomGZTest, compressed_with_time_run0)
auto text_file = "dump_gz_text_with_time_run0.melt"; auto text_file = "dump_gz_text_with_time_run0.melt";
auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz"; auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes",
0);
TearDown(); TearDown();
@ -177,7 +186,8 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0)
auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz"; auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz";
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes",
0);
TearDown(); TearDown();
@ -201,7 +211,8 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0)
auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz"; auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz";
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes",
0);
TearDown(); TearDown();

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string> #include <string>
@ -27,14 +27,17 @@ using ::testing::Eq;
class DumpAtomZSTDTest : public MeltTest { class DumpAtomZSTDTest : public MeltTest {
std::string dump_style = "atom"; std::string dump_style = "atom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) { void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -60,17 +66,18 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
} }
}; };
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// ZSTD compressed files // ZSTD compressed files
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
@ -107,7 +114,8 @@ TEST_F(DumpAtomZSTDTest, compressed_with_units_run0)
auto text_file = "dump_zstd_text_with_units_run0.melt"; auto text_file = "dump_zstd_text_with_units_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst"; auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes",
0);
// make sure file is closed // make sure file is closed
TearDown(); TearDown();
@ -131,7 +139,8 @@ TEST_F(DumpAtomZSTDTest, compressed_with_time_run0)
auto text_file = "dump_zstd_text_with_time_run0.melt"; auto text_file = "dump_zstd_text_with_time_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst"; auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes",
0);
// make sure file is closed // make sure file is closed
TearDown(); TearDown();
@ -181,7 +190,8 @@ TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0)
auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst"; auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst";
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes",
0);
// make sure file is closed // make sure file is closed
TearDown(); TearDown();
@ -206,7 +216,8 @@ TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0)
auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst"; auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst";
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0); generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes",
0);
// make sure file is closed // make sure file is closed
TearDown(); TearDown();

View File

@ -11,20 +11,23 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq; using ::testing::Eq;
class DumpCfgTest : public MeltTest { class DumpCfgTest : public MeltTest {
std::string dump_style = "cfg"; std::string dump_style = "cfg";
public: public:
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -40,22 +43,20 @@ public:
TEST_F(DumpCfgTest, invalid_options) TEST_F(DumpCfgTest, invalid_options)
{ {
TEST_FAILURE(".*Dump cfg arguments must start with 'mass type xs ys zs'.*", TEST_FAILURE(".*Dump cfg arguments must start with 'mass type xs ys zs'.*",
command("dump id all cfg 1 dump.cfg id type proc procp1 mass x y z"); command("dump id all cfg 1 dump.cfg id type proc procp1 mass x y z"););
);
} }
TEST_F(DumpCfgTest, require_multifile) TEST_F(DumpCfgTest, require_multifile)
{ {
auto dump_file = "dump.melt.cfg_run.cfg"; auto dump_file = "dump.melt.cfg_run.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz"; auto fields =
"mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields)); command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields));
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", command("run 0"););
command("run 0");
);
} }
TEST_F(DumpCfgTest, run0) TEST_F(DumpCfgTest, run0)
@ -114,7 +115,6 @@ TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg"); delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *GZIP_BINARY = nullptr; char *GZIP_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpCfgGZTest : public MeltTest { class DumpCfgGZTest : public MeltTest {
std::string dump_style = "cfg"; std::string dump_style = "cfg";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
@ -77,7 +82,6 @@ TEST_F(DumpCfgGZTest, compressed_run0)
delete_file(converted_file); delete_file(converted_file);
} }
TEST_F(DumpCfgGZTest, compressed_unwrap_run0) TEST_F(DumpCfgGZTest, compressed_unwrap_run0)
{ {
if (!GZIP_BINARY) GTEST_SKIP(); if (!GZIP_BINARY) GTEST_SKIP();

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *ZSTD_BINARY = nullptr; char *ZSTD_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpCfgZstdTest : public MeltTest { class DumpCfgZstdTest : public MeltTest {
std::string dump_style = "cfg"; std::string dump_style = "cfg";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
@ -77,7 +82,6 @@ TEST_F(DumpCfgZstdTest, compressed_run0)
delete_file(converted_file); delete_file(converted_file);
} }
TEST_F(DumpCfgZstdTest, compressed_unwrap_run0) TEST_F(DumpCfgZstdTest, compressed_unwrap_run0)
{ {
if (!ZSTD_BINARY) GTEST_SKIP(); if (!ZSTD_BINARY) GTEST_SKIP();

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq; using ::testing::Eq;
@ -25,14 +25,18 @@ char * BINARY2TXT_BINARY = nullptr;
class DumpCustomTest : public MeltTest { class DumpCustomTest : public MeltTest {
std::string dump_style = "custom"; std::string dump_style = "custom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string fields, void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string dump_modify_options, int ntimesteps) { std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields));
@ -59,7 +65,8 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_binary_to_text(std::string binary_file) { std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file); std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str()); system(cmdline.c_str());
@ -71,7 +78,8 @@ public:
TEST_F(DumpCustomTest, run1) TEST_F(DumpCustomTest, run1)
{ {
auto dump_file = "dump_custom_run1.melt"; auto dump_file = "dump_custom_run1.melt";
auto fields = "id type proc procp1 mass x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; auto fields =
"id type proc procp1 mass x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_dump(dump_file, fields, "units yes", 1); generate_dump(dump_file, fields, "units yes", 1);
@ -253,7 +261,6 @@ TEST_F(DumpCustomTest, with_variable_run1)
delete_file(dump_file); delete_file(dump_file);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq; using ::testing::Eq;
@ -25,14 +25,18 @@ char * GZIP_BINARY = nullptr;
class DumpCustomGZTest : public MeltTest { class DumpCustomGZTest : public MeltTest {
std::string dump_style = "custom"; std::string dump_style = "custom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -59,10 +65,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
@ -77,7 +85,8 @@ TEST_F(DumpCustomGZTest, compressed_run1)
auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz"; auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1); generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes",
1);
TearDown(); TearDown();
@ -103,7 +112,8 @@ TEST_F(DumpCustomGZTest, compressed_triclinic_run1)
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1); generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes",
1);
TearDown(); TearDown();

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq; using ::testing::Eq;
@ -25,14 +25,18 @@ char * ZSTD_BINARY = nullptr;
class DumpCustomZstdTest : public MeltTest { class DumpCustomZstdTest : public MeltTest {
std::string dump_style = "custom"; std::string dump_style = "custom";
public: public:
void enable_triclinic() { void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic"); command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) { void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -59,10 +65,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;
@ -77,7 +85,8 @@ TEST_F(DumpCustomZstdTest, compressed_run1)
auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst"; auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1); generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields,
"units yes", 1);
TearDown(); TearDown();
@ -103,7 +112,8 @@ TEST_F(DumpCustomZstdTest, compressed_triclinic_run1)
enable_triclinic(); enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1); generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields,
"units yes", 1);
TearDown(); TearDown();

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *GZIP_BINARY = nullptr; char *GZIP_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpLocalGZTest : public MeltTest { class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local"; std::string dump_style = "local";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *ZSTD_BINARY = nullptr; char *ZSTD_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpLocalGZTest : public MeltTest { class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local"; std::string dump_style = "local";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string fields, std::string dump_modify_options, int ntimesteps) { std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *GZIP_BINARY = nullptr; char *GZIP_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpXYZGZTest : public MeltTest { class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz"; std::string dump_style = "xyz";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string dump_modify_options, int ntimesteps) { std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;

View File

@ -11,13 +11,13 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h" #include "../testing/core.h"
#include "../testing/systems/melt.h" #include "../testing/systems/melt.h"
#include "../testing/utils.h" #include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char *ZSTD_BINARY = nullptr; char *ZSTD_BINARY = nullptr;
@ -25,9 +25,12 @@ using ::testing::Eq;
class DumpXYZGZTest : public MeltTest { class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz"; std::string dump_style = "xyz";
public: public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string dump_modify_options, int ntimesteps) { std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
std::string convert_compressed_to_text(std::string compressed_file) { std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str()); system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file; return converted_file;

View File

@ -657,8 +657,7 @@ TEST_F(PairUnitConvertTest, table_real2metal)
f = lmp->atom->f; f = lmp->atom->f;
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
for (int j = 0; j < 3; ++j) for (int j = 0; j < 3; ++j)
EXPECT_NEAR(1.0/ev_convert * fold[i][j], f[i][j], EXPECT_NEAR(1.0 / ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
fabs(f[i][j] * rel_error));
} }
TEST_F(PairUnitConvertTest, tersoff) TEST_F(PairUnitConvertTest, tersoff)

View File

@ -31,8 +31,8 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include <vector>
#include <mpi.h> #include <mpi.h>
#include <vector>
#if defined(OMPI_MAJOR_VERSION) #if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true; const bool have_openmpi = true;

View File

@ -1,8 +1,8 @@
// unit tests for issuing command to a LAMMPS instance through the Fortran wrapper // unit tests for issuing command to a LAMMPS instance through the Fortran wrapper
#include "lammps.h" #include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout #include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -18,20 +18,21 @@ extern "C" {
double f_lammps_get_natoms(); double f_lammps_get_natoms();
} }
class LAMMPS_commands : public ::testing::Test class LAMMPS_commands : public ::testing::Test {
{
protected: protected:
LAMMPS_NS::LAMMPS *lmp; LAMMPS_NS::LAMMPS *lmp;
LAMMPS_commands(){}; LAMMPS_commands(){};
~LAMMPS_commands() override{}; ~LAMMPS_commands() override{};
void SetUp() override { void SetUp() override
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_args(); lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_args();
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS ("); EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS (");
} }
void TearDown() override { void TearDown() override
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
f_lammps_close(); f_lammps_close();
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
@ -40,25 +41,29 @@ protected:
} }
}; };
TEST_F(LAMMPS_commands, from_file) { TEST_F(LAMMPS_commands, from_file)
{
EXPECT_EQ(f_lammps_get_natoms(), 0); EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_file(); f_lammps_file();
EXPECT_EQ(f_lammps_get_natoms(), 2); EXPECT_EQ(f_lammps_get_natoms(), 2);
}; };
TEST_F(LAMMPS_commands, from_line) { TEST_F(LAMMPS_commands, from_line)
{
EXPECT_EQ(f_lammps_get_natoms(), 0); EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_command(); f_lammps_command();
EXPECT_EQ(f_lammps_get_natoms(), 1); EXPECT_EQ(f_lammps_get_natoms(), 1);
}; };
TEST_F(LAMMPS_commands, from_list) { TEST_F(LAMMPS_commands, from_list)
{
EXPECT_EQ(f_lammps_get_natoms(), 0); EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_commands_list(); f_lammps_commands_list();
EXPECT_EQ(f_lammps_get_natoms(), 2); EXPECT_EQ(f_lammps_get_natoms(), 2);
}; };
TEST_F(LAMMPS_commands, from_string) { TEST_F(LAMMPS_commands, from_string)
{
EXPECT_EQ(f_lammps_get_natoms(), 0); EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_commands_string(); f_lammps_commands_string();
EXPECT_EQ(f_lammps_get_natoms(), 2); EXPECT_EQ(f_lammps_get_natoms(), 2);

View File

@ -1,8 +1,8 @@
// unit tests for the LAMMPS base class // unit tests for the LAMMPS base class
#include "lammps.h" #include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout #include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string> #include <string>
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -17,7 +17,8 @@ extern "C" {
int f_lammps_get_comm(); int f_lammps_get_comm();
} }
TEST(open_no_mpi, no_args) { TEST(open_no_mpi, no_args)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
int mpi_init = 0; int mpi_init = 0;
MPI_Initialized(&mpi_init); MPI_Initialized(&mpi_init);
@ -38,7 +39,8 @@ TEST(open_no_mpi, no_args) {
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:"); EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
} }
TEST(open_no_mpi, with_args) { TEST(open_no_mpi, with_args)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *handle = f_lammps_no_mpi_with_args(); void *handle = f_lammps_no_mpi_with_args();
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
@ -56,7 +58,8 @@ TEST(open_no_mpi, with_args) {
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:"); EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
} }
TEST(fortran_open, no_args) { TEST(fortran_open, no_args)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *handle = f_lammps_open_no_args(); void *handle = f_lammps_open_no_args();
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();
@ -75,7 +78,8 @@ TEST(fortran_open, no_args) {
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:"); EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
} }
TEST(fortran_open, with_args) { TEST(fortran_open, with_args)
{
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
void *handle = f_lammps_open_with_args(); void *handle = f_lammps_open_with_args();
std::string output = ::testing::internal::GetCapturedStdout(); std::string output = ::testing::internal::GetCapturedStdout();

View File

@ -32,8 +32,8 @@ bool verbose = false;
using LAMMPS_NS::utils::split_words; using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS { namespace LAMMPS_NS {
using ::testing::StrEq;
using ::testing::MatchesRegex; using ::testing::MatchesRegex;
using ::testing::StrEq;
class PythonPackageTest : public ::testing::Test { class PythonPackageTest : public ::testing::Test {
protected: protected:

View File

@ -41,12 +41,9 @@ using ::testing::MatchesRegex;
// whether to print verbose output (i.e. not capturing LAMMPS screen output). // whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false; bool verbose = false;
class LAMMPSTest : public ::testing::Test { class LAMMPSTest : public ::testing::Test {
public: public:
void command(const std::string &line) { void command(const std::string &line) { lmp->input->one(line.c_str()); }
lmp->input->one(line.c_str());
}
protected: protected:
const char *testbinary = "LAMMPSTest"; const char *testbinary = "LAMMPSTest";
@ -63,9 +60,7 @@ protected:
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
virtual void InitSystem() {}
virtual void InitSystem() {
}
void TearDown() override void TearDown() override
{ {
@ -76,5 +71,4 @@ protected:
} }
}; };
#endif #endif

View File

@ -17,7 +17,8 @@
class MeltTest : public LAMMPSTest { class MeltTest : public LAMMPSTest {
protected: protected:
virtual void InitSystem() override { virtual void InitSystem() override
{
command("units lj"); command("units lj");
command("atom_style atomic"); command("atom_style atomic");
command("atom_modify map yes"); command("atom_modify map yes");

View File

@ -13,12 +13,12 @@
#ifndef TEST_EXTENSIONS__H #ifndef TEST_EXTENSIONS__H
#define TEST_EXTENSIONS__H #define TEST_EXTENSIONS__H
#include <string>
#include <vector>
#include <iostream>
#include <fstream> #include <fstream>
#include <sys/types.h> #include <iostream>
#include <string>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <vector>
static void delete_file(const std::string &filename) static void delete_file(const std::string &filename)
{ {
@ -51,7 +51,8 @@ static bool equal_lines(const std::string &fileA, const std::string &fileB)
return true; return true;
} }
static std::vector<std::string> read_lines(const std::string &filename) { static std::vector<std::string> read_lines(const std::string &filename)
{
std::vector<std::string> lines; std::vector<std::string> lines;
std::ifstream infile(filename); std::ifstream infile(filename);
std::string line; std::string line;
@ -62,7 +63,8 @@ static std::vector<std::string> read_lines(const std::string &filename) {
return lines; return lines;
} }
static bool file_exists(const std::string &filename) { static bool file_exists(const std::string &filename)
{
struct stat result; struct stat result;
return stat(filename.c_str(), &result) == 0; return stat(filename.c_str(), &result) == 0;
} }

View File

@ -1,27 +1,26 @@
// THIS FILE USED TO BE EASY TO READ until I added "#if defined" statements. // THIS FILE USED TO BE EASY TO READ until I added "#if defined" statements.
// (They were added to test for many different kinds of array formats.) // (They were added to test for many different kinds of array formats.)
#include <iostream>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <chrono>
#include <random>
#include <algorithm>
#include <vector>
#include <array>
#include "math_eigen_impl.h" #include "math_eigen_impl.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
using std::cout; using std::array;
using std::cerr; using std::cerr;
using std::cout;
using std::endl; using std::endl;
using std::setprecision; using std::setprecision;
using std::vector; using std::vector;
using std::array;
using namespace MathEigen; using namespace MathEigen;
// This code works with various types of C++ matrices (for example, // This code works with various types of C++ matrices (for example,
// double **, vector<vector<double>> array<array<double,5>,5>). // double **, vector<vector<double>> array<array<double,5>,5>).
// I use "#if defined" statements to test different matrix types. // I use "#if defined" statements to test different matrix types.
@ -33,52 +32,40 @@ const int NF=5; //(the array size must be known at compile time)
const int NF = 5; //(the array size must be known at compile time) const int NF = 5; //(the array size must be known at compile time)
#endif #endif
// @brief Are two numbers "similar"? // @brief Are two numbers "similar"?
template <typename Scalar> template <typename Scalar>
inline static bool Similar(Scalar a, Scalar b, inline static bool Similar(Scalar a, Scalar b, Scalar eps = 1.0e-06, Scalar ratio = 1.0e-06,
Scalar eps=1.0e-06,
Scalar ratio=1.0e-06,
Scalar ratio_denom = 1.0) Scalar ratio_denom = 1.0)
{ {
return ((std::abs(a-b)<=std::abs(eps)) return ((std::abs(a - b) <= std::abs(eps)) ||
|| (std::abs(ratio_denom) * std::abs(a - b) <=
(std::abs(ratio_denom)*std::abs(a-b)
<=
std::abs(ratio) * 0.5 * (std::abs(a) + std::abs(b)))); std::abs(ratio) * 0.5 * (std::abs(a) + std::abs(b))));
} }
/// @brief Are two vectors (containing n numbers) similar? /// @brief Are two vectors (containing n numbers) similar?
template <typename Scalar, typename Vector> template <typename Scalar, typename Vector>
inline static bool SimilarVec(Vector a, Vector b, int n, inline static bool SimilarVec(Vector a, Vector b, int n, Scalar eps = 1.0e-06,
Scalar eps=1.0e-06, Scalar ratio = 1.0e-06, Scalar ratio_denom = 1.0)
Scalar ratio=1.0e-06,
Scalar ratio_denom=1.0)
{ {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
if (not Similar(a[i], b[i], eps, ratio, ratio_denom)) if (not Similar(a[i], b[i], eps, ratio, ratio_denom)) return false;
return false;
return true; return true;
} }
/// @brief Are two vectors (or their reflections) similar? /// @brief Are two vectors (or their reflections) similar?
template <typename Scalar, typename Vector> template <typename Scalar, typename Vector>
inline static bool SimilarVecUnsigned(Vector a, Vector b, int n, inline static bool SimilarVecUnsigned(Vector a, Vector b, int n, Scalar eps = 1.0e-06,
Scalar eps=1.0e-06, Scalar ratio = 1.0e-06, Scalar ratio_denom = 1.0)
Scalar ratio=1.0e-06,
Scalar ratio_denom=1.0)
{ {
if (SimilarVec(a, b, n, eps)) if (SimilarVec(a, b, n, eps))
return true; return true;
else { else {
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
if (not Similar(a[i], -b[i], eps, ratio, ratio_denom)) if (not Similar(a[i], -b[i], eps, ratio, ratio_denom)) return false;
return false;
return true; return true;
} }
} }
/// @brief Multiply two matrices A and B, store the result in C. (C = AB). /// @brief Multiply two matrices A and B, store the result in C. (C = AB).
template <typename Matrix, typename ConstMatrix> template <typename Matrix, typename ConstMatrix>
@ -104,37 +91,25 @@ void mmult(ConstMatrix A, //<! input array
C[i][j] += A[i][k] * B[k][j]; C[i][j] += A[i][k] * B[k][j];
} }
/// @brief /// @brief
/// Sort the rows of a matrix "evec" by the numbers contained in "eval" /// Sort the rows of a matrix "evec" by the numbers contained in "eval"
///(This is a simple O(n^2) sorting method, but O(n^2) is a lower bound anyway.) ///(This is a simple O(n^2) sorting method, but O(n^2) is a lower bound anyway.)
/// This is the same as the Jacobi::SortRows(), but that function is private. /// This is the same as the Jacobi::SortRows(), but that function is private.
template <typename Scalar, typename Vector, typename Matrix> template <typename Scalar, typename Vector, typename Matrix>
void void SortRows(Vector eval, Matrix evec, int n, bool sort_decreasing = true, bool sort_abs = false)
SortRows(Vector eval,
Matrix evec,
int n,
bool sort_decreasing=true,
bool sort_abs=false)
{ {
for (int i = 0; i < n - 1; i++) { for (int i = 0; i < n - 1; i++) {
int i_max = i; int i_max = i;
for (int j = i + 1; j < n; j++) { for (int j = i + 1; j < n; j++) {
if (sort_decreasing) { if (sort_decreasing) {
if (sort_abs) { // sort by absolute value? if (sort_abs) { // sort by absolute value?
if (std::abs(eval[j]) > std::abs(eval[i_max])) if (std::abs(eval[j]) > std::abs(eval[i_max])) i_max = j;
} else if (eval[j] > eval[i_max])
i_max = j; i_max = j;
} } else {
else if (eval[j] > eval[i_max])
i_max = j;
}
else {
if (sort_abs) { // sort by absolute value? if (sort_abs) { // sort by absolute value?
if (std::abs(eval[j]) < std::abs(eval[i_max])) if (std::abs(eval[j]) < std::abs(eval[i_max])) i_max = j;
i_max = j; } else if (eval[j] < eval[i_max])
}
else if (eval[j] < eval[i_max])
i_max = j; i_max = j;
} }
} }
@ -144,14 +119,10 @@ SortRows(Vector eval,
} }
} }
/// @brief Generate a random orthonormal n x n matrix /// @brief Generate a random orthonormal n x n matrix
template <typename Scalar, typename Matrix> template <typename Scalar, typename Matrix>
void GenRandOrth(Matrix R, void GenRandOrth(Matrix R, int n, std::default_random_engine &rand_generator)
int n,
std::default_random_engine &rand_generator)
{ {
std::normal_distribution<Scalar> gaussian_distribution(0, 1); std::normal_distribution<Scalar> gaussian_distribution(0, 1);
std::vector<Scalar> v(n); std::vector<Scalar> v(n);
@ -191,8 +162,6 @@ void GenRandOrth(Matrix R,
} // for (int i = 0; i < n; i++) } // for (int i = 0; i < n; i++)
} // void GenRandOrth() } // void GenRandOrth()
/// @brief Generate a random symmetric n x n matrix, M. /// @brief Generate a random symmetric n x n matrix, M.
/// This function generates random numbers for the eigenvalues ("evals_known") /// This function generates random numbers for the eigenvalues ("evals_known")
/// as well as the eigenvectors ("evecs_known"), and uses them to generate M. /// as well as the eigenvectors ("evecs_known"), and uses them to generate M.
@ -221,8 +190,7 @@ void GenRandSymm(Matrix M, //<! store the matrix here
std::uniform_real_distribution<Scalar> random_real01; std::uniform_real_distribution<Scalar> random_real01;
std::normal_distribution<Scalar> gaussian_distribution(0, max_eval_size); std::normal_distribution<Scalar> gaussian_distribution(0, max_eval_size);
bool use_log_uniform_distribution = false; bool use_log_uniform_distribution = false;
if (min_eval_size > 0.0) if (min_eval_size > 0.0) use_log_uniform_distribution = true;
use_log_uniform_distribution = true;
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
vector<vector<Scalar>> D(n, vector<Scalar>(n)); vector<vector<Scalar>> D(n, vector<Scalar>(n));
vector<vector<Scalar>> tmp(n, vector<Scalar>(n)); vector<vector<Scalar>> tmp(n, vector<Scalar>(n));
@ -249,10 +217,8 @@ void GenRandSymm(Matrix M, //<! store the matrix here
Scalar log_eval = (log_min + random_real01(rand_generator) * (log_max - log_min)); Scalar log_eval = (log_min + random_real01(rand_generator) * (log_max - log_min));
evals[i] = std::exp(log_eval); evals[i] = std::exp(log_eval);
// also consider both positive and negative eigenvalues: // also consider both positive and negative eigenvalues:
if (random_real01(rand_generator) < 0.5) if (random_real01(rand_generator) < 0.5) evals[i] = -evals[i];
evals[i] = -evals[i]; } else {
}
else {
evals[i] = gaussian_distribution(rand_generator); evals[i] = gaussian_distribution(rand_generator);
} }
} }
@ -319,8 +285,6 @@ void GenRandSymm(Matrix M, //<! store the matrix here
#endif #endif
} // GenRandSymm() } // GenRandSymm()
template <typename Scalar> template <typename Scalar>
void TestJacobi(int n, //<! matrix size void TestJacobi(int n, //<! matrix size
int n_matrices = 100, //<! number of matrices to test int n_matrices = 100, //<! number of matrices to test
@ -330,8 +294,7 @@ void TestJacobi(int n, //<! matrix size
int n_degeneracy = 1, //<! repeated eigenvalues? int n_degeneracy = 1, //<! repeated eigenvalues?
unsigned seed = 0, //<! random seed (if 0 then use the clock) unsigned seed = 0, //<! random seed (if 0 then use the clock)
Scalar eps=1.0e-06 Scalar eps = 1.0e-06)
)
{ {
bool test_code_coverage = false; bool test_code_coverage = false;
if (n_tests_per_matrix < 1) { if (n_tests_per_matrix < 1) {
@ -347,8 +310,6 @@ void TestJacobi(int n, //<! matrix size
seed = std::chrono::system_clock::now().time_since_epoch().count(); seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine rand_generator(seed); std::default_random_engine rand_generator(seed);
// Create an instance of the Jacobi diagonalizer, and allocate the matrix // Create an instance of the Jacobi diagonalizer, and allocate the matrix
// we will test it on, as well as the arrays that will store the resulting // we will test it on, as well as the arrays that will store the resulting
// eigenvalues and eigenvectors. // eigenvalues and eigenvectors.
@ -357,10 +318,8 @@ void TestJacobi(int n, //<! matrix size
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
Jacobi<Scalar, Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &, const vector<vector<Scalar>> &>
vector<Scalar>&, ecalc(n);
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& > ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors // allocate the matrix, eigenvalues, eigenvectors
vector<vector<Scalar>> M(n, vector<Scalar>(n)); vector<vector<Scalar>> M(n, vector<Scalar>(n));
@ -374,12 +333,12 @@ void TestJacobi(int n, //<! matrix size
n = NF; n = NF;
cout << "Testing std::array (fixed size).\n" cout << "Testing std::array (fixed size).\n"
"(Ignoring first argument, and setting matrix size to " << n << ")" << endl; "(Ignoring first argument, and setting matrix size to "
<< n << ")" << endl;
Jacobi<Scalar, Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
array<Scalar, NF>&, const array<array<Scalar, NF>, NF> &>
array<array<Scalar, NF>, NF>&, ecalc(n);
const array<array<Scalar, NF>, NF>&> ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors // allocate the matrix, eigenvalues, eigenvectors
array<array<Scalar, NF>, NF> M; array<array<Scalar, NF>, NF> M;
@ -393,11 +352,9 @@ void TestJacobi(int n, //<! matrix size
n = NF; n = NF;
cout << "Testing C fixed size arrays.\n" cout << "Testing C fixed size arrays.\n"
"(Ignoring first argument, and setting matrix size to " << n << ")" << endl; "(Ignoring first argument, and setting matrix size to "
Jacobi<Scalar, << n << ")" << endl;
Scalar*, Jacobi<Scalar, Scalar *, Scalar(*)[NF], Scalar const(*)[NF]> ecalc(n);
Scalar (*)[NF],
Scalar const (*)[NF]> ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors // allocate the matrix, eigenvalues, eigenvectors
Scalar M[NF][NF]; Scalar M[NF][NF];
@ -434,7 +391,6 @@ void TestJacobi(int n, //<! matrix size
#endif #endif
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Now, generate random matrices and test Jacobi::Diagonalize() on them. // Now, generate random matrices and test Jacobi::Diagonalize() on them.
// -------------------------------------------------------------------- // --------------------------------------------------------------------
@ -454,13 +410,7 @@ void TestJacobi(int n, //<! matrix size
#else #else
GenRandSymm<Scalar, Scalar *, Scalar **> GenRandSymm<Scalar, Scalar *, Scalar **>
#endif #endif
(M, (M, n, evals_known, evecs_known, rand_generator, min_eval_size, max_eval_size,
n,
evals_known,
evecs_known,
rand_generator,
min_eval_size,
max_eval_size,
n_degeneracy); n_degeneracy);
// Sort the matrix evals and eigenvector rows: // Sort the matrix evals and eigenvector rows:
@ -478,7 +428,6 @@ void TestJacobi(int n, //<! matrix size
#endif #endif
(evals_known, evecs_known, n); (evals_known, evecs_known, n);
if (n_matrices == 1) { if (n_matrices == 1) {
cout << "Eigenvalues (after sorting):\n"; cout << "Eigenvalues (after sorting):\n";
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
@ -490,7 +439,8 @@ void TestJacobi(int n, //<! matrix size
cout << evecs_known[i][j] << " "; cout << evecs_known[i][j] << " ";
cout << "\n"; cout << "\n";
} }
cout << " (The eigenvectors calculated by Jacobi::Diagonalize() should match these.)\n"; cout
<< " (The eigenvectors calculated by Jacobi::Diagonalize() should match these.)\n";
} }
for (int i_test = 0; i_test < n_tests_per_matrix; i_test++) { for (int i_test = 0; i_test < n_tests_per_matrix; i_test++) {
@ -499,36 +449,22 @@ void TestJacobi(int n, //<! matrix size
// test SORT_INCREASING_ABS_EVALS: // test SORT_INCREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar>> &>::SORT_INCREASING_ABS_EVALS); const vector<vector<Scalar>> &>::SORT_INCREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS #elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_ABS_EVALS); const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS #elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar(*)[NF],
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const(*)[NF]>::SORT_INCREASING_ABS_EVALS); Scalar const(*)[NF]>::SORT_INCREASING_ABS_EVALS);
#else #else
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar **,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const *const *>::SORT_INCREASING_ABS_EVALS); Scalar const *const *>::SORT_INCREASING_ABS_EVALS);
#endif #endif
@ -537,36 +473,22 @@ void TestJacobi(int n, //<! matrix size
// test SORT_DECREASING_ABS_EVALS: // test SORT_DECREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar>> &>::SORT_DECREASING_ABS_EVALS); const vector<vector<Scalar>> &>::SORT_DECREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS #elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar, NF>, NF> &>::SORT_DECREASING_ABS_EVALS); const array<array<Scalar, NF>, NF> &>::SORT_DECREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS #elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar(*)[NF],
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const(*)[NF]>::SORT_DECREASING_ABS_EVALS); Scalar const(*)[NF]>::SORT_DECREASING_ABS_EVALS);
#else #else
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar **,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const *const *>::SORT_DECREASING_ABS_EVALS); Scalar const *const *>::SORT_DECREASING_ABS_EVALS);
#endif #endif
@ -575,36 +497,21 @@ void TestJacobi(int n, //<! matrix size
// test SORT_INCREASING_EVALS: // test SORT_INCREASING_EVALS:
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar>> &>::SORT_INCREASING_EVALS); const vector<vector<Scalar>> &>::SORT_INCREASING_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS #elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_EVALS); const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS #elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar(*)[NF],
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const(*)[NF]>::SORT_INCREASING_EVALS); Scalar const(*)[NF]>::SORT_INCREASING_EVALS);
#else #else
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, Scalar *, Scalar **,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const *const *>::SORT_INCREASING_EVALS); Scalar const *const *>::SORT_INCREASING_EVALS);
#endif #endif
for (int i = 1; i < n; i++) for (int i = 1; i < n; i++)
@ -612,42 +519,26 @@ void TestJacobi(int n, //<! matrix size
// test DO_NOT_SORT // test DO_NOT_SORT
#if defined USE_VECTOR_OF_VECTORS #if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, ecalc.Diagonalize(M, evals, evecs,
evals, Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar>> &>::DO_NOT_SORT); const vector<vector<Scalar>> &>::DO_NOT_SORT);
#elif defined USE_ARRAY_OF_ARRAYS #elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar, NF>, NF> &>::DO_NOT_SORT); const array<array<Scalar, NF>, NF> &>::DO_NOT_SORT);
#elif defined USE_C_FIXED_SIZE_ARRAYS #elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, Scalar *, Scalar(*)[NF], Scalar const(*)[NF]>::DO_NOT_SORT);
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]>::DO_NOT_SORT);
#else #else
ecalc.Diagonalize(M, ecalc.Diagonalize(
evals, M, evals, evecs,
evecs, Jacobi<Scalar, Scalar *, Scalar **, Scalar const *const *>::DO_NOT_SORT);
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const*const*>::DO_NOT_SORT);
#endif #endif
} // if (test_code_coverage) } // if (test_code_coverage)
// Now (finally) calculate the eigenvalues and eigenvectors // Now (finally) calculate the eigenvalues and eigenvectors
int n_sweeps = ecalc.Diagonalize(M, evals, evecs); int n_sweeps = ecalc.Diagonalize(M, evals, evecs);
@ -673,8 +564,7 @@ void TestJacobi(int n, //<! matrix size
test_evec[a] = 0.0; test_evec[a] = 0.0;
for (int b = 0; b < n; b++) for (int b = 0; b < n; b++)
test_evec[a] += M[a][b] * evecs[i][b]; test_evec[a] += M[a][b] * evecs[i][b];
assert(Similar(test_evec[a], assert(Similar(test_evec[a], evals[i] * evecs[i][a],
evals[i] * evecs[i][a],
eps, // tolerance (absolute difference) eps, // tolerance (absolute difference)
eps * max_eval_size, // tolerance ratio (numerator) eps * max_eval_size, // tolerance ratio (numerator)
evals_known[i] // tolerance ration (denominator) evals_known[i] // tolerance ration (denominator)
@ -697,8 +587,8 @@ void TestJacobi(int n, //<! matrix size
} // TestJacobi() } // TestJacobi()
int main(int argc, char **argv)
int main(int argc, char **argv) { {
int n_size = 2; int n_size = 2;
int n_matr = 1; int n_matr = 1;
double emin = 0.0; double emin = 0.0;
@ -708,8 +598,7 @@ int main(int argc, char **argv) {
unsigned seed = 0; unsigned seed = 0;
if (argc <= 1) { if (argc <= 1) {
cerr << cerr << "Error: This program requires at least 1 argument.\n"
"Error: This program requires at least 1 argument.\n"
"\n" "\n"
"Description: Run Jacobi::Diagonalize() on randomly generated matrices.\n" "Description: Run Jacobi::Diagonalize() on randomly generated matrices.\n"
"\n" "\n"
@ -743,21 +632,14 @@ int main(int argc, char **argv) {
} }
n_size = std::stoi(argv[1]); n_size = std::stoi(argv[1]);
if (argc > 2) if (argc > 2) n_matr = std::stoi(argv[2]);
n_matr = std::stoi(argv[2]); if (argc > 3) emin = std::stof(argv[3]);
if (argc > 3) if (argc > 4) emax = std::stof(argv[4]);
emin = std::stof(argv[3]); if (argc > 5) n_degeneracy = std::stoi(argv[5]);
if (argc > 4) if (argc > 6) n_tests = std::stoi(argv[6]);
emax = std::stof(argv[4]); if (argc > 7) seed = std::stoi(argv[7]);
if (argc > 5)
n_degeneracy = std::stoi(argv[5]);
if (argc > 6)
n_tests = std::stoi(argv[6]);
if (argc > 7)
seed = std::stoi(argv[7]);
double eps = 1.0e-06; double eps = 1.0e-06;
if (argc > 8) if (argc > 8) eps = std::stof(argv[8]);
eps = std::stof(argv[8]);
TestJacobi(n_size, n_matr, emin, emax, n_tests, n_degeneracy, seed, eps); TestJacobi(n_size, n_matr, emin, emax, n_tests, n_degeneracy, seed, eps);

View File

@ -19,7 +19,8 @@
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
TEST(MyPage, int) { TEST(MyPage, int)
{
MyPage<int> p; MyPage<int> p;
// default init. maxchunk=1, pagesize=1024 // default init. maxchunk=1, pagesize=1024
@ -107,7 +108,8 @@ TEST(MyPage, int) {
ASSERT_EQ(p.nchunk, 10); ASSERT_EQ(p.nchunk, 10);
} }
TEST(MyPage, double) { TEST(MyPage, double)
{
MyPage<double> p; MyPage<double> p;
// default init. maxchunk=1, pagesize=1024 // default init. maxchunk=1, pagesize=1024
@ -195,7 +197,8 @@ TEST(MyPage, double) {
ASSERT_EQ(p.nchunk, 10); ASSERT_EQ(p.nchunk, 10);
} }
TEST(MyPage, bigint) { TEST(MyPage, bigint)
{
MyPage<bigint> p; MyPage<bigint> p;
// default init. maxchunk=1, pagesize=1024 // default init. maxchunk=1, pagesize=1024
@ -283,7 +286,8 @@ TEST(MyPage, bigint) {
ASSERT_EQ(p.nchunk, 10); ASSERT_EQ(p.nchunk, 10);
} }
TEST(MyPoolChunk, int) { TEST(MyPoolChunk, int)
{
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1 // defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
MyPoolChunk<int> p; MyPoolChunk<int> p;
@ -315,7 +319,8 @@ TEST(MyPoolChunk, int) {
ASSERT_EQ(p.nchunk, 1); ASSERT_EQ(p.nchunk, 1);
} }
TEST(MyPoolChunk, double) { TEST(MyPoolChunk, double)
{
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1 // defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
MyPoolChunk<double> p; MyPoolChunk<double> p;
@ -344,4 +349,3 @@ TEST(MyPoolChunk, double) {
ASSERT_EQ(p.ndatum, 1); ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1); ASSERT_EQ(p.nchunk, 1);
} }

View File

@ -158,13 +158,15 @@ TEST(ValueTokenizer, valid_double_with_exponential)
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22); ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
} }
TEST(ValueTokenizer, contains) { TEST(ValueTokenizer, contains)
{
ValueTokenizer values("test word"); ValueTokenizer values("test word");
ASSERT_TRUE(values.contains("test")); ASSERT_TRUE(values.contains("test"));
ASSERT_TRUE(values.contains("word")); ASSERT_TRUE(values.contains("word"));
} }
TEST(ValueTokenizer, not_contains) { TEST(ValueTokenizer, not_contains)
{
ValueTokenizer values("test word"); ValueTokenizer values("test word");
ASSERT_FALSE(values.contains("test2")); ASSERT_FALSE(values.contains("test2"));
} }

View File

@ -628,7 +628,6 @@ TEST(Utils, timespec2seconds_hhmmss)
ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0); ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0);
} }
TEST(Utils, date2num) TEST(Utils, date2num)
{ {
ASSERT_EQ(utils::date2num("1Jan05"), 20050101); ASSERT_EQ(utils::date2num("1Jan05"), 20050101);