File: test_lmptype.cpp

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (79 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* ----------------------------------------------------------------------
   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[7];
    int64_t b1 = (3L << 48) - 1;
    int i1     = 20;
    double d1  = 0.1;

    m[0] = b1;
    m[1] = i1;
    m[2] = d1;

    m[3] = (bigint) - ((1L << 40) + (1L << 50));
    m[4] = -1023;
    m[5] = -2.225;

    EXPECT_EQ(m[0].type, multitype::LAMMPS_INT64);
    EXPECT_EQ(m[1].type, multitype::LAMMPS_INT);
    EXPECT_EQ(m[2].type, multitype::LAMMPS_DOUBLE);

#if defined(LAMMPS_SMALLSMALL)
    EXPECT_EQ(m[3].type, multitype::LAMMPS_INT);
#else
    EXPECT_EQ(m[3].type, multitype::LAMMPS_INT64);
#endif
    EXPECT_EQ(m[4].type, multitype::LAMMPS_INT);
    EXPECT_EQ(m[5].type, multitype::LAMMPS_DOUBLE);
    EXPECT_EQ(m[6].type, multitype::LAMMPS_NONE);

    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);
}