Unverified Commit dbcf66cf authored by Richard Berger's avatar Richard Berger
Browse files

Increase coverage of dump custom

parent eab8652d
Loading
Loading
Loading
Loading
+128 −7
Original line number Original line Diff line number Diff line
@@ -27,9 +27,10 @@ class DumpCustomTest : public MeltTest {
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";


    if (!verbose) ::testing::internal::CaptureStdout();
    if (!verbose) ::testing::internal::CaptureStdout();
    command(fmt::format("dump id all custom 1 {} id type x y vx fx", dump_file));
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes");
    command("dump_modify id units yes");
    command("run 1");
    command("run 1");
    if (!verbose) ::testing::internal::GetCapturedStdout();
    if (!verbose) ::testing::internal::GetCapturedStdout();
@@ -40,7 +41,99 @@ TEST_F(DumpCustomTest, run1)
    ASSERT_EQ(lines.size(), 84);
    ASSERT_EQ(lines.size(), 84);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), "ITEM: ATOMS id type x y vx fx");
    ASSERT_STREQ(lines[10].c_str(), fmt::format("ITEM: ATOMS {}", fields).c_str());
    ASSERT_EQ(utils::split_words(lines[11]).size(), 26);
    delete_file(dump_file);
}

TEST_F(DumpCustomTest, thresh_run0)
{
    auto dump_file = "dump_custom_thresh_run0.melt";
    auto fields = "id type x y z";

    if (!verbose) ::testing::internal::CaptureStdout();
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes thresh x < 1 thresh y < 1 thresh z < 1");
    command("run 0");
    if (!verbose) ::testing::internal::GetCapturedStdout();


    ASSERT_FILE_EXISTS(dump_file);
    auto lines = read_lines(dump_file);
    ASSERT_EQ(lines.size(), 15);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), fmt::format("ITEM: ATOMS {}", fields).c_str());
    ASSERT_EQ(utils::split_words(lines[11]).size(), 5);
    delete_file(dump_file);
}

TEST_F(DumpCustomTest, compute_run0)
{
    auto dump_file = "dump_custom_compute_run0.melt";
    auto fields = "id type x y z c_comp[1] c_comp[2] c_comp[3]";

    if (!verbose) ::testing::internal::CaptureStdout();
    command("compute comp all property/atom x y z");
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes");
    command("run 0");
    if (!verbose) ::testing::internal::GetCapturedStdout();


    ASSERT_FILE_EXISTS(dump_file);
    auto lines = read_lines(dump_file);
    ASSERT_EQ(lines.size(), 43);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), fmt::format("ITEM: ATOMS {}", fields).c_str());
    ASSERT_EQ(utils::split_words(lines[11]).size(), 8);
    delete_file(dump_file);
}

TEST_F(DumpCustomTest, fix_run0)
{
    auto dump_file = "dump_custom_compute_run0.melt";
    auto fields = "id x y z f_numdiff[1] f_numdiff[2] f_numdiff[3]";

    if (!verbose) ::testing::internal::CaptureStdout();
    command("fix numdiff all numdiff 1 0.0001");
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes");
    command("run 0");
    if (!verbose) ::testing::internal::GetCapturedStdout();


    ASSERT_FILE_EXISTS(dump_file);
    auto lines = read_lines(dump_file);
    ASSERT_EQ(lines.size(), 43);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), fmt::format("ITEM: ATOMS {}", fields).c_str());
    ASSERT_EQ(utils::split_words(lines[11]).size(), 7);
    delete_file(dump_file);
}

TEST_F(DumpCustomTest, custom_run0)
{
    auto dump_file = "dump_custom_custom_run0.melt";
    auto fields = "id x y z i_flag1 d_flag2";

    if (!verbose) ::testing::internal::CaptureStdout();
    command("fix prop all property/atom i_flag1 d_flag2");
    command("compute 1 all property/atom i_flag1 d_flag2");
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes");
    command("run 0");
    if (!verbose) ::testing::internal::GetCapturedStdout();


    ASSERT_FILE_EXISTS(dump_file);
    auto lines = read_lines(dump_file);
    ASSERT_EQ(lines.size(), 43);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), fmt::format("ITEM: ATOMS {}", fields).c_str());
    ASSERT_EQ(utils::split_words(lines[11]).size(), 6);
    ASSERT_EQ(utils::split_words(lines[11]).size(), 6);
    delete_file(dump_file);
    delete_file(dump_file);
}
}
@@ -50,12 +143,13 @@ TEST_F(DumpCustomTest, binary_run1)
    auto text_file = "dump_custom_text_run1.melt";
    auto text_file = "dump_custom_text_run1.melt";
    auto binary_file = "dump_custom_binary_run1.melt.bin";
    auto binary_file = "dump_custom_binary_run1.melt.bin";
    auto converted_file = fmt::format("{}.txt", binary_file);
    auto converted_file = fmt::format("{}.txt", binary_file);
    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";


    if(!BINARY2TXT_BINARY) GTEST_SKIP();
    if(!BINARY2TXT_BINARY) GTEST_SKIP();


    if (!verbose) ::testing::internal::CaptureStdout();
    if (!verbose) ::testing::internal::CaptureStdout();
    command(fmt::format("dump id0 all custom 1 {} id type x y vx fx", text_file));
    command(fmt::format("dump id0 all custom 1 {} {}", text_file, fields));
    command(fmt::format("dump id1 all custom 1 {} id type x y vx fx", binary_file));
    command(fmt::format("dump id1 all custom 1 {} {}", binary_file, fields));
    command("dump_modify id0 units yes");
    command("dump_modify id0 units yes");
    command("dump_modify id1 units yes");
    command("dump_modify id1 units yes");
    command("run 1");
    command("run 1");
@@ -79,10 +173,12 @@ TEST_F(DumpCustomTest, binary_run1)
TEST_F(DumpCustomTest, triclinic_run1)
TEST_F(DumpCustomTest, triclinic_run1)
{
{
    auto dump_file = "dump_custom_tri_run1.melt";
    auto dump_file = "dump_custom_tri_run1.melt";
    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";

    if (!verbose) ::testing::internal::CaptureStdout();
    if (!verbose) ::testing::internal::CaptureStdout();


    command("change_box all triclinic");
    command("change_box all triclinic");
    command(fmt::format("dump id all custom 1 {} id type x y vx fx", dump_file));
    command(fmt::format("dump id all custom 1 {} {}", dump_file, fields));
    command("dump_modify id units yes");
    command("dump_modify id units yes");
    command("run 1");
    command("run 1");
    if (!verbose) ::testing::internal::GetCapturedStdout();
    if (!verbose) ::testing::internal::GetCapturedStdout();
@@ -102,12 +198,14 @@ TEST_F(DumpCustomTest, binary_triclinic_run1)
    auto text_file = "dump_custom_tri_text_run1.melt";
    auto text_file = "dump_custom_tri_text_run1.melt";
    auto binary_file = "dump_custom_tri_binary_run1.melt.bin";
    auto binary_file = "dump_custom_tri_binary_run1.melt.bin";
    auto converted_file = fmt::format("{}.txt", binary_file);
    auto converted_file = fmt::format("{}.txt", binary_file);
    auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz";


    if(!BINARY2TXT_BINARY) GTEST_SKIP();
    if(!BINARY2TXT_BINARY) GTEST_SKIP();


    if (!verbose) ::testing::internal::CaptureStdout();
    if (!verbose) ::testing::internal::CaptureStdout();
    command(fmt::format("dump id0 all custom 1 {} id type x y vx fx", text_file));
    command("change_box all triclinic");
    command(fmt::format("dump id1 all custom 1 {} id type x y vx fx", binary_file));
    command(fmt::format("dump id0 all custom 1 {} {}", text_file, fields));
    command(fmt::format("dump id1 all custom 1 {} {}", binary_file, fields));
    command("dump_modify id0 units yes");
    command("dump_modify id0 units yes");
    command("dump_modify id1 units yes");
    command("dump_modify id1 units yes");
    command("run 1");
    command("run 1");
@@ -128,6 +226,29 @@ TEST_F(DumpCustomTest, binary_triclinic_run1)
    delete_file(converted_file);
    delete_file(converted_file);
}
}


TEST_F(DumpCustomTest, with_variable_run1)
{
    auto dump_file = "dump_custom_with_variable_run1.melt";

    if (!verbose) ::testing::internal::CaptureStdout();
    command("compute         1 all property/atom proc");
    command("variable        p atom (c_1%10)+1");
    command(fmt::format("dump id all custom 1 {} id type x y z v_p", dump_file));
    command("dump_modify id units yes");
    command("run 1");
    if (!verbose) ::testing::internal::GetCapturedStdout();


    ASSERT_FILE_EXISTS(dump_file);
    auto lines = read_lines(dump_file);
    ASSERT_EQ(lines.size(), 84);
    ASSERT_STREQ(lines[6].c_str(), "ITEM: BOX BOUNDS pp pp pp");
    ASSERT_EQ(utils::split_words(lines[7]).size(), 2);
    ASSERT_STREQ(lines[10].c_str(), "ITEM: ATOMS id type x y z v_p");
    ASSERT_EQ(utils::split_words(lines[11]).size(), 6);
    delete_file(dump_file);
}



int main(int argc, char **argv)
int main(int argc, char **argv)
{
{
+1 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ 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("lattice         fcc 0.8442");
        command("lattice         fcc 0.8442");
        command("region          box block 0 2 0 2 0 2");
        command("region          box block 0 2 0 2 0 2");