set units for potential file reader tests. allow verbose execution.

This commit is contained in:
Axel Kohlmeyer
2020-06-16 06:19:31 -04:00
parent 7a00ec90e5
commit b5a809413e

View File

@ -23,16 +23,21 @@
#include "MANYBODY/pair_tersoff_mod_c.h" #include "MANYBODY/pair_tersoff_mod_c.h"
#include "MANYBODY/pair_tersoff_zbl.h" #include "MANYBODY/pair_tersoff_zbl.h"
#include "MANYBODY/pair_vashishta.h" #include "MANYBODY/pair_vashishta.h"
#include "input.h"
#include "lammps.h" #include "lammps.h"
#include "potential_file_reader.h" #include "potential_file_reader.h"
#include "utils.h" #include "utils.h"
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include <cstring>
#include <mpi.h> #include <mpi.h>
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
const int LAMMPS_NS::PairSW::NPARAMS_PER_LINE; const int LAMMPS_NS::PairSW::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairComb::NPARAMS_PER_LINE; const int LAMMPS_NS::PairComb::NPARAMS_PER_LINE;
const int LAMMPS_NS::PairComb3::NPARAMS_PER_LINE; const int LAMMPS_NS::PairComb3::NPARAMS_PER_LINE;
@ -55,24 +60,25 @@ protected:
"PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"}; "PotentialFileReaderTest", "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args; char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *); int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD); lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
void TearDown() override void TearDown() override
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
delete lmp; delete lmp;
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
} }
}; };
TEST_F(PotentialFileReaderTest, Si) TEST_F(PotentialFileReaderTest, Si)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber"); PotentialFileReader reader(lmp, "Si.sw", "Stillinger-Weber");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairSW::NPARAMS_PER_LINE); auto line = reader.next_line(PairSW::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairSW::NPARAMS_PER_LINE);
@ -80,9 +86,10 @@ TEST_F(PotentialFileReaderTest, Si)
TEST_F(PotentialFileReaderTest, Comb) TEST_F(PotentialFileReaderTest, Comb)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "ffield.comb", "COMB"); PotentialFileReader reader(lmp, "ffield.comb", "COMB");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairComb::NPARAMS_PER_LINE); auto line = reader.next_line(PairComb::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb::NPARAMS_PER_LINE);
@ -90,9 +97,10 @@ TEST_F(PotentialFileReaderTest, Comb)
TEST_F(PotentialFileReaderTest, Comb3) TEST_F(PotentialFileReaderTest, Comb3)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "ffield.comb3", "COMB3"); PotentialFileReader reader(lmp, "ffield.comb3", "COMB3");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairComb3::NPARAMS_PER_LINE); auto line = reader.next_line(PairComb3::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairComb3::NPARAMS_PER_LINE);
@ -100,9 +108,10 @@ TEST_F(PotentialFileReaderTest, Comb3)
TEST_F(PotentialFileReaderTest, Tersoff) TEST_F(PotentialFileReaderTest, Tersoff)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff"); PotentialFileReader reader(lmp, "Si.tersoff", "Tersoff");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairTersoff::NPARAMS_PER_LINE); auto line = reader.next_line(PairTersoff::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoff::NPARAMS_PER_LINE);
@ -110,9 +119,10 @@ TEST_F(PotentialFileReaderTest, Tersoff)
TEST_F(PotentialFileReaderTest, TersoffMod) TEST_F(PotentialFileReaderTest, TersoffMod)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod"); PotentialFileReader reader(lmp, "Si.tersoff.mod", "Tersoff/Mod");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairTersoffMOD::NPARAMS_PER_LINE); auto line = reader.next_line(PairTersoffMOD::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMOD::NPARAMS_PER_LINE);
@ -120,9 +130,10 @@ TEST_F(PotentialFileReaderTest, TersoffMod)
TEST_F(PotentialFileReaderTest, TersoffModC) TEST_F(PotentialFileReaderTest, TersoffModC)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC"); PotentialFileReader reader(lmp, "Si.tersoff.modc", "Tersoff/ModC");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairTersoffMODC::NPARAMS_PER_LINE); auto line = reader.next_line(PairTersoffMODC::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffMODC::NPARAMS_PER_LINE);
@ -130,9 +141,10 @@ TEST_F(PotentialFileReaderTest, TersoffModC)
TEST_F(PotentialFileReaderTest, TersoffZBL) TEST_F(PotentialFileReaderTest, TersoffZBL)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL"); PotentialFileReader reader(lmp, "SiC.tersoff.zbl", "Tersoff/ZBL");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairTersoffZBL::NPARAMS_PER_LINE); auto line = reader.next_line(PairTersoffZBL::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairTersoffZBL::NPARAMS_PER_LINE);
@ -140,9 +152,10 @@ TEST_F(PotentialFileReaderTest, TersoffZBL)
TEST_F(PotentialFileReaderTest, GW) TEST_F(PotentialFileReaderTest, GW)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "SiC.gw", "GW"); PotentialFileReader reader(lmp, "SiC.gw", "GW");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairGW::NPARAMS_PER_LINE); auto line = reader.next_line(PairGW::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGW::NPARAMS_PER_LINE);
@ -150,9 +163,10 @@ TEST_F(PotentialFileReaderTest, GW)
TEST_F(PotentialFileReaderTest, GWZBL) TEST_F(PotentialFileReaderTest, GWZBL)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL"); PotentialFileReader reader(lmp, "SiC.gw.zbl", "GW/ZBL");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairGWZBL::NPARAMS_PER_LINE); auto line = reader.next_line(PairGWZBL::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairGWZBL::NPARAMS_PER_LINE);
@ -160,9 +174,10 @@ TEST_F(PotentialFileReaderTest, GWZBL)
TEST_F(PotentialFileReaderTest, Nb3bHarmonic) TEST_F(PotentialFileReaderTest, Nb3bHarmonic)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic"); PotentialFileReader reader(lmp, "MOH.nb3b.harmonic", "NB3B Harmonic");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairNb3bHarmonic::NPARAMS_PER_LINE); auto line = reader.next_line(PairNb3bHarmonic::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairNb3bHarmonic::NPARAMS_PER_LINE);
@ -170,9 +185,10 @@ TEST_F(PotentialFileReaderTest, Nb3bHarmonic)
TEST_F(PotentialFileReaderTest, Vashishta) TEST_F(PotentialFileReaderTest, Vashishta)
{ {
::testing::internal::CaptureStdout(); if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("units metal");
PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta"); PotentialFileReader reader(lmp, "SiC.vashishta", "Vashishta");
::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
auto line = reader.next_line(PairVashishta::NPARAMS_PER_LINE); auto line = reader.next_line(PairVashishta::NPARAMS_PER_LINE);
ASSERT_EQ(utils::count_words(line), PairVashishta::NPARAMS_PER_LINE); ASSERT_EQ(utils::count_words(line), PairVashishta::NPARAMS_PER_LINE);
@ -182,5 +198,6 @@ int main(int argc, char **argv)
{ {
MPI_Init(&argc, &argv); MPI_Init(&argc, &argv);
::testing::InitGoogleMock(&argc, argv); ::testing::InitGoogleMock(&argc, argv);
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }