Refactor dump atom tests

This commit is contained in:
Richard Berger
2020-08-14 15:41:24 -04:00
parent 1b60f876e0
commit 365d8f57f1

View File

@ -11,166 +11,285 @@
See the README file in the top-level LAMMPS directory. See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
#include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h" #include "fmt/format.h"
#include "utils.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 <string>
using ::testing::Eq;
char * BINARY2TXT_BINARY = nullptr; char * BINARY2TXT_BINARY = nullptr;
class DumpAtomTest : public MeltTest { class DumpAtomTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
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) {
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file));
if (!dump_modify_options.empty()) {
command(fmt::format("dump_modify id0 {}", dump_modify_options));
command(fmt::format("dump_modify id1 {}", dump_modify_options));
}
command(fmt::format("run {}", ntimesteps));
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_binary_to_text(std::string binary_file) {
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return fmt::format("{}.txt", binary_file);
}
}; };
TEST_F(DumpAtomTest, run0) TEST_F(DumpAtomTest, run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run0.melt";
command("dump id all atom 1 dump_run0.melt"); generate_dump(dump_file, "scale yes image no", 0);
command("dump_modify id scale yes image no");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines("dump_run0.melt"); auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41); ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS pp pp pp"); ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 2); ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type xs ys zs"); ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type xs ys zs"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 5); ASSERT_EQ(utils::split_words(lines[9]).size(), 5);
delete_file("dump_run0.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, no_scale_run0) TEST_F(DumpAtomTest, no_scale_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_no_scale_run0.melt";
command("dump id all atom 1 dump_no_scale_run0.melt"); generate_dump(dump_file, "scale no", 0);
command("dump_modify id scale no");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_no_scale_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines("dump_no_scale_run0.melt"); auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41); ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS pp pp pp"); ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 2); ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type x y z"); ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type x y z"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 5); ASSERT_EQ(utils::split_words(lines[9]).size(), 5);
delete_file("dump_no_scale_run0.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, no_buffer_no_scale_run0) TEST_F(DumpAtomTest, no_buffer_no_scale_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_no_buffer_no_scale_run0.melt";
command("dump id all atom 1 dump_no_buffer_no_scale_run0.melt"); generate_dump(dump_file, "scale no", 0);
command("dump_modify id buffer no scale no");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_no_buffer_no_scale_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines("dump_no_buffer_no_scale_run0.melt"); auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41); ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS pp pp pp"); ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 2); ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type x y z"); ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type x y z"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 5); ASSERT_EQ(utils::split_words(lines[9]).size(), 5);
delete_file("dump_no_buffer_no_scale_run0.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, no_buffer_with_scale_run0) TEST_F(DumpAtomTest, no_buffer_with_scale_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_no_buffer_with_scale_run0.melt";
command("dump id all atom 1 dump_no_buffer_with_scale_run0.melt"); generate_dump(dump_file, "buffer no scale yes", 0);
command("dump_modify id buffer no scale yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_no_buffer_with_scale_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines("dump_no_buffer_with_scale_run0.melt"); auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41); ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS pp pp pp"); ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 2); ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type xs ys zs"); ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type xs ys zs"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 5); ASSERT_EQ(utils::split_words(lines[9]).size(), 5);
delete_file("dump_no_buffer_with_scale_run0.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, with_image_run0) TEST_F(DumpAtomTest, with_image_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_with_image_run0.melt";
command("dump id all atom 1 dump_with_image_run0.melt"); generate_dump(dump_file, "scale no image yes", 0);
command("dump_modify id scale no image yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_with_image_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
auto lines = read_lines("dump_with_image_run0.melt");
ASSERT_EQ(lines.size(), 41); ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type x y z ix iy iz"); ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type x y z ix iy iz"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 8); ASSERT_EQ(utils::split_words(lines[9]).size(), 8);
delete_file(dump_file);
delete_file("dump_with_image_run0.melt");
} }
TEST_F(DumpAtomTest, with_units_run0) TEST_F(DumpAtomTest, with_units_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_with_units_run0.melt";
command("dump id all atom 1 dump_with_units_run0.melt"); generate_dump(dump_file, "scale no units yes", 0);
command("dump_modify id scale no units yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_with_units_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
auto lines = read_lines("dump_with_units_run0.melt");
ASSERT_EQ(lines.size(), 43); ASSERT_EQ(lines.size(), 43);
ASSERT_STREQ(lines[0].c_str(), "ITEM: UNITS"); ASSERT_THAT(lines[0], Eq("ITEM: UNITS"));
ASSERT_STREQ(lines[1].c_str(), "lj"); ASSERT_THAT(lines[1], Eq("lj"));
ASSERT_STREQ(lines[10].c_str(), "ITEM: ATOMS id type x y z"); ASSERT_THAT(lines[10], Eq("ITEM: ATOMS id type x y z"));
ASSERT_EQ(utils::split_words(lines[11]).size(), 5); ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
delete_file(dump_file);
delete_file("dump_with_units_run0.melt");
} }
TEST_F(DumpAtomTest, with_time_run0) TEST_F(DumpAtomTest, with_time_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_with_time_run0.melt";
command("dump id all atom 1 dump_with_time_run0.melt"); generate_dump(dump_file, "scale no time yes", 0);
command("dump_modify id scale no time yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_with_time_run0.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
auto lines = read_lines("dump_with_time_run0.melt");
ASSERT_EQ(lines.size(), 43); ASSERT_EQ(lines.size(), 43);
ASSERT_STREQ(lines[0].c_str(), "ITEM: TIME"); ASSERT_THAT(lines[0], Eq("ITEM: TIME"));
ASSERT_STREQ(lines[10].c_str(), "ITEM: ATOMS id type x y z"); ASSERT_THAT(lines[10], Eq("ITEM: ATOMS id type x y z"));
ASSERT_EQ(utils::split_words(lines[11]).size(), 5); ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
delete_file(dump_file);
delete_file("dump_with_time_run0.melt");
} }
TEST_F(DumpAtomTest, with_units_run1) TEST_F(DumpAtomTest, with_units_run1)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_with_units_run1.melt";
command("dump id all atom 1 dump_with_units_run1.melt"); generate_dump(dump_file, "scale no units yes", 1);
command("dump_modify id scale no units yes");
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_with_units_run1.melt"); ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
auto lines = read_lines("dump_with_units_run1.melt");
ASSERT_EQ(lines.size(), 84); ASSERT_EQ(lines.size(), 84);
ASSERT_STREQ(lines[0].c_str(), "ITEM: UNITS"); ASSERT_THAT(lines[0], Eq("ITEM: UNITS"));
ASSERT_STREQ(lines[1].c_str(), "lj"); ASSERT_THAT(lines[1], Eq("lj"));
ASSERT_STREQ(lines[10].c_str(), "ITEM: ATOMS id type x y z"); ASSERT_THAT(lines[10], Eq("ITEM: ATOMS id type x y z"));
ASSERT_EQ(utils::split_words(lines[11]).size(), 5); ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
delete_file(dump_file);
}
delete_file("dump_with_units_run1.melt"); TEST_F(DumpAtomTest, no_buffer_with_scale_and_image_run0)
{
auto dump_file = "dump_no_buffer_with_scale_and_image_run0.melt";
generate_dump(dump_file, "buffer no scale yes image yes", 0);
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41);
ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type xs ys zs ix iy iz"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 8);
delete_file(dump_file);
}
TEST_F(DumpAtomTest, triclinic_run0)
{
auto dump_file = "dump_triclinic_run0.melt";
enable_triclinic();
generate_dump(dump_file, "", 0);
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41);
ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS xy xz yz pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 3);
ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type xs ys zs"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 5);
delete_file(dump_file);
}
TEST_F(DumpAtomTest, triclinic_with_units_run0)
{
auto dump_file = "dump_triclinic_with_units_run0.melt";
enable_triclinic();
generate_dump(dump_file, "units yes", 0);
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 43);
ASSERT_THAT(lines[0], Eq("ITEM: UNITS"));
ASSERT_THAT(lines[1], Eq("lj"));
ASSERT_THAT(lines[6], Eq("ITEM: BOX BOUNDS xy xz yz pp pp pp"));
ASSERT_EQ(utils::split_words(lines[7]).size(), 3);
ASSERT_THAT(lines[10], Eq("ITEM: ATOMS id type xs ys zs"));
ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
delete_file(dump_file);
}
TEST_F(DumpAtomTest, triclinic_with_time_run0)
{
auto dump_file = "dump_triclinic_with_time_run0.melt";
enable_triclinic();
generate_dump(dump_file, "time yes", 0);
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 43);
ASSERT_THAT(lines[0], Eq("ITEM: TIME"));
ASSERT_THAT(lines[6], Eq("ITEM: BOX BOUNDS xy xz yz pp pp pp"));
ASSERT_EQ(utils::split_words(lines[7]).size(), 3);
ASSERT_THAT(lines[10], Eq("ITEM: ATOMS id type xs ys zs"));
ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
delete_file(dump_file);
}
TEST_F(DumpAtomTest, triclinic_with_image_run0)
{
auto dump_file = "dump_triclinic_with_image_run0.melt";
enable_triclinic();
generate_dump(dump_file, "image yes", 0);
ASSERT_FILE_EXISTS(dump_file);
auto lines = read_lines(dump_file);
ASSERT_EQ(lines.size(), 41);
ASSERT_THAT(lines[4], Eq("ITEM: BOX BOUNDS xy xz yz pp pp pp"));
ASSERT_EQ(utils::split_words(lines[5]).size(), 3);
ASSERT_THAT(lines[8], Eq("ITEM: ATOMS id type xs ys zs ix iy iz"));
ASSERT_EQ(utils::split_words(lines[9]).size(), 8);
delete_file(dump_file);
}
//-------------------------------------------------------------------------------------------------
// binary formats
//-------------------------------------------------------------------------------------------------
TEST_F(DumpAtomTest, binary_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_run0.melt";
auto binary_file = "dump_binary_run0.melt.bin";
generate_text_and_binary_dump(text_file, binary_file, "", 0);
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(binary_file);
auto converted_file = convert_binary_to_text(binary_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(binary_file);
delete_file(converted_file);
} }
TEST_F(DumpAtomTest, binary_with_units_run0) TEST_F(DumpAtomTest, binary_with_units_run0)
@ -179,23 +298,56 @@ TEST_F(DumpAtomTest, binary_with_units_run0)
auto text_file = "dump_text_with_units_run0.melt"; auto text_file = "dump_text_with_units_run0.melt";
auto binary_file = "dump_binary_with_units_run0.melt.bin"; auto binary_file = "dump_binary_with_units_run0.melt.bin";
auto converted_file = fmt::format("{}.txt", binary_file);
if (!verbose) ::testing::internal::CaptureStdout(); generate_text_and_binary_dump(text_file, binary_file, "scale no units yes", 0);
command(fmd::format("dump id0 all atom 1 {}", text_file));
command(fmt::format("dump id1 all atom 1 {}", binary_file));
command("dump_modify id0 scale no units yes");
command("dump_modify id1 scale no units yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS(text_file); ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(binary_file); ASSERT_FILE_EXISTS(binary_file);
if (!verbose) ::testing::internal::CaptureStdout(); auto converted_file = convert_binary_to_text(binary_file);
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str()); ASSERT_FILE_EXISTS(converted_file);
if (!verbose) ::testing::internal::GetCapturedStdout(); ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(binary_file);
delete_file(converted_file);
}
TEST_F(DumpAtomTest, binary_with_time_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_with_time_run0.melt";
auto binary_file = "dump_binary_with_time_run0.melt.bin";
generate_text_and_binary_dump(text_file, binary_file, "scale no time yes", 0);
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(binary_file);
auto converted_file = convert_binary_to_text(binary_file);
ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
delete_file(binary_file);
delete_file(converted_file);
}
TEST_F(DumpAtomTest, binary_triclinic_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_tri_run0.melt";
auto binary_file = "dump_binary_tri_run0.melt.bin";
enable_triclinic();
generate_text_and_binary_dump(text_file, binary_file, "", 0);
ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(binary_file);
auto converted_file = convert_binary_to_text(binary_file);
ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file); ASSERT_FILE_EQUAL(text_file, converted_file);
@ -210,24 +362,14 @@ TEST_F(DumpAtomTest, binary_triclinic_with_units_run0)
auto text_file = "dump_text_tri_with_units_run0.melt"; auto text_file = "dump_text_tri_with_units_run0.melt";
auto binary_file = "dump_binary_tri_with_units_run0.melt.bin"; auto binary_file = "dump_binary_tri_with_units_run0.melt.bin";
auto converted_file = fmt::format("{}.txt", binary_file);
if (!verbose) ::testing::internal::CaptureStdout(); enable_triclinic();
command("change_box all triclinic"); generate_text_and_binary_dump(text_file, binary_file, "scale no units yes", 0);
command(fmt::format("dump id0 all atom 1 {}", text_file));
command(fmt::format("dump id1 all atom 1 {}", binary_file));
command("dump_modify id0 scale no units yes");
command("dump_modify id1 scale no units yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS(text_file); ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EXISTS(binary_file); ASSERT_FILE_EXISTS(binary_file);
if (!verbose) ::testing::internal::CaptureStdout(); auto converted_file = convert_binary_to_text(binary_file);
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS(converted_file); ASSERT_FILE_EXISTS(converted_file);
ASSERT_FILE_EQUAL(text_file, converted_file); ASSERT_FILE_EQUAL(text_file, converted_file);
@ -236,282 +378,74 @@ TEST_F(DumpAtomTest, binary_triclinic_with_units_run0)
delete_file(converted_file); delete_file(converted_file);
} }
TEST_F(DumpAtomTest, binary_with_time_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("dump id0 all atom 1 dump_text_with_time_run0.melt");
command("dump id1 all atom 1 dump_binary_with_time_run0.melt.bin");
command("dump_modify id0 scale no time yes");
command("dump_modify id1 scale no time yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_text_with_time_run0.melt");
ASSERT_FILE_EXISTS("dump_binary_with_time_run0.melt.bin");
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} dump_binary_with_time_run0.melt.bin", BINARY2TXT_BINARY);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_binary_with_time_run0.melt.bin.txt");
ASSERT_FILE_EQUAL("dump_text_with_time_run0.melt", "dump_binary_with_time_run0.melt.bin.txt");
delete_file("dump_text_with_time_run0.melt");
delete_file("dump_binary_with_time_run0.melt.bin");
delete_file("dump_binary_with_time_run0.melt.bin.txt");
}
TEST_F(DumpAtomTest, binary_triclinic_with_time_run0) TEST_F(DumpAtomTest, binary_triclinic_with_time_run0)
{ {
if(!BINARY2TXT_BINARY) GTEST_SKIP(); if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout(); auto text_file = "dump_text_tri_with_time_run0.melt";
command("change_box all triclinic"); auto binary_file = "dump_binary_tri_with_time_run0.melt.bin";
command("dump id0 all atom 1 dump_text_tri_with_time_run0.melt");
command("dump id1 all atom 1 dump_binary_tri_with_time_run0.melt.bin");
command("dump_modify id0 scale no time yes");
command("dump_modify id1 scale no time yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_text_tri_with_time_run0.melt"); enable_triclinic();
ASSERT_FILE_EXISTS("dump_binary_tri_with_time_run0.melt.bin"); generate_text_and_binary_dump(text_file, binary_file, "scale no time yes", 0);
if (!verbose) ::testing::internal::CaptureStdout(); ASSERT_FILE_EXISTS(text_file);
std::string cmdline = fmt::format("{} dump_binary_tri_with_time_run0.melt.bin", BINARY2TXT_BINARY); ASSERT_FILE_EXISTS(binary_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_binary_tri_with_time_run0.melt.bin.txt"); auto converted_file = convert_binary_to_text(binary_file);
ASSERT_FILE_EQUAL("dump_text_tri_with_time_run0.melt", "dump_binary_tri_with_time_run0.melt.bin.txt");
delete_file("dump_text_tri_with_time_run0.melt");
delete_file("dump_binary_tri_with_time_run0.melt.bin");
delete_file("dump_binary_tri_with_time_run0.melt.bin.txt");
}
TEST_F(DumpAtomTest, no_buffer_with_scale_and_image_run0) ASSERT_FILE_EXISTS(converted_file);
{ ASSERT_FILE_EQUAL(text_file, converted_file);
if (!verbose) ::testing::internal::CaptureStdout(); delete_file(text_file);
command("dump id all atom 1 dump_no_buffer_with_scale_and_image_run0.melt"); delete_file(binary_file);
command("dump_modify id buffer no scale yes image yes"); delete_file(converted_file);
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_no_buffer_with_scale_and_image_run0.melt");
auto lines = read_lines("dump_no_buffer_with_scale_and_image_run0.melt");
ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS pp pp pp");
ASSERT_EQ(utils::split_words(lines[5]).size(), 2);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type xs ys zs ix iy iz");
ASSERT_EQ(utils::split_words(lines[9]).size(), 8);
delete_file("dump_no_buffer_with_scale_and_image_run0.melt");
}
TEST_F(DumpAtomTest, triclinic_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
command("dump id all atom 1 dump_triclinic_run0.melt");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_triclinic_run0.melt");
auto lines = read_lines("dump_triclinic_run0.melt");
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS xy xz yz pp pp pp");
ASSERT_EQ(utils::split_words(lines[5]).size(), 3);
ASSERT_EQ(lines.size(), 41);
delete_file("dump_triclinic_run0.melt");
}
TEST_F(DumpAtomTest, triclinic_with_units_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
command("dump id all atom 1 dump_triclinic_with_units_run0.melt");
command("dump_modify id units yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_triclinic_with_units_run0.melt");
auto lines = read_lines("dump_triclinic_with_units_run0.melt");
ASSERT_STREQ(lines[0].c_str(), "ITEM: UNITS");
ASSERT_STREQ(lines[1].c_str(), "lj");
ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS xy xz yz pp pp pp");
ASSERT_EQ(utils::split_words(lines[7]).size(), 3);
ASSERT_EQ(lines.size(), 43);
delete_file("dump_triclinic_with_units_run0.melt");
}
TEST_F(DumpAtomTest, triclinic_with_time_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
command("dump id all atom 1 dump_triclinic_with_time_run0.melt");
command("dump_modify id time yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_triclinic_with_time_run0.melt");
auto lines = read_lines("dump_triclinic_with_time_run0.melt");
ASSERT_STREQ(lines[0].c_str(), "ITEM: TIME");
ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS xy xz yz pp pp pp");
ASSERT_EQ(utils::split_words(lines[7]).size(), 3);
ASSERT_EQ(lines.size(), 43);
delete_file("dump_triclinic_with_time_run0.melt");
}
TEST_F(DumpAtomTest, triclinic_with_image_run0)
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
command("dump id all atom 1 dump_triclinic_with_image_run0.melt");
command("dump_modify id image yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_triclinic_with_image_run0.melt");
auto lines = read_lines("dump_triclinic_with_image_run0.melt");
ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS xy xz yz pp pp pp");
ASSERT_EQ(utils::split_words(lines[5]).size(), 3);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type xs ys zs ix iy iz");
ASSERT_EQ(utils::split_words(lines[9]).size(), 8);
delete_file("dump_triclinic_with_image_run0.melt");
}
TEST_F(DumpAtomTest, binary_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("dump id0 all atom 1 dump_text_run0.melt");
command("dump id1 all atom 1 dump_binary_run0.melt.bin");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_text_run0.melt");
ASSERT_FILE_EXISTS("dump_binary_run0.melt.bin");
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} dump_binary_run0.melt.bin", BINARY2TXT_BINARY);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_binary_run0.melt.bin.txt");
ASSERT_FILE_EQUAL("dump_text_run0.melt", "dump_binary_run0.melt.bin.txt");
delete_file("dump_text_run0.melt");
delete_file("dump_binary_run0.melt.bin");
delete_file("dump_binary_run0.melt.bin.txt");
}
TEST_F(DumpAtomTest, binary_triclinic_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
command("dump id0 all atom 1 dump_text_tri_run0.melt");
command("dump id1 all atom 1 dump_binary_tri_run0.melt.bin");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_text_tri_run0.melt");
ASSERT_FILE_EXISTS("dump_binary_tri_run0.melt.bin");
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} dump_binary_tri_run0.melt.bin", BINARY2TXT_BINARY);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_binary_tri_run0.melt.bin.txt");
ASSERT_FILE_EQUAL("dump_text_tri_run0.melt", "dump_binary_tri_run0.melt.bin.txt");
delete_file("dump_text_tri_run0.melt");
delete_file("dump_binary_tri_run0.melt.bin");
delete_file("dump_binary_tri_run0.melt.bin.txt");
} }
TEST_F(DumpAtomTest, binary_triclinic_with_image_run0) TEST_F(DumpAtomTest, binary_triclinic_with_image_run0)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); if(!BINARY2TXT_BINARY) GTEST_SKIP();
command("change_box all triclinic");
command("dump id0 all atom 1 dump_text_tri_with_image_run0.melt");
command("dump id1 all atom 1 dump_binary_tri_with_image_run0.melt.bin");
command("dump_modify id0 image yes");
command("dump_modify id1 image yes");
command("run 0");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_text_tri_with_image_run0.melt"); auto text_file = "dump_text_tri_with_image_run0.melt";
ASSERT_FILE_EXISTS("dump_binary_tri_with_image_run0.melt.bin"); auto binary_file = "dump_binary_tri_with_image_run0.melt.bin";
if (!verbose) ::testing::internal::CaptureStdout(); enable_triclinic();
std::string cmdline = fmt::format("{} dump_binary_tri_with_image_run0.melt.bin", BINARY2TXT_BINARY); generate_text_and_binary_dump(text_file, binary_file, "image yes", 0);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_binary_tri_with_image_run0.melt.bin.txt"); ASSERT_FILE_EXISTS(text_file);
ASSERT_FILE_EQUAL("dump_text_tri_with_image_run0.melt", ASSERT_FILE_EXISTS(binary_file);
"dump_binary_tri_with_image_run0.melt.bin.txt");
auto lines = read_lines("dump_binary_tri_with_image_run0.melt.bin.txt"); auto converted_file = convert_binary_to_text(binary_file);
ASSERT_EQ(lines.size(), 41);
ASSERT_STREQ(lines[4].c_str(), "ITEM: BOX BOUNDS xy xz yz pp pp pp"); ASSERT_FILE_EXISTS(converted_file);
ASSERT_EQ(utils::split_words(lines[5]).size(), 3); ASSERT_FILE_EQUAL(text_file, converted_file);
delete_file(text_file);
ASSERT_STREQ(lines[8].c_str(), "ITEM: ATOMS id type xs ys zs ix iy iz"); delete_file(binary_file);
ASSERT_EQ(utils::split_words(lines[9]).size(), 8); delete_file(converted_file);
delete_file("dump_text_tri_with_image_run0.melt");
delete_file("dump_binary_tri_with_image_run0.melt.bin");
delete_file("dump_binary_tri_with_image_run0.melt.bin.txt");
} }
TEST_F(DumpAtomTest, run1) TEST_F(DumpAtomTest, run1)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run1.melt";
command("dump id all atom 1 dump_run1.melt"); generate_dump(dump_file, "", 1);
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run1.melt"); ASSERT_FILE_EXISTS(dump_file);
ASSERT_EQ(count_lines("dump_run1.melt"), 82); ASSERT_EQ(count_lines(dump_file), 82);
delete_file("dump_run1.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, run2) TEST_F(DumpAtomTest, run2)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run2.melt";
command("dump id all atom 1 dump_run2.melt"); generate_dump(dump_file, "", 2);
command("run 2");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run2.melt"); ASSERT_FILE_EXISTS(dump_file);
ASSERT_EQ(count_lines("dump_run2.melt"), 123); ASSERT_EQ(count_lines(dump_file), 123);
delete_file("dump_run2.melt"); delete_file(dump_file);
} }
TEST_F(DumpAtomTest, multi_file_run1) TEST_F(DumpAtomTest, multi_file_run1)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run1_*.melt";
command("dump id all atom 1 dump_run1_*.melt"); generate_dump(dump_file, "", 1);
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run1_0.melt"); ASSERT_FILE_EXISTS("dump_run1_0.melt");
ASSERT_FILE_EXISTS("dump_run1_1.melt"); ASSERT_FILE_EXISTS("dump_run1_1.melt");
@ -523,10 +457,8 @@ TEST_F(DumpAtomTest, multi_file_run1)
TEST_F(DumpAtomTest, per_processor_file_run1) TEST_F(DumpAtomTest, per_processor_file_run1)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run1_p%.melt";
command("dump id all atom 1 dump_run1_p%.melt"); generate_dump(dump_file, "", 1);
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run1_p0.melt"); ASSERT_FILE_EXISTS("dump_run1_p0.melt");
ASSERT_EQ(count_lines("dump_run1_p0.melt"), 82); ASSERT_EQ(count_lines("dump_run1_p0.melt"), 82);
@ -535,10 +467,8 @@ TEST_F(DumpAtomTest, per_processor_file_run1)
TEST_F(DumpAtomTest, per_processor_multi_file_run1) TEST_F(DumpAtomTest, per_processor_multi_file_run1)
{ {
if (!verbose) ::testing::internal::CaptureStdout(); auto dump_file = "dump_run1_p%_*.melt";
command("dump id all atom 1 dump_run1_p%_*.melt"); generate_dump(dump_file, "", 1);
command("run 1");
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS("dump_run1_p0_0.melt"); ASSERT_FILE_EXISTS("dump_run1_p0_0.melt");
ASSERT_FILE_EXISTS("dump_run1_p0_1.melt"); ASSERT_FILE_EXISTS("dump_run1_p0_1.melt");
@ -580,16 +510,16 @@ TEST_F(DumpAtomTest, dump_modify_invalid)
TEST_F(DumpAtomTest, write_dump) TEST_F(DumpAtomTest, write_dump)
{ {
auto reference = "dump_run0.melt";
auto dump_file = "write_dump_atom_run0.melt";
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("dump id all atom 1 dump_run0.melt"); command(fmt::format("dump id all atom 1 {}", reference));
command("dump_modify id scale no units yes"); command("dump_modify id scale no units yes");
command("run 0"); command("run 0");
command("write_dump all atom write_dump_atom_run*.melt modify scale no units yes"); command("write_dump all atom write_dump_atom_run*.melt modify scale no units yes");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto reference = "dump_run0.melt";
auto dump_file = "write_dump_atom_run0.melt";
ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(reference);
ASSERT_FILE_EXISTS(dump_file); ASSERT_FILE_EXISTS(dump_file);
@ -600,27 +530,23 @@ TEST_F(DumpAtomTest, write_dump)
TEST_F(DumpAtomTest, binary_write_dump) TEST_F(DumpAtomTest, binary_write_dump)
{ {
if(!BINARY2TXT_BINARY) GTEST_SKIP();
auto reference = "dump_run0.melt.bin";
auto dump_file = "write_dump_atom_run0_p0.melt.bin";
if (!verbose) ::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
command("dump id all atom 1 dump_run0.melt.bin"); command(fmt::format("dump id all atom 1 {}", reference));
command("dump_modify id scale no units yes"); command("dump_modify id scale no units yes");
command("run 0"); command("run 0");
command("write_dump all atom write_dump_atom_run*_p%.melt.bin modify scale no units yes"); command("write_dump all atom write_dump_atom_run*_p%.melt.bin modify scale no units yes");
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto reference = "dump_run0.melt.bin";
auto dump_file = "write_dump_atom_run0_p0.melt.bin";
auto reference_txt = "dump_run0.melt.bin.txt";
auto dump_file_txt = "write_dump_atom_run0_p0.melt.bin.txt";
ASSERT_FILE_EXISTS(reference); ASSERT_FILE_EXISTS(reference);
ASSERT_FILE_EXISTS(dump_file); ASSERT_FILE_EXISTS(dump_file);
if (!verbose) ::testing::internal::CaptureStdout(); auto reference_txt = convert_binary_to_text(reference);
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, reference); auto dump_file_txt = convert_binary_to_text(dump_file);
system(cmdline.c_str());
cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, dump_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
ASSERT_FILE_EXISTS(reference_txt); ASSERT_FILE_EXISTS(reference_txt);
ASSERT_FILE_EXISTS(dump_file_txt); ASSERT_FILE_EXISTS(dump_file_txt);