add tests for utils::open_potential()

This commit is contained in:
Axel Kohlmeyer 2021-04-04 22:23:13 -04:00
parent a858c07e8a
commit e00e2676fc
No known key found for this signature in database
GPG Key ID: D9B44E93BF0C375A
1 changed files with 62 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "potential_file_reader.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "../testing/core.h"
#include <cstring>
@ -257,6 +258,67 @@ TEST_F(PotentialFileReaderTest, UnitConvert)
delete reader;
}
class OpenPotentialTest : public LAMMPSTest {
};
// open for native units
TEST_F(OpenPotentialTest, Sw_native)
{
int convert_flag = utils::get_supported_conversions(utils::ENERGY);
BEGIN_CAPTURE_OUTPUT();
command("units metal");
FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag);
auto text = END_CAPTURE_OUTPUT();
double conv = utils::get_conversion_factor(utils::ENERGY, convert_flag);
ASSERT_NE(fp, nullptr);
ASSERT_DOUBLE_EQ(conv, 1.0);
fclose(fp);
}
// open with supported conversion enabled
TEST_F(OpenPotentialTest, Sw_conv)
{
int convert_flag = utils::get_supported_conversions(utils::ENERGY);
ASSERT_EQ(convert_flag, utils::METAL2REAL | utils::REAL2METAL);
BEGIN_HIDE_OUTPUT();
command("units real");
FILE *fp = utils::open_potential("Si.sw", lmp, &convert_flag);
auto text = END_CAPTURE_OUTPUT();
double conv = utils::get_conversion_factor(utils::ENERGY, convert_flag);
ASSERT_NE(fp, nullptr);
ASSERT_EQ(convert_flag, utils::METAL2REAL);
ASSERT_DOUBLE_EQ(conv, 23.060549);
fclose(fp);
}
// open with conversion disabled
TEST_F(OpenPotentialTest, Sw_noconv)
{
BEGIN_HIDE_OUTPUT();
command("units real");
END_HIDE_OUTPUT();
TEST_FAILURE(".*potential.*requires metal units but real.*",
utils::open_potential("Si.sw", lmp, nullptr););
BEGIN_HIDE_OUTPUT();
command("units lj");
END_HIDE_OUTPUT();
int convert_flag = utils::get_supported_conversions(utils::UNKNOWN);
ASSERT_EQ(convert_flag, utils::NOCONVERT);
}
// open non-existing potential
TEST_F(OpenPotentialTest, No_file)
{
int convert_flag = utils::get_supported_conversions(utils::ENERGY);
BEGIN_HIDE_OUTPUT();
command("units metal");
FILE *fp = utils::open_potential("Unknown.sw", lmp, &convert_flag);
END_HIDE_OUTPUT();
ASSERT_EQ(fp,nullptr);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);