Merge remote-tracking branch 'origin/master' into refactor-reading

This commit is contained in:
Richard Berger
2020-07-17 23:08:26 -04:00
1223 changed files with 865702 additions and 2037147 deletions

View File

@ -5,6 +5,7 @@ add_test(Tokenizer test_tokenizer)
add_executable(test_utils test_utils.cpp)
target_link_libraries(test_utils PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)
add_test(Utils test_utils)
set_tests_properties(Utils PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}")
add_executable(test_fmtlib test_fmtlib.cpp)
target_link_libraries(test_fmtlib PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)

View File

@ -11,96 +11,127 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "lmptype.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include <string>
#include "lmptype.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <exception>
#include <string>
using namespace LAMMPS_NS;
using ::testing::Eq;
// this tests a subset of {fmt} that is most relevant to LAMMPS
TEST(FmtLib, insert_string) {
TEST(FmtLib, insert_string)
{
const char val[] = "word";
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word word"));
}
TEST(FmtLib, insert_int) {
TEST(FmtLib, insert_int)
{
const int val = 333;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 333"));
}
TEST(FmtLib, insert_neg_int) {
TEST(FmtLib, insert_neg_int)
{
const int val = -333;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -333"));
}
TEST(FmtLib, insert_bigint) {
if (sizeof(bigint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_bigint)
{
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
const bigint val = 9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_neg_bigint) {
if (sizeof(bigint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_neg_bigint)
{
#if defined(LAMMPS_BIGBIG) || defined(LAMMPS_SMALLBIG)
const bigint val = -9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_tagint) {
if (sizeof(tagint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_tagint)
{
#if defined(LAMMPS_BIGBIG)
const tagint val = 9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_neg_tagint) {
if (sizeof(tagint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_neg_tagint)
{
#if defined(LAMMPS_BIGBIG)
const tagint val = -9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_imageint) {
if (sizeof(imageint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_imageint)
{
#if defined(LAMMPS_BIGBIG)
const imageint val = 9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_neg_imageint) {
if (sizeof(imageint) == 4) GTEST_SKIP();
TEST(FmtLib, insert_neg_imageint)
{
#if defined(LAMMPS_BIGBIG)
const imageint val = -9945234592L;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -9945234592"));
#else
GTEST_SKIP();
#endif
}
TEST(FmtLib, insert_double) {
TEST(FmtLib, insert_double)
{
const double val = 1.5;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word 1.5"));
}
TEST(FmtLib, insert_neg_double) {
TEST(FmtLib, insert_neg_double)
{
const double val = -1.5;
auto text = fmt::format("word {}",val);
auto text = fmt::format("word {}", val);
ASSERT_THAT(text, Eq("word -1.5"));
}
TEST(FmtLib, int_for_double) {
TEST(FmtLib, int_for_double)
{
const double val = -1.5;
ASSERT_THROW(fmt::format("word {:d}",val),std::exception);
ASSERT_THROW(fmt::format("word {:d}", val), std::exception);
}
TEST(FmtLib, double_for_int) {
TEST(FmtLib, double_for_int)
{
const int val = 15;
ASSERT_THROW(fmt::format("word {:g}",val),std::exception);
ASSERT_THROW(fmt::format("word {:g}", val), std::exception);
}

View File

@ -11,104 +11,117 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "tokenizer.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace LAMMPS_NS;
using ::testing::Eq;
TEST(Tokenizer, empty_string) {
TEST(Tokenizer, empty_string)
{
Tokenizer t("", " ");
ASSERT_EQ(t.count(), 0);
}
TEST(Tokenizer, whitespace_only) {
TEST(Tokenizer, whitespace_only)
{
Tokenizer t(" ", " ");
ASSERT_EQ(t.count(), 0);
}
TEST(Tokenizer, single_word) {
TEST(Tokenizer, single_word)
{
Tokenizer t("test", " ");
ASSERT_EQ(t.count(), 1);
}
TEST(Tokenizer, two_words) {
TEST(Tokenizer, two_words)
{
Tokenizer t("test word", " ");
ASSERT_EQ(t.count(), 2);
}
TEST(Tokenizer, prefix_seperators) {
TEST(Tokenizer, prefix_separators)
{
Tokenizer t(" test word", " ");
ASSERT_EQ(t.count(), 2);
}
TEST(Tokenizer, postfix_seperators) {
TEST(Tokenizer, postfix_separators)
{
Tokenizer t("test word ", " ");
ASSERT_EQ(t.count(), 2);
}
TEST(Tokenizer, iterate_words) {
TEST(Tokenizer, iterate_words)
{
Tokenizer t(" test word ", " ");
ASSERT_THAT(t[0], Eq("test"));
ASSERT_THAT(t[1], Eq("word"));
ASSERT_THAT(t.next(), Eq("test"));
ASSERT_THAT(t.next(), Eq("word"));
ASSERT_EQ(t.count(), 2);
}
TEST(Tokenizer, default_seperators) {
TEST(Tokenizer, default_separators)
{
Tokenizer t(" \r\n test \t word \f");
ASSERT_THAT(t[0], Eq("test"));
ASSERT_THAT(t[1], Eq("word"));
ASSERT_THAT(t.next(), Eq("test"));
ASSERT_THAT(t.next(), Eq("word"));
ASSERT_EQ(t.count(), 2);
}
TEST(Tokenizer, for_loop) {
TEST(Tokenizer, as_vector)
{
Tokenizer t(" \r\n test \t word \f");
std::vector<std::string> list;
for(auto word : t) {
list.push_back(word);
}
std::vector<std::string> list = t.as_vector();
ASSERT_THAT(list[0], Eq("test"));
ASSERT_THAT(list[1], Eq("word"));
}
TEST(ValueTokenizer, empty_string) {
TEST(ValueTokenizer, empty_string)
{
ValueTokenizer values("");
ASSERT_FALSE(values.has_next());
}
TEST(ValueTokenizer, bad_integer) {
TEST(ValueTokenizer, bad_integer)
{
ValueTokenizer values("f10");
ASSERT_THROW(values.next_int(), InvalidIntegerException);
}
TEST(ValueTokenizer, bad_double) {
TEST(ValueTokenizer, bad_double)
{
ValueTokenizer values("1a.0");
ASSERT_THROW(values.next_double(), InvalidFloatException);
}
TEST(ValueTokenizer, valid_int) {
TEST(ValueTokenizer, valid_int)
{
ValueTokenizer values("10");
ASSERT_EQ(values.next_int(), 10);
}
TEST(ValueTokenizer, valid_tagint) {
TEST(ValueTokenizer, valid_tagint)
{
ValueTokenizer values("42");
ASSERT_EQ(values.next_tagint(), 42);
}
TEST(ValueTokenizer, valid_bigint) {
TEST(ValueTokenizer, valid_bigint)
{
ValueTokenizer values("42");
ASSERT_EQ(values.next_bigint(), 42);
}
TEST(ValueTokenizer, valid_double) {
TEST(ValueTokenizer, valid_double)
{
ValueTokenizer values("3.14");
ASSERT_DOUBLE_EQ(values.next_double(), 3.14);
}
TEST(ValueTokenizer, valid_double_with_exponential) {
TEST(ValueTokenizer, valid_double_with_exponential)
{
ValueTokenizer values("3.14e22");
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
}

View File

@ -11,207 +11,423 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
using namespace LAMMPS_NS;
using ::testing::Eq;
using ::testing::EndsWith;
TEST(Utils, trim_comment) {
TEST(Utils, trim_comment)
{
auto trimmed = utils::trim_comment("some text # comment");
ASSERT_THAT(trimmed, Eq("some text "));
}
TEST(Utils, count_words) {
TEST(Utils, count_words)
{
ASSERT_EQ(utils::count_words("some text # comment"), 4);
}
TEST(Utils, trim_and_count_words) {
TEST(Utils, count_words_string)
{
ASSERT_EQ(utils::count_words(std::string("some text # comment")), 4);
}
TEST(Utils, count_words_non_default)
{
ASSERT_EQ(utils::count_words("some text # comment", " #"), 3);
}
TEST(Utils, trim_and_count_words)
{
ASSERT_EQ(utils::trim_and_count_words("some text # comment"), 2);
}
TEST(Utils, valid_integer1) {
TEST(Utils, count_words_with_extra_spaces)
{
ASSERT_EQ(utils::count_words(" some text # comment "), 4);
}
TEST(Utils, split_words_simple)
{
std::vector<std::string> list = utils::split_words("one two three");
ASSERT_EQ(list.size(), 3);
}
TEST(Utils, split_words_quoted)
{
std::vector<std::string> list = utils::split_words("one 'two' \"three\"");
ASSERT_EQ(list.size(), 3);
}
TEST(Utils, split_words_escaped)
{
std::vector<std::string> list = utils::split_words("1\\' '\"two\"' 3\\\"");
ASSERT_EQ(list.size(), 3);
}
TEST(Utils, split_words_quote_in_quoted)
{
std::vector<std::string> list = utils::split_words("one 't\\'wo' \"th\\\"ree\"");
ASSERT_EQ(list.size(), 3);
}
TEST(Utils, valid_integer1)
{
ASSERT_TRUE(utils::is_integer("10"));
}
TEST(Utils, valid_integer2) {
TEST(Utils, valid_integer2)
{
ASSERT_TRUE(utils::is_integer("-10"));
}
TEST(Utils, valid_integer3) {
TEST(Utils, valid_integer3)
{
ASSERT_TRUE(utils::is_integer("+10"));
}
TEST(Utils, valid_double1) {
TEST(Utils, valid_double1)
{
ASSERT_TRUE(utils::is_double("10.0"));
}
TEST(Utils, valid_double2) {
TEST(Utils, valid_double2)
{
ASSERT_TRUE(utils::is_double("1."));
}
TEST(Utils, valid_double3) {
TEST(Utils, valid_double3)
{
ASSERT_TRUE(utils::is_double(".0"));
}
TEST(Utils, valid_double4) {
TEST(Utils, valid_double4)
{
ASSERT_TRUE(utils::is_double("-10.0"));
}
TEST(Utils, valid_double5) {
TEST(Utils, valid_double5)
{
ASSERT_TRUE(utils::is_double("-1."));
}
TEST(Utils, valid_double6) {
TEST(Utils, valid_double6)
{
ASSERT_TRUE(utils::is_double("-.0"));
}
TEST(Utils, valid_double7) {
TEST(Utils, valid_double7)
{
ASSERT_TRUE(utils::is_double("+10.0"));
}
TEST(Utils, valid_double8) {
TEST(Utils, valid_double8)
{
ASSERT_TRUE(utils::is_double("+1."));
}
TEST(Utils, valid_double9) {
TEST(Utils, valid_double9)
{
ASSERT_TRUE(utils::is_double("+.0"));
}
TEST(Utils, empty_not_an_integer) {
TEST(Utils, empty_not_an_integer)
{
ASSERT_FALSE(utils::is_integer(""));
}
TEST(Utils, empty_not_a_double) {
TEST(Utils, empty_not_a_double)
{
ASSERT_FALSE(utils::is_double(""));
}
TEST(Utils, text_not_an_integer) {
TEST(Utils, text_not_an_integer)
{
ASSERT_FALSE(utils::is_integer("one"));
}
TEST(Utils, text_not_a_double) {
TEST(Utils, text_not_a_double)
{
ASSERT_FALSE(utils::is_double("half"));
}
TEST(Utils, double_not_an_integer1) {
TEST(Utils, double_not_an_integer1)
{
ASSERT_FALSE(utils::is_integer("10.0"));
}
TEST(Utils, double_not_an_integer2) {
TEST(Utils, double_not_an_integer2)
{
ASSERT_FALSE(utils::is_integer(".0"));
}
TEST(Utils, double_not_an_integer3) {
TEST(Utils, double_not_an_integer3)
{
ASSERT_FALSE(utils::is_integer("1."));
}
TEST(Utils, integer_is_double1) {
TEST(Utils, integer_is_double1)
{
ASSERT_TRUE(utils::is_double("10"));
}
TEST(Utils, integer_is_double2) {
TEST(Utils, integer_is_double2)
{
ASSERT_TRUE(utils::is_double("-10"));
}
TEST(Utils, is_double_with_exponential) {
TEST(Utils, is_double_with_exponential)
{
ASSERT_TRUE(utils::is_double("+1e02"));
}
TEST(Utils, is_double_with_neg_exponential) {
TEST(Utils, is_double_with_neg_exponential)
{
ASSERT_TRUE(utils::is_double("1.0e-22"));
}
TEST(Utils, is_double_with_pos_exponential) {
TEST(Utils, is_double_with_pos_exponential)
{
ASSERT_TRUE(utils::is_double(".1e+22"));
}
TEST(Utils, signed_double_and_exponential) {
TEST(Utils, signed_double_and_exponential)
{
ASSERT_TRUE(utils::is_double("-10E-22"));
}
TEST(Utils, is_double_with_d_exponential) {
TEST(Utils, is_double_with_d_exponential)
{
ASSERT_FALSE(utils::is_double("10d22"));
}
TEST(Utils, is_double_with_neg_d_exponential) {
TEST(Utils, is_double_with_neg_d_exponential)
{
ASSERT_FALSE(utils::is_double("10d-22"));
}
TEST(Utils, signed_double_and_d_exponential) {
TEST(Utils, signed_double_and_d_exponential)
{
ASSERT_FALSE(utils::is_double("-10D-22"));
}
TEST(Utils, strmatch_beg) {
ASSERT_TRUE(utils::strmatch("rigid/small/omp","^rigid"));
TEST(Utils, strmatch_beg)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "^rigid"));
}
TEST(Utils, strmatch_mid1) {
ASSERT_TRUE(utils::strmatch("rigid/small/omp","small"));
TEST(Utils, strmatch_mid1)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "small"));
}
TEST(Utils, strmatch_mid2) {
ASSERT_TRUE(utils::strmatch("rigid/small/omp","omp"));
TEST(Utils, strmatch_mid2)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "omp"));
}
TEST(Utils, strmatch_end) {
ASSERT_TRUE(utils::strmatch("rigid/small/omp","/omp$"));
TEST(Utils, strmatch_end)
{
ASSERT_TRUE(utils::strmatch("rigid/small/omp", "/omp$"));
}
TEST(Utils, no_strmatch_beg) {
ASSERT_FALSE(utils::strmatch("rigid/small/omp","^small"));
TEST(Utils, no_strmatch_beg)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "^small"));
}
TEST(Utils, no_strmatch_mid) {
ASSERT_FALSE(utils::strmatch("rigid/small/omp","none"));
TEST(Utils, no_strmatch_mid)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "none"));
}
TEST(Utils, no_strmatch_end) {
ASSERT_FALSE(utils::strmatch("rigid/small/omp","/opt$"));
TEST(Utils, no_strmatch_end)
{
ASSERT_FALSE(utils::strmatch("rigid/small/omp", "/opt$"));
}
TEST(Utils, strmatch_whole_line) {
ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNITS\\s*$"));
TEST(Utils, strmatch_whole_line)
{
ASSERT_TRUE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNITS\\s*$"));
}
TEST(Utils, no_strmatch_whole_line) {
ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n","^\\s*ITEM: UNIT\\s*$"));
TEST(Utils, no_strmatch_whole_line)
{
ASSERT_FALSE(utils::strmatch("ITEM: UNITS\n", "^\\s*ITEM: UNIT\\s*$"));
}
TEST(Utils, strmatch_integer_in_line) {
ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\d+\\s+angles\\s"));
TEST(Utils, strmatch_integer_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\d+\\s+angles\\s"));
}
TEST(Utils, strmatch_float_in_line) {
ASSERT_TRUE(utils::strmatch(" 5.0 angles\n","^\\s*\\f+\\s+angles\\s"));
TEST(Utils, strmatch_float_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\f+\\s+angles\\s"));
}
TEST(Utils, strmatch_int_as_float_in_line) {
ASSERT_TRUE(utils::strmatch(" 5 angles\n","^\\s*\\f+\\s+angles\\s"));
TEST(Utils, strmatch_int_as_float_in_line)
{
ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\f+\\s+angles\\s"));
}
TEST(Utils, strmatch_char_range) {
ASSERT_TRUE(utils::strmatch("rigid","^[ip-s]+gid"));
TEST(Utils, strmatch_char_range)
{
ASSERT_TRUE(utils::strmatch("rigid", "^[ip-s]+gid"));
}
TEST(Utils, strmatch_opt_range) {
ASSERT_TRUE(utils::strmatch("rigid","^[0-9]*[p-s]igid"));
TEST(Utils, strmatch_notchar_range)
{
ASSERT_TRUE(utils::strmatch("rigid", "^[^a-g]+gid"));
}
TEST(Utils, path_join) {
TEST(Utils, strmatch_backslash)
{
ASSERT_TRUE(utils::strmatch("\\rigid", "^\\W\\w+gid"));
}
TEST(Utils, strmatch_opt_range)
{
ASSERT_TRUE(utils::strmatch("rigid", "^[0-9]*[\\Wp-s]igid"));
}
TEST(Utils, strmatch_opt_char)
{
ASSERT_TRUE(utils::strmatch("rigid", "^r?igid"));
ASSERT_TRUE(utils::strmatch("igid", "^r?igid"));
}
TEST(Utils, strmatch_dot)
{
ASSERT_TRUE(utils::strmatch("rigid", ".igid"));
ASSERT_TRUE(utils::strmatch("Rigid", ".igid"));
}
TEST(Utils, strmatch_digit_nondigit)
{
ASSERT_TRUE(utils::strmatch(" 5 angles\n", "^\\s*\\d+\\s+\\D+\\s"));
}
TEST(Utils, strmatch_integer_noninteger)
{
ASSERT_TRUE(utils::strmatch(" -5 angles\n", "^\\s*\\i+\\s+\\I+\\s"));
}
TEST(Utils, strmatch_float_nonfloat)
{
ASSERT_TRUE(utils::strmatch(" 5.0 angls\n", "^\\s*\\f+\\s+\\F+\\s"));
}
TEST(Utils, strmatch_whitespace_nonwhitespace)
{
ASSERT_TRUE(utils::strmatch(" 5.0 angles\n", "^\\s*\\S+\\s+\\S+\\s"));
}
TEST(Utils, guesspath)
{
char buf[256];
FILE *fp = fopen("test_guesspath.txt","w");
#if defined(__linux__)
const char *path = utils::guesspath(buf,sizeof(buf),fp);
ASSERT_THAT(path,EndsWith("test_guesspath.txt"));
#else
const char *path = utils::guesspath(buf,sizeof(buf),fp);
ASSERT_THAT(path,EndsWith("(unknown)"));
#endif
fclose(fp);
}
TEST(Utils, path_join)
{
#if defined(_WIN32)
ASSERT_THAT(utils::path_join("c:\\parent\\folder", "filename"), Eq("c:\\parent\\folder\\filename"));
ASSERT_THAT(utils::path_join("c:\\parent\\folder", "filename"),
Eq("c:\\parent\\folder\\filename"));
#else
ASSERT_THAT(utils::path_join("/parent/folder", "filename"), Eq("/parent/folder/filename"));
#endif
}
TEST(Utils, path_basename) {
TEST(Utils, path_basename)
{
#if defined(_WIN32)
ASSERT_THAT(utils::path_basename("c:\\parent\\folder\\filename"), Eq("filename"));
#else
ASSERT_THAT(utils::path_basename("/parent/folder/filename"), Eq("filename"));
#endif
}
TEST(Utils, getsyserror)
{
#if defined(__linux__)
errno = ENOENT;
std::string errmesg = utils::getsyserror();
ASSERT_THAT(errmesg, Eq("No such file or directory"));
#else
GTEST_SKIP();
#endif
}
TEST(Utils, potential_file)
{
FILE *fp;
fp = fopen("ctest1.txt", "w");
ASSERT_NE(fp, nullptr);
fputs("# DATE: 2020-02-20 UNITS: real CONTRIBUTOR: Nessuno\n", fp);
fclose(fp);
fp = fopen("ctest2.txt", "w");
ASSERT_NE(fp, nullptr);
fputs("# CONTRIBUTOR: Pippo\n", fp);
fclose(fp);
ASSERT_TRUE(utils::file_is_readable("ctest1.txt"));
ASSERT_TRUE(utils::file_is_readable("ctest2.txt"));
ASSERT_FALSE(utils::file_is_readable("no_such_file.txt"));
ASSERT_THAT(utils::get_potential_file_path("ctest1.txt"), Eq("ctest1.txt"));
ASSERT_THAT(utils::get_potential_file_path("no_such_file.txt"), Eq(""));
const char *folder = getenv("LAMMPS_POTENTIALS");
if (folder != nullptr) {
std::string path = utils::path_join(folder, "Cu_u3.eam");
EXPECT_THAT(utils::get_potential_file_path("Cu_u3.eam"), Eq(path));
EXPECT_THAT(utils::get_potential_units(path, "EAM"), Eq("metal"));
}
ASSERT_THAT(utils::get_potential_date("ctest1.txt", "Test"), Eq("2020-02-20"));
ASSERT_THAT(utils::get_potential_units("ctest1.txt", "Test"), Eq("real"));
ASSERT_THAT(utils::get_potential_date("ctest2.txt", "Test"), Eq(""));
ASSERT_THAT(utils::get_potential_units("ctest2.txt", "Test"), Eq(""));
remove("ctest1.txt");
remove("ctest2.txt");
}
TEST(Utils, unit_conversion)
{
double factor;
int flag;
flag = utils::get_supported_conversions(utils::UNKNOWN);
ASSERT_EQ(flag, utils::NOCONVERT);
flag = utils::get_supported_conversions(utils::ENERGY);
ASSERT_EQ(flag, utils::METAL2REAL | utils::REAL2METAL);
factor = utils::get_conversion_factor(utils::UNKNOWN, (1 << 30) - 1);
ASSERT_DOUBLE_EQ(factor, 0.0);
factor = utils::get_conversion_factor(utils::UNKNOWN, utils::NOCONVERT);
ASSERT_DOUBLE_EQ(factor, 0.0);
factor = utils::get_conversion_factor(utils::ENERGY, utils::NOCONVERT);
ASSERT_DOUBLE_EQ(factor, 1.0);
factor = utils::get_conversion_factor(utils::ENERGY, utils::METAL2REAL);
ASSERT_DOUBLE_EQ(factor, 23.060549);
factor = utils::get_conversion_factor(utils::ENERGY, utils::REAL2METAL);
ASSERT_DOUBLE_EQ(factor, 1.0 / 23.060549);
}