add multitype data type and unittest (including tests for ubuf)

This commit is contained in:
Axel Kohlmeyer
2023-06-06 20:38:15 -04:00
parent 9cc6839a8b
commit 14acb3e0ca
3 changed files with 168 additions and 2 deletions

View File

@ -7,6 +7,10 @@ add_executable(test_mempool test_mempool.cpp)
target_link_libraries(test_mempool PRIVATE lammps GTest::GMockMain)
add_test(NAME MemPool COMMAND test_mempool)
add_executable(test_lmptype test_lmptype.cpp)
target_link_libraries(test_lmptype PRIVATE lammps GTest::GMockMain)
add_test(NAME LmpType COMMAND test_lmptype)
add_executable(test_argutils test_argutils.cpp)
target_link_libraries(test_argutils PRIVATE lammps GTest::GMockMain)
add_test(NAME ArgUtils COMMAND test_argutils)

View File

@ -0,0 +1,84 @@
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
https://www.lammps.org/, Sandia National Laboratories
LAMMPS Development team: developers@lammps.org
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 "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
using namespace LAMMPS_NS;
TEST(Types, ubuf)
{
double buf[3];
double d1 = 0.1;
int i1 = -10;
#if defined(LAMMPS_SMALLSMALL)
bigint b1 = 2048;
#else
bigint b1 = (1L << 58) + (1L << 50);
#endif
buf[0] = d1;
buf[1] = ubuf(i1).d;
buf[2] = ubuf(b1).d;
EXPECT_EQ(d1, buf[0]);
EXPECT_EQ(i1, (int)ubuf(buf[1]).i);
EXPECT_EQ(b1, (bigint)ubuf(buf[2]).i);
}
TEST(Types, multitype)
{
multitype m[6];
int64_t b1 = (3L << 48) - 1;
int i1 = 20;
double d1 = 0.1;
m[0] = b1;
m[1] = i1;
m[2] = d1;
#if !defined(LAMMPS_SMALLSMALL)
m[3] = -((1L << 40) + (1L << 50));
#endif
m[4] = -1023;
m[5] = -2.225;
#if defined(LAMMPS_SMALLSMALL)
EXPECT_EQ(m[0].type, multitype::INT);
#else
EXPECT_EQ(m[0].type, multitype::BIGINT);
#endif
EXPECT_EQ(m[1].type, multitype::INT);
EXPECT_EQ(m[2].type, multitype::DOUBLE);
#if defined(LAMMPS_SMALLSMALL)
EXPECT_EQ(m[3].type, multitype::NONE);
#else
EXPECT_EQ(m[3].type, multitype::BIGINT);
#endif
EXPECT_EQ(m[4].type, multitype::INT);
EXPECT_EQ(m[5].type, multitype::DOUBLE);
EXPECT_EQ(m[0].data.b, b1);
EXPECT_EQ(m[1].data.i, i1);
EXPECT_EQ(m[2].data.d, d1);
#if !defined(LAMMPS_SMALLSMALL)
EXPECT_EQ(m[3].data.b, -((1L << 40) + (1L << 50)));
#endif
EXPECT_EQ(m[4].data.i, -1023);
EXPECT_EQ(m[5].data.d, -2.225);
}