Merge remote-tracking branch 'akohlmey/unit-test-updates' into refactor-table-reading
This commit is contained in:
@ -5,3 +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)
|
||||
|
||||
add_executable(test_fmtlib test_fmtlib.cpp)
|
||||
target_link_libraries(test_fmtlib PRIVATE lammps GTest::GMockMain GTest::GMock GTest::GTest)
|
||||
add_test(FmtLib test_fmtlib)
|
||||
|
||||
106
unittest/utils/test_fmtlib.cpp
Normal file
106
unittest/utils/test_fmtlib.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
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 <exception>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
using ::testing::Eq;
|
||||
|
||||
// this tests a subset of {fmt} that is most relevant to LAMMPS
|
||||
|
||||
TEST(FmtLib, insert_string) {
|
||||
const char val[] = "word";
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word word"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_int) {
|
||||
const int val = 333;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word 333"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_neg_int) {
|
||||
const int val = -333;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word -333"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_bigint) {
|
||||
if (sizeof(bigint) == 4) GTEST_SKIP();
|
||||
const bigint val = 9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_neg_bigint) {
|
||||
if (sizeof(bigint) == 4) GTEST_SKIP();
|
||||
const bigint val = -9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_tagint) {
|
||||
if (sizeof(tagint) == 4) GTEST_SKIP();
|
||||
const tagint val = 9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_neg_tagint) {
|
||||
if (sizeof(tagint) == 4) GTEST_SKIP();
|
||||
const tagint val = -9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_imageint) {
|
||||
if (sizeof(imageint) == 4) GTEST_SKIP();
|
||||
const imageint val = 9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word 9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_neg_imageint) {
|
||||
if (sizeof(imageint) == 4) GTEST_SKIP();
|
||||
const imageint val = -9945234592L;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word -9945234592"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_double) {
|
||||
const double val = 1.5;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word 1.5"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, insert_neg_double) {
|
||||
const double val = -1.5;
|
||||
auto text = fmt::format("word {}",val);
|
||||
ASSERT_THAT(text, Eq("word -1.5"));
|
||||
}
|
||||
|
||||
TEST(FmtLib, int_for_double) {
|
||||
const double val = -1.5;
|
||||
ASSERT_THROW(fmt::format("word {:d}",val),std::exception);
|
||||
}
|
||||
|
||||
TEST(FmtLib, double_for_int) {
|
||||
const int val = 15;
|
||||
ASSERT_THROW(fmt::format("word {:g}",val),std::exception);
|
||||
}
|
||||
@ -1,5 +1,18 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "tokenizer.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
@ -1,5 +1,18 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "utils.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user