reformat unittest sources with clang-format

This commit is contained in:
Axel Kohlmeyer
2020-11-18 18:27:20 -05:00
committed by Richard Berger
parent a8b60848c3
commit 569a000e6b
32 changed files with 2022 additions and 2071 deletions

View File

@ -488,79 +488,79 @@ TEST_F(ResetIDsTest, TopologyData)
auto angle_atom1 = lmp->atom->angle_atom1;
auto angle_atom2 = lmp->atom->angle_atom2;
auto angle_atom3 = lmp->atom->angle_atom3;
ASSERT_EQ(num_bond[GETIDX(1)],2);
ASSERT_EQ(bond_atom[GETIDX(1)][0],2);
ASSERT_EQ(bond_atom[GETIDX(1)][1],3);
ASSERT_EQ(num_bond[GETIDX(2)],0);
ASSERT_EQ(num_bond[GETIDX(3)],3);
ASSERT_EQ(bond_atom[GETIDX(3)][0],4);
ASSERT_EQ(bond_atom[GETIDX(3)][1],5);
ASSERT_EQ(bond_atom[GETIDX(3)][2],6);
ASSERT_EQ(num_bond[GETIDX(4)],0);
ASSERT_EQ(num_bond[GETIDX(5)],0);
ASSERT_EQ(num_bond[GETIDX(6)],2);
ASSERT_EQ(bond_atom[GETIDX(6)][0],8);
ASSERT_EQ(bond_atom[GETIDX(6)][1],7);
ASSERT_EQ(num_bond[GETIDX(7)],0);
ASSERT_EQ(num_bond[GETIDX(8)],2);
ASSERT_EQ(bond_atom[GETIDX(8)][0],9);
ASSERT_EQ(bond_atom[GETIDX(8)][1],10);
ASSERT_EQ(num_bond[GETIDX(9)],0);
ASSERT_EQ(num_bond[GETIDX(10)],3);
ASSERT_EQ(bond_atom[GETIDX(10)][0],11);
ASSERT_EQ(bond_atom[GETIDX(10)][1],12);
ASSERT_EQ(bond_atom[GETIDX(10)][2],16);
ASSERT_EQ(num_bond[GETIDX(11)],0);
ASSERT_EQ(num_bond[GETIDX(12)],3);
ASSERT_EQ(bond_atom[GETIDX(12)][0],13);
ASSERT_EQ(bond_atom[GETIDX(12)][1],14);
ASSERT_EQ(bond_atom[GETIDX(12)][2],15);
ASSERT_EQ(num_bond[GETIDX(13)],0);
ASSERT_EQ(num_bond[GETIDX(14)],0);
ASSERT_EQ(num_bond[GETIDX(15)],0);
ASSERT_EQ(num_bond[GETIDX(16)],1);
ASSERT_EQ(bond_atom[GETIDX(16)][0],17);
ASSERT_EQ(num_bond[GETIDX(17)],0);
ASSERT_EQ(num_bond[GETIDX(18)],2);
ASSERT_EQ(bond_atom[GETIDX(18)][0],19);
ASSERT_EQ(bond_atom[GETIDX(18)][1],20);
ASSERT_EQ(num_bond[GETIDX(19)],0);
ASSERT_EQ(num_bond[GETIDX(20)],0);
ASSERT_EQ(num_bond[GETIDX(24)],2);
ASSERT_EQ(bond_atom[GETIDX(24)][0],25);
ASSERT_EQ(bond_atom[GETIDX(24)][1],26);
ASSERT_EQ(num_bond[GETIDX(25)],0);
ASSERT_EQ(num_bond[GETIDX(26)],0);
ASSERT_EQ(num_bond[GETIDX(1)], 2);
ASSERT_EQ(bond_atom[GETIDX(1)][0], 2);
ASSERT_EQ(bond_atom[GETIDX(1)][1], 3);
ASSERT_EQ(num_bond[GETIDX(2)], 0);
ASSERT_EQ(num_bond[GETIDX(3)], 3);
ASSERT_EQ(bond_atom[GETIDX(3)][0], 4);
ASSERT_EQ(bond_atom[GETIDX(3)][1], 5);
ASSERT_EQ(bond_atom[GETIDX(3)][2], 6);
ASSERT_EQ(num_bond[GETIDX(4)], 0);
ASSERT_EQ(num_bond[GETIDX(5)], 0);
ASSERT_EQ(num_bond[GETIDX(6)], 2);
ASSERT_EQ(bond_atom[GETIDX(6)][0], 8);
ASSERT_EQ(bond_atom[GETIDX(6)][1], 7);
ASSERT_EQ(num_bond[GETIDX(7)], 0);
ASSERT_EQ(num_bond[GETIDX(8)], 2);
ASSERT_EQ(bond_atom[GETIDX(8)][0], 9);
ASSERT_EQ(bond_atom[GETIDX(8)][1], 10);
ASSERT_EQ(num_bond[GETIDX(9)], 0);
ASSERT_EQ(num_bond[GETIDX(10)], 3);
ASSERT_EQ(bond_atom[GETIDX(10)][0], 11);
ASSERT_EQ(bond_atom[GETIDX(10)][1], 12);
ASSERT_EQ(bond_atom[GETIDX(10)][2], 16);
ASSERT_EQ(num_bond[GETIDX(11)], 0);
ASSERT_EQ(num_bond[GETIDX(12)], 3);
ASSERT_EQ(bond_atom[GETIDX(12)][0], 13);
ASSERT_EQ(bond_atom[GETIDX(12)][1], 14);
ASSERT_EQ(bond_atom[GETIDX(12)][2], 15);
ASSERT_EQ(num_bond[GETIDX(13)], 0);
ASSERT_EQ(num_bond[GETIDX(14)], 0);
ASSERT_EQ(num_bond[GETIDX(15)], 0);
ASSERT_EQ(num_bond[GETIDX(16)], 1);
ASSERT_EQ(bond_atom[GETIDX(16)][0], 17);
ASSERT_EQ(num_bond[GETIDX(17)], 0);
ASSERT_EQ(num_bond[GETIDX(18)], 2);
ASSERT_EQ(bond_atom[GETIDX(18)][0], 19);
ASSERT_EQ(bond_atom[GETIDX(18)][1], 20);
ASSERT_EQ(num_bond[GETIDX(19)], 0);
ASSERT_EQ(num_bond[GETIDX(20)], 0);
ASSERT_EQ(num_bond[GETIDX(24)], 2);
ASSERT_EQ(bond_atom[GETIDX(24)][0], 25);
ASSERT_EQ(bond_atom[GETIDX(24)][1], 26);
ASSERT_EQ(num_bond[GETIDX(25)], 0);
ASSERT_EQ(num_bond[GETIDX(26)], 0);
ASSERT_EQ(num_angle[GETIDX(1)],1);
ASSERT_EQ(angle_atom1[GETIDX(1)][0],2);
ASSERT_EQ(angle_atom2[GETIDX(1)][0],1);
ASSERT_EQ(angle_atom3[GETIDX(1)][0],3);
ASSERT_EQ(num_angle[GETIDX(2)],0);
ASSERT_EQ(num_angle[GETIDX(3)],6);
ASSERT_EQ(angle_atom1[GETIDX(3)][0],1);
ASSERT_EQ(angle_atom2[GETIDX(3)][0],3);
ASSERT_EQ(angle_atom3[GETIDX(3)][0],5);
ASSERT_EQ(angle_atom1[GETIDX(3)][1],1);
ASSERT_EQ(angle_atom2[GETIDX(3)][1],3);
ASSERT_EQ(angle_atom3[GETIDX(3)][1],4);
ASSERT_EQ(angle_atom1[GETIDX(3)][2],1);
ASSERT_EQ(angle_atom2[GETIDX(3)][2],3);
ASSERT_EQ(angle_atom3[GETIDX(3)][2],6);
ASSERT_EQ(angle_atom1[GETIDX(3)][3],4);
ASSERT_EQ(angle_atom2[GETIDX(3)][3],3);
ASSERT_EQ(angle_atom3[GETIDX(3)][3],5);
ASSERT_EQ(angle_atom1[GETIDX(3)][4],5);
ASSERT_EQ(angle_atom2[GETIDX(3)][4],3);
ASSERT_EQ(angle_atom3[GETIDX(3)][4],6);
ASSERT_EQ(num_angle[GETIDX(18)],1);
ASSERT_EQ(angle_atom1[GETIDX(18)][0],19);
ASSERT_EQ(angle_atom2[GETIDX(18)][0],18);
ASSERT_EQ(angle_atom3[GETIDX(18)][0],20);
ASSERT_EQ(num_angle[GETIDX(24)],1);
ASSERT_EQ(angle_atom1[GETIDX(24)][0],25);
ASSERT_EQ(angle_atom2[GETIDX(24)][0],24);
ASSERT_EQ(angle_atom3[GETIDX(24)][0],26);
ASSERT_EQ(num_angle[GETIDX(1)], 1);
ASSERT_EQ(angle_atom1[GETIDX(1)][0], 2);
ASSERT_EQ(angle_atom2[GETIDX(1)][0], 1);
ASSERT_EQ(angle_atom3[GETIDX(1)][0], 3);
ASSERT_EQ(num_angle[GETIDX(2)], 0);
ASSERT_EQ(num_angle[GETIDX(3)], 6);
ASSERT_EQ(angle_atom1[GETIDX(3)][0], 1);
ASSERT_EQ(angle_atom2[GETIDX(3)][0], 3);
ASSERT_EQ(angle_atom3[GETIDX(3)][0], 5);
ASSERT_EQ(angle_atom1[GETIDX(3)][1], 1);
ASSERT_EQ(angle_atom2[GETIDX(3)][1], 3);
ASSERT_EQ(angle_atom3[GETIDX(3)][1], 4);
ASSERT_EQ(angle_atom1[GETIDX(3)][2], 1);
ASSERT_EQ(angle_atom2[GETIDX(3)][2], 3);
ASSERT_EQ(angle_atom3[GETIDX(3)][2], 6);
ASSERT_EQ(angle_atom1[GETIDX(3)][3], 4);
ASSERT_EQ(angle_atom2[GETIDX(3)][3], 3);
ASSERT_EQ(angle_atom3[GETIDX(3)][3], 5);
ASSERT_EQ(angle_atom1[GETIDX(3)][4], 5);
ASSERT_EQ(angle_atom2[GETIDX(3)][4], 3);
ASSERT_EQ(angle_atom3[GETIDX(3)][4], 6);
ASSERT_EQ(num_angle[GETIDX(18)], 1);
ASSERT_EQ(angle_atom1[GETIDX(18)][0], 19);
ASSERT_EQ(angle_atom2[GETIDX(18)][0], 18);
ASSERT_EQ(angle_atom3[GETIDX(18)][0], 20);
ASSERT_EQ(num_angle[GETIDX(24)], 1);
ASSERT_EQ(angle_atom1[GETIDX(24)][0], 25);
ASSERT_EQ(angle_atom2[GETIDX(24)][0], 24);
ASSERT_EQ(angle_atom3[GETIDX(24)][0], 26);
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("reset_atom_ids sort yes");
@ -574,88 +574,88 @@ TEST_F(ResetIDsTest, TopologyData)
angle_atom1 = lmp->atom->angle_atom1;
angle_atom2 = lmp->atom->angle_atom2;
angle_atom3 = lmp->atom->angle_atom3;
ASSERT_EQ(num_bond[GETIDX(1)],2);
ASSERT_EQ(bond_atom[GETIDX(1)][0],3);
ASSERT_EQ(bond_atom[GETIDX(1)][1],2);
ASSERT_EQ(num_bond[GETIDX(2)],0);
ASSERT_EQ(num_bond[GETIDX(3)],2);
ASSERT_EQ(bond_atom[GETIDX(3)][0],16);
ASSERT_EQ(bond_atom[GETIDX(3)][1],5);
ASSERT_EQ(num_bond[GETIDX(4)],0);
ASSERT_EQ(num_bond[GETIDX(5)],3);
ASSERT_EQ(bond_atom[GETIDX(5)][0],4);
ASSERT_EQ(bond_atom[GETIDX(5)][1],8);
ASSERT_EQ(bond_atom[GETIDX(5)][2],18);
ASSERT_EQ(num_bond[GETIDX(6)],0);
ASSERT_EQ(num_bond[GETIDX(7)],0);
ASSERT_EQ(num_bond[GETIDX(8)],3);
ASSERT_EQ(bond_atom[GETIDX(8)][0],9);
ASSERT_EQ(bond_atom[GETIDX(8)][1],6);
ASSERT_EQ(bond_atom[GETIDX(8)][2],7);
ASSERT_EQ(num_bond[GETIDX(9)],0);
ASSERT_EQ(num_bond[GETIDX(10)],0);
ASSERT_EQ(num_bond[GETIDX(11)],3);
ASSERT_EQ(bond_atom[GETIDX(11)][0],10);
ASSERT_EQ(bond_atom[GETIDX(11)][1],19);
ASSERT_EQ(bond_atom[GETIDX(11)][2],1);
ASSERT_EQ(num_bond[GETIDX(12)],0);
ASSERT_EQ(num_bond[GETIDX(13)],0);
ASSERT_EQ(num_bond[GETIDX(14)],2);
ASSERT_EQ(bond_atom[GETIDX(14)][0],13);
ASSERT_EQ(bond_atom[GETIDX(14)][1],15);
ASSERT_EQ(num_bond[GETIDX(15)],0);
ASSERT_EQ(num_bond[GETIDX(16)],0);
ASSERT_EQ(num_bond[GETIDX(17)],0);
ASSERT_EQ(num_bond[GETIDX(18)],1);
ASSERT_EQ(bond_atom[GETIDX(18)][0],17);
ASSERT_EQ(num_bond[GETIDX(19)],0);
ASSERT_EQ(num_bond[GETIDX(20)],2);
ASSERT_EQ(bond_atom[GETIDX(20)][0],12);
ASSERT_EQ(bond_atom[GETIDX(20)][1],11);
ASSERT_EQ(num_bond[GETIDX(21)],0);
ASSERT_EQ(num_bond[GETIDX(22)],2);
ASSERT_EQ(bond_atom[GETIDX(22)][0],21);
ASSERT_EQ(bond_atom[GETIDX(22)][1],23);
ASSERT_EQ(num_bond[GETIDX(23)],0);
ASSERT_EQ(num_bond[GETIDX(1)], 2);
ASSERT_EQ(bond_atom[GETIDX(1)][0], 3);
ASSERT_EQ(bond_atom[GETIDX(1)][1], 2);
ASSERT_EQ(num_bond[GETIDX(2)], 0);
ASSERT_EQ(num_bond[GETIDX(3)], 2);
ASSERT_EQ(bond_atom[GETIDX(3)][0], 16);
ASSERT_EQ(bond_atom[GETIDX(3)][1], 5);
ASSERT_EQ(num_bond[GETIDX(4)], 0);
ASSERT_EQ(num_bond[GETIDX(5)], 3);
ASSERT_EQ(bond_atom[GETIDX(5)][0], 4);
ASSERT_EQ(bond_atom[GETIDX(5)][1], 8);
ASSERT_EQ(bond_atom[GETIDX(5)][2], 18);
ASSERT_EQ(num_bond[GETIDX(6)], 0);
ASSERT_EQ(num_bond[GETIDX(7)], 0);
ASSERT_EQ(num_bond[GETIDX(8)], 3);
ASSERT_EQ(bond_atom[GETIDX(8)][0], 9);
ASSERT_EQ(bond_atom[GETIDX(8)][1], 6);
ASSERT_EQ(bond_atom[GETIDX(8)][2], 7);
ASSERT_EQ(num_bond[GETIDX(9)], 0);
ASSERT_EQ(num_bond[GETIDX(10)], 0);
ASSERT_EQ(num_bond[GETIDX(11)], 3);
ASSERT_EQ(bond_atom[GETIDX(11)][0], 10);
ASSERT_EQ(bond_atom[GETIDX(11)][1], 19);
ASSERT_EQ(bond_atom[GETIDX(11)][2], 1);
ASSERT_EQ(num_bond[GETIDX(12)], 0);
ASSERT_EQ(num_bond[GETIDX(13)], 0);
ASSERT_EQ(num_bond[GETIDX(14)], 2);
ASSERT_EQ(bond_atom[GETIDX(14)][0], 13);
ASSERT_EQ(bond_atom[GETIDX(14)][1], 15);
ASSERT_EQ(num_bond[GETIDX(15)], 0);
ASSERT_EQ(num_bond[GETIDX(16)], 0);
ASSERT_EQ(num_bond[GETIDX(17)], 0);
ASSERT_EQ(num_bond[GETIDX(18)], 1);
ASSERT_EQ(bond_atom[GETIDX(18)][0], 17);
ASSERT_EQ(num_bond[GETIDX(19)], 0);
ASSERT_EQ(num_bond[GETIDX(20)], 2);
ASSERT_EQ(bond_atom[GETIDX(20)][0], 12);
ASSERT_EQ(bond_atom[GETIDX(20)][1], 11);
ASSERT_EQ(num_bond[GETIDX(21)], 0);
ASSERT_EQ(num_bond[GETIDX(22)], 2);
ASSERT_EQ(bond_atom[GETIDX(22)][0], 21);
ASSERT_EQ(bond_atom[GETIDX(22)][1], 23);
ASSERT_EQ(num_bond[GETIDX(23)], 0);
ASSERT_EQ(num_angle[GETIDX(1)],3);
ASSERT_EQ(angle_atom1[GETIDX(1)][0],11);
ASSERT_EQ(angle_atom2[GETIDX(1)][0],1);
ASSERT_EQ(angle_atom3[GETIDX(1)][0],2);
ASSERT_EQ(angle_atom1[GETIDX(1)][1],11);
ASSERT_EQ(angle_atom2[GETIDX(1)][1],1);
ASSERT_EQ(angle_atom3[GETIDX(1)][1],3);
ASSERT_EQ(angle_atom1[GETIDX(1)][2],2);
ASSERT_EQ(angle_atom2[GETIDX(1)][2],1);
ASSERT_EQ(angle_atom3[GETIDX(1)][2],3);
ASSERT_EQ(num_angle[GETIDX(2)],0);
ASSERT_EQ(num_angle[GETIDX(5)],6);
ASSERT_EQ(angle_atom1[GETIDX(5)][0],3);
ASSERT_EQ(angle_atom2[GETIDX(5)][0],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][0],4);
ASSERT_EQ(angle_atom1[GETIDX(5)][1],3);
ASSERT_EQ(angle_atom2[GETIDX(5)][1],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][1],18);
ASSERT_EQ(angle_atom1[GETIDX(5)][2],4);
ASSERT_EQ(angle_atom2[GETIDX(5)][2],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][2],8);
ASSERT_EQ(angle_atom1[GETIDX(5)][3],8);
ASSERT_EQ(angle_atom2[GETIDX(5)][3],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][3],18);
ASSERT_EQ(angle_atom1[GETIDX(5)][4],3);
ASSERT_EQ(angle_atom2[GETIDX(5)][4],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][4],8);
ASSERT_EQ(angle_atom1[GETIDX(5)][5],4);
ASSERT_EQ(angle_atom2[GETIDX(5)][5],5);
ASSERT_EQ(angle_atom3[GETIDX(5)][5],18);
ASSERT_EQ(num_angle[GETIDX(20)],1);
ASSERT_EQ(angle_atom1[GETIDX(20)][0],12);
ASSERT_EQ(angle_atom2[GETIDX(20)][0],20);
ASSERT_EQ(angle_atom3[GETIDX(20)][0],11);
ASSERT_EQ(num_angle[GETIDX(22)],1);
ASSERT_EQ(angle_atom1[GETIDX(22)][0],21);
ASSERT_EQ(angle_atom2[GETIDX(22)][0],22);
ASSERT_EQ(angle_atom3[GETIDX(22)][0],23);
ASSERT_EQ(num_angle[GETIDX(1)], 3);
ASSERT_EQ(angle_atom1[GETIDX(1)][0], 11);
ASSERT_EQ(angle_atom2[GETIDX(1)][0], 1);
ASSERT_EQ(angle_atom3[GETIDX(1)][0], 2);
ASSERT_EQ(angle_atom1[GETIDX(1)][1], 11);
ASSERT_EQ(angle_atom2[GETIDX(1)][1], 1);
ASSERT_EQ(angle_atom3[GETIDX(1)][1], 3);
ASSERT_EQ(angle_atom1[GETIDX(1)][2], 2);
ASSERT_EQ(angle_atom2[GETIDX(1)][2], 1);
ASSERT_EQ(angle_atom3[GETIDX(1)][2], 3);
ASSERT_EQ(num_angle[GETIDX(2)], 0);
ASSERT_EQ(num_angle[GETIDX(5)], 6);
ASSERT_EQ(angle_atom1[GETIDX(5)][0], 3);
ASSERT_EQ(angle_atom2[GETIDX(5)][0], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][0], 4);
ASSERT_EQ(angle_atom1[GETIDX(5)][1], 3);
ASSERT_EQ(angle_atom2[GETIDX(5)][1], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][1], 18);
ASSERT_EQ(angle_atom1[GETIDX(5)][2], 4);
ASSERT_EQ(angle_atom2[GETIDX(5)][2], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][2], 8);
ASSERT_EQ(angle_atom1[GETIDX(5)][3], 8);
ASSERT_EQ(angle_atom2[GETIDX(5)][3], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][3], 18);
ASSERT_EQ(angle_atom1[GETIDX(5)][4], 3);
ASSERT_EQ(angle_atom2[GETIDX(5)][4], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][4], 8);
ASSERT_EQ(angle_atom1[GETIDX(5)][5], 4);
ASSERT_EQ(angle_atom2[GETIDX(5)][5], 5);
ASSERT_EQ(angle_atom3[GETIDX(5)][5], 18);
ASSERT_EQ(num_angle[GETIDX(20)], 1);
ASSERT_EQ(angle_atom1[GETIDX(20)][0], 12);
ASSERT_EQ(angle_atom2[GETIDX(20)][0], 20);
ASSERT_EQ(angle_atom3[GETIDX(20)][0], 11);
ASSERT_EQ(num_angle[GETIDX(22)], 1);
ASSERT_EQ(angle_atom1[GETIDX(22)][0], 21);
ASSERT_EQ(angle_atom2[GETIDX(22)][0], 22);
ASSERT_EQ(angle_atom3[GETIDX(22)][0], 23);
}
TEST_F(ResetIDsTest, DeathTests)

View File

@ -319,7 +319,7 @@ TEST_F(SimpleCommandsTest, Shell)
lmp->input->one("shell putenv TEST_VARIABLE=simpletest");
if (!verbose) ::testing::internal::GetCapturedStdout();
char * test_var = getenv("TEST_VARIABLE");
char *test_var = getenv("TEST_VARIABLE");
ASSERT_NE(test_var, nullptr);
ASSERT_THAT(test_var, StrEq("simpletest"));
@ -328,8 +328,8 @@ TEST_F(SimpleCommandsTest, Shell)
lmp->input->one("shell putenv TEST_VARIABLE2=simpletest2 OTHER_VARIABLE=2");
if (!verbose) ::testing::internal::GetCapturedStdout();
char * test_var2 = getenv("TEST_VARIABLE2");
char * other_var = getenv("OTHER_VARIABLE");
char *test_var2 = getenv("TEST_VARIABLE2");
char *other_var = getenv("OTHER_VARIABLE");
ASSERT_NE(test_var2, nullptr);
ASSERT_THAT(test_var2, StrEq("simpletest2"));

View File

@ -1,114 +1,110 @@
// unit tests for issuing command to a LAMMPS instance through the Input class
#include "lammps.h"
#include "input.h"
#include "atom.h"
#include "input.h"
#include "lammps.h"
#include "memory.h"
#include <cstring>
#include <mpi.h>
#include <string>
#include <cstring>
#include "gtest/gtest.h"
const char *demo_input[] = {
"region box block 0 $x 0 2 0 2",
"create_box 1 box",
"create_atoms 1 single 1.0 1.0 ${zpos}" };
const char *cont_input[] = {
"create_atoms 1 single &",
"0.2 0.1 0.1" };
const char *demo_input[] = {"region box block 0 $x 0 2 0 2", "create_box 1 box",
"create_atoms 1 single 1.0 1.0 ${zpos}"};
const char *cont_input[] = {"create_atoms 1 single &", "0.2 0.1 0.1"};
namespace LAMMPS_NS
{
namespace LAMMPS_NS {
class Input_commands : public ::testing::Test
{
protected:
class Input_commands : public ::testing::Test {
protected:
LAMMPS *lmp;
Input_commands() {
Input_commands()
{
const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
int flag;
MPI_Initialized(&flag);
if (!flag) MPI_Init(&argc,&argv);
if (!flag) MPI_Init(&argc, &argv);
}
~Input_commands() override {}
void SetUp() override {
const char *args[] = {"LAMMPS_test",
"-log", "none",
"-echo", "screen",
"-nocite",
"-var", "zpos", "1.5",
"-var","x","2"};
void SetUp() override
{
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "screen", "-nocite",
"-var", "zpos", "1.5", "-var", "x", "2"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS (");
}
void TearDown() override {
void TearDown() override
{
::testing::internal::CaptureStdout();
delete lmp;
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
lmp = nullptr;
}
};
};
TEST_F(Input_commands, from_file) {
TEST_F(Input_commands, from_file)
{
FILE *fp;
const char demo_file[] = "in.test";
const char cont_file[] = "in.cont";
fp = fopen(demo_file,"w");
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
fputs(demo_input[i],fp);
fputc('\n',fp);
fp = fopen(demo_file, "w");
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
fputs(demo_input[i], fp);
fputc('\n', fp);
}
fclose(fp);
fp = fopen(cont_file,"w");
for (unsigned int i=0; i < sizeof(cont_input)/sizeof(char *); ++i) {
fputs(cont_input[i],fp);
fputc('\n',fp);
fp = fopen(cont_file, "w");
for (unsigned int i = 0; i < sizeof(cont_input) / sizeof(char *); ++i) {
fputs(cont_input[i], fp);
fputc('\n', fp);
}
fclose(fp);
EXPECT_EQ(lmp->atom->natoms,0);
EXPECT_EQ(lmp->atom->natoms, 0);
lmp->input->file(demo_file);
lmp->input->file(cont_file);
EXPECT_EQ(lmp->atom->natoms,2);
EXPECT_EQ(lmp->atom->natoms, 2);
unlink(demo_file);
unlink(cont_file);
};
};
TEST_F(Input_commands, from_line) {
EXPECT_EQ(lmp->atom->natoms,0);
for (unsigned int i=0; i < sizeof(demo_input)/sizeof(char *); ++i) {
TEST_F(Input_commands, from_line)
{
EXPECT_EQ(lmp->atom->natoms, 0);
for (unsigned int i = 0; i < sizeof(demo_input) / sizeof(char *); ++i) {
lmp->input->one(demo_input[i]);
}
EXPECT_EQ(lmp->atom->natoms,1);
};
EXPECT_EQ(lmp->atom->natoms, 1);
};
TEST_F(Input_commands, substitute) {
char *string,*scratch;
int nstring=100,nscratch=100;
TEST_F(Input_commands, substitute)
{
char *string, *scratch;
int nstring = 100, nscratch = 100;
lmp->memory->create(string,nstring,"test:string");
lmp->memory->create(scratch,nscratch,"test:scratch");
strcpy(string,demo_input[0]);
lmp->input->substitute(string,scratch,nstring,nscratch,0);
EXPECT_STREQ(string,"region box block 0 2 0 2 0 2");
lmp->memory->create(string, nstring, "test:string");
lmp->memory->create(scratch, nscratch, "test:scratch");
strcpy(string, demo_input[0]);
lmp->input->substitute(string, scratch, nstring, nscratch, 0);
EXPECT_STREQ(string, "region box block 0 2 0 2 0 2");
strcpy(string,demo_input[2]);
lmp->input->substitute(string,scratch,nstring,nscratch,0);
EXPECT_STREQ(string,"create_atoms 1 single 1.0 1.0 1.5");
strcpy(string, demo_input[2]);
lmp->input->substitute(string, scratch, nstring, nscratch, 0);
EXPECT_STREQ(string, "create_atoms 1 single 1.0 1.0 1.5");
lmp->memory->destroy(string);
lmp->memory->destroy(scratch);
};
}
};
} // namespace LAMMPS_NS

View File

@ -1,8 +1,8 @@
// unit tests for the LAMMPS base class
#include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string>
#include "gmock/gmock.h"
@ -10,33 +10,29 @@
using ::testing::StartsWith;
namespace LAMMPS_NS
{
// test fixture for regular tests
class LAMMPS_plain : public ::testing::Test {
protected:
namespace LAMMPS_NS {
// test fixture for regular tests
class LAMMPS_plain : public ::testing::Test {
protected:
LAMMPS *lmp;
LAMMPS_plain() : lmp(nullptr) {
LAMMPS_plain() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
int flag;
MPI_Initialized(&flag);
if (!flag) MPI_Init(&argc,&argv);
if (!flag) MPI_Init(&argc, &argv);
}
~LAMMPS_plain() override {
lmp = nullptr;
}
~LAMMPS_plain() override { lmp = nullptr; }
void SetUp() override {
const char *args[] = {"LAMMPS_test",
"-log", "none",
"-echo", "both",
"-nocite"};
void SetUp() override
{
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "both", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout();
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
@ -44,16 +40,17 @@ namespace LAMMPS_NS
EXPECT_THAT(output, StartsWith("LAMMPS ("));
}
void TearDown() override {
void TearDown() override
{
::testing::internal::CaptureStdout();
delete lmp;
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, StartsWith("Total wall time:"));
}
};
};
TEST_F(LAMMPS_plain, InitMembers)
{
TEST_F(LAMMPS_plain, InitMembers)
{
EXPECT_NE(lmp->memory, nullptr);
EXPECT_NE(lmp->error, nullptr);
EXPECT_NE(lmp->universe, nullptr);
@ -90,112 +87,104 @@ namespace LAMMPS_NS
EXPECT_NE(lmp->python, nullptr);
EXPECT_EQ(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit,"");
EXPECT_STRNE(LAMMPS::git_branch,"");
EXPECT_STRNE(LAMMPS::git_descriptor,"");
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
} else {
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
}
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
}
}
TEST_F(LAMMPS_plain, TestStyles)
{
TEST_F(LAMMPS_plain, TestStyles)
{
// skip tests if base class is not available
if (lmp == nullptr) return;
const char *found;
const char *atom_styles[] = {
"atomic", "body", "charge", "ellipsoid", "hybrid",
"line", "sphere", "tri", NULL };
const char *atom_styles[] = {"atomic", "body", "charge", "ellipsoid", "hybrid",
"line", "sphere", "tri", NULL};
for (int i = 0; atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom",atom_styles[i]);
found = lmp->match_style("atom", atom_styles[i]);
EXPECT_STREQ(found, NULL);
}
const char *molecule_atom_styles[] = {
"angle", "bond", "full", "molecular", "template", NULL };
const char *molecule_atom_styles[] = {"angle", "bond", "full", "molecular", "template", NULL};
for (int i = 0; molecule_atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom",molecule_atom_styles[i]);
found = lmp->match_style("atom", molecule_atom_styles[i]);
EXPECT_STREQ(found, "MOLECULE");
}
const char *kokkos_atom_styles[] = {
"angle/kk", "bond/kk", "full/kk", "molecular/kk", "hybrid/kk", NULL };
const char *kokkos_atom_styles[] = {"angle/kk", "bond/kk", "full/kk",
"molecular/kk", "hybrid/kk", NULL};
for (int i = 0; kokkos_atom_styles[i] != NULL; ++i) {
found = lmp->match_style("atom",kokkos_atom_styles[i]);
found = lmp->match_style("atom", kokkos_atom_styles[i]);
EXPECT_STREQ(found, "KOKKOS");
}
found = lmp->match_style("atom","dipole");
EXPECT_STREQ(found,"DIPOLE");
found = lmp->match_style("atom","peri");
EXPECT_STREQ(found,"PERI");
found = lmp->match_style("atom","spin");
EXPECT_STREQ(found,"SPIN");
found = lmp->match_style("atom","wavepacket");
EXPECT_STREQ(found,"USER-AWPMD");
found = lmp->match_style("atom","dpd");
EXPECT_STREQ(found,"USER-DPD");
found = lmp->match_style("atom","edpd");
EXPECT_STREQ(found,"USER-MESODPD");
found = lmp->match_style("atom","mdpd");
EXPECT_STREQ(found,"USER-MESODPD");
found = lmp->match_style("atom","tdpd");
EXPECT_STREQ(found,"USER-MESODPD");
found = lmp->match_style("atom","spin");
EXPECT_STREQ(found,"SPIN");
found = lmp->match_style("atom","smd");
EXPECT_STREQ(found,"USER-SMD");
found = lmp->match_style("atom","sph");
EXPECT_STREQ(found,"USER-SPH");
found = lmp->match_style("atom","i_don't_exist");
EXPECT_STREQ(found,NULL);
}
found = lmp->match_style("atom", "dipole");
EXPECT_STREQ(found, "DIPOLE");
found = lmp->match_style("atom", "peri");
EXPECT_STREQ(found, "PERI");
found = lmp->match_style("atom", "spin");
EXPECT_STREQ(found, "SPIN");
found = lmp->match_style("atom", "wavepacket");
EXPECT_STREQ(found, "USER-AWPMD");
found = lmp->match_style("atom", "dpd");
EXPECT_STREQ(found, "USER-DPD");
found = lmp->match_style("atom", "edpd");
EXPECT_STREQ(found, "USER-MESODPD");
found = lmp->match_style("atom", "mdpd");
EXPECT_STREQ(found, "USER-MESODPD");
found = lmp->match_style("atom", "tdpd");
EXPECT_STREQ(found, "USER-MESODPD");
found = lmp->match_style("atom", "spin");
EXPECT_STREQ(found, "SPIN");
found = lmp->match_style("atom", "smd");
EXPECT_STREQ(found, "USER-SMD");
found = lmp->match_style("atom", "sph");
EXPECT_STREQ(found, "USER-SPH");
found = lmp->match_style("atom", "i_don't_exist");
EXPECT_STREQ(found, NULL);
}
// test fixture for OpenMP with 2 threads
class LAMMPS_omp : public ::testing::Test {
protected:
// test fixture for OpenMP with 2 threads
class LAMMPS_omp : public ::testing::Test {
protected:
LAMMPS *lmp;
LAMMPS_omp() : lmp(nullptr) {
LAMMPS_omp() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
int flag;
MPI_Initialized(&flag);
if (!flag) MPI_Init(&argc,&argv);
if (!flag) MPI_Init(&argc, &argv);
}
~LAMMPS_omp() override {
lmp = nullptr;
}
~LAMMPS_omp() override { lmp = nullptr; }
void SetUp() override {
const char *args[] = {"LAMMPS_test",
"-log", "none",
"-screen", "none",
"-echo", "screen",
"-pk", "omp","2", "neigh", "yes",
"-sf", "omp"
};
void SetUp() override
{
const char *args[] = {"LAMMPS_test", "-log", "none", "-screen", "none", "-echo", "screen",
"-pk", "omp", "2", "neigh", "yes", "-sf", "omp"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
// only run this test fixture with omp suffix if USER-OMP package is installed
if (LAMMPS::is_installed_pkg("USER-OMP"))
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
else GTEST_SKIP();
else
GTEST_SKIP();
}
void TearDown() override {
delete lmp;
}
};
void TearDown() override { delete lmp; }
};
TEST_F(LAMMPS_omp, InitMembers)
{
TEST_F(LAMMPS_omp, InitMembers)
{
EXPECT_NE(lmp->memory, nullptr);
EXPECT_NE(lmp->error, nullptr);
EXPECT_NE(lmp->universe, nullptr);
@ -232,44 +221,39 @@ namespace LAMMPS_NS
EXPECT_NE(lmp->python, nullptr);
EXPECT_NE(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit,"");
EXPECT_STRNE(LAMMPS::git_branch,"");
EXPECT_STRNE(LAMMPS::git_descriptor,"");
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
} else {
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
}
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
}
}
// test fixture for Kokkos tests
class LAMMPS_kokkos : public ::testing::Test {
protected:
// test fixture for Kokkos tests
class LAMMPS_kokkos : public ::testing::Test {
protected:
LAMMPS *lmp;
LAMMPS_kokkos() : lmp(nullptr) {
LAMMPS_kokkos() : lmp(nullptr)
{
const char *args[] = {"LAMMPS_test"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
int flag;
MPI_Initialized(&flag);
if (!flag) MPI_Init(&argc,&argv);
if (!flag) MPI_Init(&argc, &argv);
}
~LAMMPS_kokkos() override {
lmp = nullptr;
}
~LAMMPS_kokkos() override { lmp = nullptr; }
void SetUp() override {
const char *args[] = {"LAMMPS_test",
"-log", "none",
"-echo", "none",
"-screen", "none",
"-k", "on","t", "2",
"-sf", "kk"
};
void SetUp() override
{
const char *args[] = {"LAMMPS_test", "-log", "none", "-echo", "none", "-screen", "none",
"-k", "on", "t", "2", "-sf", "kk"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
// only run this test fixture with kk suffix if KOKKOS package is installed
// also need to figure out a way to find which parallelizations are enabled
@ -279,16 +263,15 @@ namespace LAMMPS_NS
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_THAT(output, StartsWith("Kokkos::OpenMP::"));
} else GTEST_SKIP();
} else
GTEST_SKIP();
}
void TearDown() override {
delete lmp;
}
};
void TearDown() override { delete lmp; }
};
TEST_F(LAMMPS_kokkos, InitMembers)
{
TEST_F(LAMMPS_kokkos, InitMembers)
{
EXPECT_NE(lmp->memory, nullptr);
EXPECT_NE(lmp->error, nullptr);
EXPECT_NE(lmp->universe, nullptr);
@ -325,21 +308,22 @@ namespace LAMMPS_NS
EXPECT_NE(lmp->python, nullptr);
EXPECT_NE(lmp->citeme, nullptr);
if (LAMMPS::has_git_info) {
EXPECT_STRNE(LAMMPS::git_commit,"");
EXPECT_STRNE(LAMMPS::git_branch,"");
EXPECT_STRNE(LAMMPS::git_descriptor,"");
EXPECT_STRNE(LAMMPS::git_commit, "");
EXPECT_STRNE(LAMMPS::git_branch, "");
EXPECT_STRNE(LAMMPS::git_descriptor, "");
} else {
EXPECT_STREQ(LAMMPS::git_commit,"(unknown)");
EXPECT_STREQ(LAMMPS::git_branch,"(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor,"(unknown)");
}
EXPECT_STREQ(LAMMPS::git_commit, "(unknown)");
EXPECT_STREQ(LAMMPS::git_branch, "(unknown)");
EXPECT_STREQ(LAMMPS::git_descriptor, "(unknown)");
}
}
// check help message printing
TEST(LAMMPS_help, HelpMessage) {
// check help message printing
TEST(LAMMPS_help, HelpMessage)
{
const char *args[] = {"LAMMPS_test", "-h"};
char **argv = (char **)args;
int argc = sizeof(args)/sizeof(char *);
int argc = sizeof(args) / sizeof(char *);
::testing::internal::CaptureStdout();
LAMMPS *lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
@ -347,5 +331,5 @@ namespace LAMMPS_NS
EXPECT_THAT(output,
StartsWith("\nLarge-scale Atomic/Molecular Massively Parallel Simulator -"));
delete lmp;
}
}
} // namespace LAMMPS_NS

View File

@ -519,8 +519,8 @@ TEST(FixTimestep, plain)
// rigid fixes need work to test properly with r-RESPA.
// fix nve/limit cannot work with r-RESPA
ifix = lmp->modify->find_fix("test");
if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid")
&& !utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) {
if (!utils::strmatch(lmp->modify->fix[ifix]->style, "^rigid") &&
!utils::strmatch(lmp->modify->fix[ifix]->style, "^nve/limit")) {
if (!verbose) ::testing::internal::CaptureStdout();
cleanup_lammps(lmp, test_config);

View File

@ -12,9 +12,9 @@
------------------------------------------------------------------------- */
#include "test_main.h"
#include "pointers.h"
#include "test_config.h"
#include "test_config_reader.h"
#include "pointers.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

View File

@ -209,7 +209,6 @@ struct AtomState {
int eff_plastic_strain_rate_flag = 0;
double pdscale = 1.0;
int maxspecial = 1;
int nmolecule = 0;
@ -258,7 +257,8 @@ struct AtomState {
ASSERT_EQ(ptr, nullptr); \
}
void ASSERT_ATOM_STATE_EQ(Atom* atom, const AtomState& expected) {
void ASSERT_ATOM_STATE_EQ(Atom *atom, const AtomState &expected)
{
ASSERT_THAT(std::string(atom->atom_style), Eq(expected.atom_style));
ASSERT_NE(atom->avec, nullptr);
@ -3407,7 +3407,6 @@ TEST_F(AtomStyleTest, template_charge)
ASSERT_EQ(lmp->atom->tag_consecutive(), 1);
ASSERT_EQ(lmp->atom->map_tag_max, 16);
type = lmp->atom->type;
molecule = lmp->atom->molecule;
molindex = lmp->atom->molindex;

View File

@ -11,30 +11,33 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
using ::testing::Eq;
char * BINARY2TXT_BINARY = nullptr;
char *BINARY2TXT_BINARY = nullptr;
class DumpAtomTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,9 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", dump_style, binary_file));
@ -60,7 +65,8 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_binary_to_text(std::string binary_file) {
std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
@ -290,7 +296,7 @@ TEST_F(DumpAtomTest, triclinic_with_image_run0)
TEST_F(DumpAtomTest, binary_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_run0.melt";
auto binary_file = "dump_binary_run0.melt.bin";
@ -311,7 +317,7 @@ TEST_F(DumpAtomTest, binary_run0)
TEST_F(DumpAtomTest, binary_with_units_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_with_units_run0.melt";
auto binary_file = "dump_binary_with_units_run0.melt.bin";
@ -332,7 +338,7 @@ TEST_F(DumpAtomTest, binary_with_units_run0)
TEST_F(DumpAtomTest, binary_with_time_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_with_time_run0.melt";
auto binary_file = "dump_binary_with_time_run0.melt.bin";
@ -353,7 +359,7 @@ TEST_F(DumpAtomTest, binary_with_time_run0)
TEST_F(DumpAtomTest, binary_triclinic_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_tri_run0.melt";
auto binary_file = "dump_binary_tri_run0.melt.bin";
@ -375,7 +381,7 @@ TEST_F(DumpAtomTest, binary_triclinic_run0)
TEST_F(DumpAtomTest, binary_triclinic_with_units_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_tri_with_units_run0.melt";
auto binary_file = "dump_binary_tri_with_units_run0.melt.bin";
@ -397,7 +403,7 @@ TEST_F(DumpAtomTest, binary_triclinic_with_units_run0)
TEST_F(DumpAtomTest, binary_triclinic_with_time_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_tri_with_time_run0.melt";
auto binary_file = "dump_binary_tri_with_time_run0.melt.bin";
@ -419,7 +425,7 @@ TEST_F(DumpAtomTest, binary_triclinic_with_time_run0)
TEST_F(DumpAtomTest, binary_triclinic_with_image_run0)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_text_tri_with_image_run0.melt";
auto binary_file = "dump_binary_tri_with_image_run0.melt.bin";
@ -501,8 +507,7 @@ TEST_F(DumpAtomTest, dump_modify_scale_invalid)
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*",
command("dump_modify id scale true"););
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id scale true"););
}
TEST_F(DumpAtomTest, dump_modify_image_invalid)
@ -511,8 +516,7 @@ TEST_F(DumpAtomTest, dump_modify_image_invalid)
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*",
command("dump_modify id image true"););
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id image true"););
}
TEST_F(DumpAtomTest, dump_modify_invalid)
@ -521,8 +525,7 @@ TEST_F(DumpAtomTest, dump_modify_invalid)
command("dump id all atom 1 dump.txt");
if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Illegal dump_modify command.*",
command("dump_modify id true"););
TEST_FAILURE(".*Illegal dump_modify command.*", command("dump_modify id true"););
}
TEST_F(DumpAtomTest, write_dump)
@ -547,7 +550,7 @@ TEST_F(DumpAtomTest, write_dump)
TEST_F(DumpAtomTest, binary_write_dump)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto reference = "dump_run0.melt.bin";
auto dump_file = "write_dump_atom_run0_p0.melt.bin";

View File

@ -11,30 +11,33 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
char * GZIP_BINARY = nullptr;
char *GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpAtomGZTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -60,24 +66,25 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
//-------------------------------------------------------------------------------------------------
// GZ compressed files
//-------------------------------------------------------------------------------------------------
TEST_F(DumpAtomGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_run0.melt";
auto compressed_file = "dump_gz_compressed_run0.melt.gz";
@ -101,12 +108,13 @@ TEST_F(DumpAtomGZTest, compressed_run0)
TEST_F(DumpAtomGZTest, compressed_with_units_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_with_units_run0.melt";
auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes",
0);
TearDown();
@ -124,12 +132,13 @@ TEST_F(DumpAtomGZTest, compressed_with_units_run0)
TEST_F(DumpAtomGZTest, compressed_with_time_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_with_time_run0.melt";
auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes",
0);
TearDown();
@ -147,7 +156,7 @@ TEST_F(DumpAtomGZTest, compressed_with_time_run0)
TEST_F(DumpAtomGZTest, compressed_triclinic_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz";
@ -171,13 +180,14 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_run0)
TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_units_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes",
0);
TearDown();
@ -195,13 +205,14 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0)
TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_time_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes",
0);
TearDown();
@ -219,7 +230,7 @@ TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0)
TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_gz_text_tri_with_image_run0.melt";
auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz";

View File

@ -11,30 +11,33 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <string>
char * ZSTD_BINARY = nullptr;
char *ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpAtomZSTDTest : public MeltTest {
std::string dump_style = "atom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {}", dump_style, dump_file));
@ -46,7 +49,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -60,24 +66,25 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
}
};
//-------------------------------------------------------------------------------------------------
// ZSTD compressed files
//-------------------------------------------------------------------------------------------------
TEST_F(DumpAtomZSTDTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_run0.melt";
auto compressed_file = "dump_zstd_compressed_run0.melt.zst";
@ -102,12 +109,13 @@ TEST_F(DumpAtomZSTDTest, compressed_run0)
TEST_F(DumpAtomZSTDTest, compressed_with_units_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_with_units_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes",
0);
// make sure file is closed
TearDown();
@ -126,12 +134,13 @@ TEST_F(DumpAtomZSTDTest, compressed_with_units_run0)
TEST_F(DumpAtomZSTDTest, compressed_with_time_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_with_time_run0.melt";
auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst";
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes",
0);
// make sure file is closed
TearDown();
@ -150,7 +159,7 @@ TEST_F(DumpAtomZSTDTest, compressed_with_time_run0)
TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst";
@ -175,13 +184,14 @@ TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0)
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_units_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes",
0);
// make sure file is closed
TearDown();
@ -200,13 +210,14 @@ TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0)
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_time_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst";
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", 0);
generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes",
0);
// make sure file is closed
TearDown();
@ -225,7 +236,7 @@ TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0)
TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_zstd_text_tri_with_image_run0.melt";
auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst";

View File

@ -11,20 +11,23 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq;
class DumpCfgTest : public MeltTest {
std::string dump_style = "cfg";
public:
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -40,22 +43,20 @@ public:
TEST_F(DumpCfgTest, invalid_options)
{
TEST_FAILURE(".*Dump cfg arguments must start with 'mass type xs ys zs'.*",
command("dump id all cfg 1 dump.cfg id type proc procp1 mass x y z");
);
command("dump id all cfg 1 dump.cfg id type proc procp1 mass x y z"););
}
TEST_F(DumpCfgTest, require_multifile)
{
auto dump_file = "dump.melt.cfg_run.cfg";
auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
auto fields =
"mass type xs ys zs id proc procp1 x y z ix iy iz xu yu zu xsu ysu zsu vx vy vz fx fy fz";
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all cfg 1 {} {}", dump_file, fields));
if (!verbose) ::testing::internal::GetCapturedStdout();
TEST_FAILURE(".*Dump cfg requires one snapshot per file.*",
command("run 0");
);
TEST_FAILURE(".*Dump cfg requires one snapshot per file.*", command("run 0"););
}
TEST_F(DumpCfgTest, run0)
@ -114,7 +115,6 @@ TEST_F(DumpCfgTest, no_unwrap_no_buffer_run0)
delete_file("dump_cfg_no_unwrap_no_buffer_run0.melt.cfg");
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * GZIP_BINARY = nullptr;
char *GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpCfgGZTest : public MeltTest {
std::string dump_style = "cfg";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpCfgGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_gz_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz";
@ -77,10 +82,9 @@ TEST_F(DumpCfgGZTest, compressed_run0)
delete_file(converted_file);
}
TEST_F(DumpCfgGZTest, compressed_unwrap_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz";

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * ZSTD_BINARY = nullptr;
char *ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpCfgZstdTest : public MeltTest {
std::string dump_style = "cfg";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpCfgZstdTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_zstd_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst";
@ -77,10 +82,9 @@ TEST_F(DumpCfgZstdTest, compressed_run0)
delete_file(converted_file);
}
TEST_F(DumpCfgZstdTest, compressed_unwrap_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg";
auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst";

View File

@ -11,28 +11,32 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq;
char * BINARY2TXT_BINARY = nullptr;
char *BINARY2TXT_BINARY = nullptr;
class DumpCustomTest : public MeltTest {
std::string dump_style = "custom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_binary_dump(std::string text_file, std::string binary_file, std::string fields,
std::string dump_modify_options, int ntimesteps) {
void generate_text_and_binary_dump(std::string text_file, std::string binary_file,
std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", dump_style, binary_file, fields));
@ -59,7 +65,8 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_binary_to_text(std::string binary_file) {
std::string convert_binary_to_text(std::string binary_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string cmdline = fmt::format("{} {}", BINARY2TXT_BINARY, binary_file);
system(cmdline.c_str());
@ -71,7 +78,8 @@ public:
TEST_F(DumpCustomTest, run1)
{
auto dump_file = "dump_custom_run1.melt";
auto fields = "id type proc procp1 mass x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
auto fields =
"id type proc procp1 mass x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_dump(dump_file, fields, "units yes", 1);
@ -168,7 +176,7 @@ TEST_F(DumpCustomTest, custom_run0)
TEST_F(DumpCustomTest, binary_run1)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_text_run1.melt";
auto binary_file = "dump_custom_binary_run1.melt.bin";
@ -209,7 +217,7 @@ TEST_F(DumpCustomTest, triclinic_run1)
TEST_F(DumpCustomTest, binary_triclinic_run1)
{
if(!BINARY2TXT_BINARY) GTEST_SKIP();
if (!BINARY2TXT_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_tri_text_run1.melt";
auto binary_file = "dump_custom_tri_binary_run1.melt.bin";
@ -253,7 +261,6 @@ TEST_F(DumpCustomTest, with_variable_run1)
delete_file(dump_file);
}
int main(int argc, char **argv)
{
MPI_Init(&argc, &argv);

View File

@ -11,28 +11,32 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq;
char * GZIP_BINARY = nullptr;
char *GZIP_BINARY = nullptr;
class DumpCustomGZTest : public MeltTest {
std::string dump_style = "custom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -59,10 +65,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -71,13 +79,14 @@ public:
TEST_F(DumpCustomGZTest, compressed_run1)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_gz_text_run1.melt";
auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes",
1);
TearDown();
@ -95,7 +104,7 @@ TEST_F(DumpCustomGZTest, compressed_run1)
TEST_F(DumpCustomGZTest, compressed_triclinic_run1)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_gz_tri_text_run1.melt";
auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz";
@ -103,7 +112,8 @@ TEST_F(DumpCustomGZTest, compressed_triclinic_run1)
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", 1);
generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes",
1);
TearDown();

View File

@ -11,28 +11,32 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
using ::testing::Eq;
char * ZSTD_BINARY = nullptr;
char *ZSTD_BINARY = nullptr;
class DumpCustomZstdTest : public MeltTest {
std::string dump_style = "custom";
public:
void enable_triclinic() {
void enable_triclinic()
{
if (!verbose) ::testing::internal::CaptureStdout();
command("change_box all triclinic");
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options,
int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields));
@ -44,8 +48,10 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -59,10 +65,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -71,13 +79,14 @@ public:
TEST_F(DumpCustomZstdTest, compressed_run1)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_zstd_text_run1.melt";
auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst";
auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz";
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields,
"units yes", 1);
TearDown();
@ -95,7 +104,7 @@ TEST_F(DumpCustomZstdTest, compressed_run1)
TEST_F(DumpCustomZstdTest, compressed_triclinic_run1)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_file = "dump_custom_zstd_tri_text_run1.melt";
auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst";
@ -103,7 +112,8 @@ TEST_F(DumpCustomZstdTest, compressed_triclinic_run1)
enable_triclinic();
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, "units yes", 1);
generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields,
"units yes", 1);
TearDown();

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * GZIP_BINARY = nullptr;
char *GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpLocalGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("compute comp all pair/local dist eng");

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * ZSTD_BINARY = nullptr;
char *ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpLocalGZTest : public MeltTest {
std::string dump_style = "local";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string fields, std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style, std::string fields,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields));
command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpLocalGZTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
command("compute comp all pair/local dist eng");

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * GZIP_BINARY = nullptr;
char *GZIP_BINARY = nullptr;
using ::testing::Eq;
class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpXYZGZTest, compressed_run0)
{
if(!GZIP_BINARY) GTEST_SKIP();
if (!GZIP_BINARY) GTEST_SKIP();
auto text_files = "dump_xyz_gz_text_run*.melt.xyz";
auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz";

View File

@ -11,23 +11,26 @@
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "fmt/format.h"
#include "utils.h"
#include "../testing/core.h"
#include "../testing/systems/melt.h"
#include "../testing/utils.h"
#include "fmt/format.h"
#include "utils.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
char * ZSTD_BINARY = nullptr;
char *ZSTD_BINARY = nullptr;
using ::testing::Eq;
class DumpXYZGZTest : public MeltTest {
std::string dump_style = "xyz";
public:
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, std::string compression_style,
std::string dump_modify_options, int ntimesteps) {
void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file,
std::string compression_style,
std::string dump_modify_options, int ntimesteps)
{
if (!verbose) ::testing::internal::CaptureStdout();
command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file));
command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file));
@ -41,10 +44,12 @@ public:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
std::string convert_compressed_to_text(std::string compressed_file) {
std::string convert_compressed_to_text(std::string compressed_file)
{
if (!verbose) ::testing::internal::CaptureStdout();
std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.'));
std::string cmdline = fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
std::string cmdline =
fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file);
system(cmdline.c_str());
if (!verbose) ::testing::internal::GetCapturedStdout();
return converted_file;
@ -53,7 +58,7 @@ public:
TEST_F(DumpXYZGZTest, compressed_run0)
{
if(!ZSTD_BINARY) GTEST_SKIP();
if (!ZSTD_BINARY) GTEST_SKIP();
auto text_files = "dump_xyz_zstd_text_run*.melt.xyz";
auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst";

View File

@ -650,15 +650,14 @@ TEST_F(PairUnitConvertTest, table_real2metal)
double pnew;
lmp->output->thermo->evaluate_keyword("press", &pnew);
EXPECT_NEAR(pold, 1.0/p_convert * pnew, fabs(pnew * rel_error));
EXPECT_NEAR(pold, 1.0 / p_convert * pnew, fabs(pnew * rel_error));
double enew = lmp->force->pair->eng_vdwl + lmp->force->pair->eng_coul;
EXPECT_NEAR(1.0/ev_convert * eold, enew, fabs(enew * rel_error));
EXPECT_NEAR(1.0 / ev_convert * eold, enew, fabs(enew * rel_error));
f = lmp->atom->f;
for (int i = 0; i < 4; ++i)
for (int j = 0; j < 3; ++j)
EXPECT_NEAR(1.0/ev_convert * fold[i][j], f[i][j],
fabs(f[i][j] * rel_error));
EXPECT_NEAR(1.0 / ev_convert * fold[i][j], f[i][j], fabs(f[i][j] * rel_error));
}
TEST_F(PairUnitConvertTest, tersoff)

View File

@ -31,8 +31,8 @@
#include <cstring>
#include <iostream>
#include <vector>
#include <mpi.h>
#include <vector>
#if defined(OMPI_MAJOR_VERSION)
const bool have_openmpi = true;

View File

@ -1,65 +1,70 @@
// unit tests for issuing command to a LAMMPS instance through the Fortran wrapper
#include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string>
#include "gtest/gtest.h"
// prototypes for fortran reverse wrapper functions
extern "C" {
void *f_lammps_with_args();
void f_lammps_close();
void f_lammps_file();
void f_lammps_command();
void f_lammps_commands_list();
void f_lammps_commands_string();
double f_lammps_get_natoms();
void *f_lammps_with_args();
void f_lammps_close();
void f_lammps_file();
void f_lammps_command();
void f_lammps_commands_list();
void f_lammps_commands_string();
double f_lammps_get_natoms();
}
class LAMMPS_commands : public ::testing::Test
{
class LAMMPS_commands : public ::testing::Test {
protected:
LAMMPS_NS::LAMMPS *lmp;
LAMMPS_commands() {};
~LAMMPS_commands() override {};
LAMMPS_commands(){};
~LAMMPS_commands() override{};
void SetUp() override {
void SetUp() override
{
::testing::internal::CaptureStdout();
lmp = (LAMMPS_NS::LAMMPS *)f_lammps_with_args();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,8).c_str(), "LAMMPS (");
EXPECT_STREQ(output.substr(0, 8).c_str(), "LAMMPS (");
}
void TearDown() override {
void TearDown() override
{
::testing::internal::CaptureStdout();
f_lammps_close();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
lmp = nullptr;
}
};
TEST_F(LAMMPS_commands, from_file) {
EXPECT_EQ(f_lammps_get_natoms(),0);
TEST_F(LAMMPS_commands, from_file)
{
EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_file();
EXPECT_EQ(f_lammps_get_natoms(),2);
EXPECT_EQ(f_lammps_get_natoms(), 2);
};
TEST_F(LAMMPS_commands, from_line) {
EXPECT_EQ(f_lammps_get_natoms(),0);
TEST_F(LAMMPS_commands, from_line)
{
EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_command();
EXPECT_EQ(f_lammps_get_natoms(),1);
EXPECT_EQ(f_lammps_get_natoms(), 1);
};
TEST_F(LAMMPS_commands, from_list) {
EXPECT_EQ(f_lammps_get_natoms(),0);
TEST_F(LAMMPS_commands, from_list)
{
EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_commands_list();
EXPECT_EQ(f_lammps_get_natoms(),2);
EXPECT_EQ(f_lammps_get_natoms(), 2);
};
TEST_F(LAMMPS_commands, from_string) {
EXPECT_EQ(f_lammps_get_natoms(),0);
TEST_F(LAMMPS_commands, from_string)
{
EXPECT_EQ(f_lammps_get_natoms(), 0);
f_lammps_commands_string();
EXPECT_EQ(f_lammps_get_natoms(),2);
EXPECT_EQ(f_lammps_get_natoms(), 2);
};

View File

@ -1,33 +1,34 @@
// unit tests for the LAMMPS base class
#include "lammps.h"
#include <mpi.h>
#include <cstdio> // for stdin, stdout
#include <mpi.h>
#include <string>
#include "gtest/gtest.h"
// prototypes for fortran reverse wrapper functions
extern "C" {
void *f_lammps_open_no_args();
void *f_lammps_open_with_args();
void *f_lammps_no_mpi_no_args();
void *f_lammps_no_mpi_with_args();
void f_lammps_close();
int f_lammps_get_comm();
void *f_lammps_open_no_args();
void *f_lammps_open_with_args();
void *f_lammps_no_mpi_no_args();
void *f_lammps_no_mpi_with_args();
void f_lammps_close();
int f_lammps_get_comm();
}
TEST(open_no_mpi, no_args) {
TEST(open_no_mpi, no_args)
{
::testing::internal::CaptureStdout();
int mpi_init=0;
int mpi_init = 0;
MPI_Initialized(&mpi_init);
EXPECT_EQ(mpi_init,0);
EXPECT_EQ(mpi_init, 0);
void *handle = f_lammps_no_mpi_no_args();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
EXPECT_STREQ(output.substr(0, 6).c_str(), "LAMMPS");
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
MPI_Initialized(&mpi_init);
EXPECT_NE(mpi_init,0);
EXPECT_NE(mpi_init, 0);
EXPECT_EQ(lmp->world, MPI_COMM_WORLD);
EXPECT_EQ(lmp->infile, stdin);
EXPECT_EQ(lmp->screen, stdout);
@ -35,14 +36,15 @@ TEST(open_no_mpi, no_args) {
::testing::internal::CaptureStdout();
f_lammps_close();
output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
}
TEST(open_no_mpi, with_args) {
TEST(open_no_mpi, with_args)
{
::testing::internal::CaptureStdout();
void *handle = f_lammps_no_mpi_with_args();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
EXPECT_STREQ(output.substr(0, 6).c_str(), "LAMMPS");
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
EXPECT_EQ(lmp->infile, stdin);
EXPECT_EQ(lmp->screen, stdout);
@ -53,14 +55,15 @@ TEST(open_no_mpi, with_args) {
::testing::internal::CaptureStdout();
f_lammps_close();
output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
}
TEST(fortran_open, no_args) {
TEST(fortran_open, no_args)
{
::testing::internal::CaptureStdout();
void *handle = f_lammps_open_no_args();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
EXPECT_STREQ(output.substr(0, 6).c_str(), "LAMMPS");
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
int f_comm = f_lammps_get_comm();
@ -72,14 +75,15 @@ TEST(fortran_open, no_args) {
::testing::internal::CaptureStdout();
f_lammps_close();
output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
}
TEST(fortran_open, with_args) {
TEST(fortran_open, with_args)
{
::testing::internal::CaptureStdout();
void *handle = f_lammps_open_with_args();
std::string output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,6).c_str(),"LAMMPS");
EXPECT_STREQ(output.substr(0, 6).c_str(), "LAMMPS");
LAMMPS_NS::LAMMPS *lmp = (LAMMPS_NS::LAMMPS *)handle;
int f_comm = f_lammps_get_comm();
@ -93,5 +97,5 @@ TEST(fortran_open, with_args) {
::testing::internal::CaptureStdout();
f_lammps_close();
output = ::testing::internal::GetCapturedStdout();
EXPECT_STREQ(output.substr(0,16).c_str(), "Total wall time:");
EXPECT_STREQ(output.substr(0, 16).c_str(), "Total wall time:");
}

View File

@ -32,8 +32,8 @@ bool verbose = false;
using LAMMPS_NS::utils::split_words;
namespace LAMMPS_NS {
using ::testing::StrEq;
using ::testing::MatchesRegex;
using ::testing::StrEq;
class PythonPackageTest : public ::testing::Test {
protected:
@ -74,7 +74,7 @@ protected:
TEST_F(PythonPackageTest, python_invoke)
{
if (!info->has_style("command","python")) GTEST_SKIP();
if (!info->has_style("command", "python")) GTEST_SKIP();
// execute python function from file
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("python printnum file ${input_dir}/func.py");
@ -107,9 +107,9 @@ TEST_F(PythonPackageTest, python_invoke)
ASSERT_THAT(output, MatchesRegex("python.*2.25.*"));
}
TEST_F(PythonPackageTest, python_variable)
TEST_F(PythonPackageTest, python_variable)
{
if (!info->has_style("command","python")) GTEST_SKIP();
if (!info->has_style("command", "python")) GTEST_SKIP();
if (!verbose) ::testing::internal::CaptureStdout();
lmp->input->one("variable sq python square");
lmp->input->one("variable val index 1.5");

View File

@ -41,20 +41,17 @@ using ::testing::MatchesRegex;
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
bool verbose = false;
class LAMMPSTest : public ::testing::Test {
public:
void command(const std::string &line) {
lmp->input->one(line.c_str());
}
void command(const std::string &line) { lmp->input->one(line.c_str()); }
protected:
const char * testbinary = "LAMMPSTest";
const char *testbinary = "LAMMPSTest";
LAMMPS *lmp;
void SetUp() override
{
const char *args[] = { testbinary, "-log", "none", "-echo", "screen", "-nocite"};
const char *args[] = {testbinary, "-log", "none", "-echo", "screen", "-nocite"};
char **argv = (char **)args;
int argc = sizeof(args) / sizeof(char *);
if (!verbose) ::testing::internal::CaptureStdout();
@ -63,9 +60,7 @@ protected:
if (!verbose) ::testing::internal::GetCapturedStdout();
}
virtual void InitSystem() {
}
virtual void InitSystem() {}
void TearDown() override
{
@ -76,5 +71,4 @@ protected:
}
};
#endif

View File

@ -17,7 +17,8 @@
class MeltTest : public LAMMPSTest {
protected:
virtual void InitSystem() override {
virtual void InitSystem() override
{
command("units lj");
command("atom_style atomic");
command("atom_modify map yes");

View File

@ -13,12 +13,12 @@
#ifndef TEST_EXTENSIONS__H
#define TEST_EXTENSIONS__H
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <sys/types.h>
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
static void delete_file(const std::string &filename)
{
@ -44,14 +44,15 @@ static bool equal_lines(const std::string &fileA, const std::string &fileB)
std::string lineA, lineB;
while (std::getline(afile, lineA)) {
if(!std::getline(bfile, lineB)) return false;
if(lineA != lineB) return false;
if (!std::getline(bfile, lineB)) return false;
if (lineA != lineB) return false;
}
return true;
}
static std::vector<std::string> read_lines(const std::string &filename) {
static std::vector<std::string> read_lines(const std::string &filename)
{
std::vector<std::string> lines;
std::ifstream infile(filename);
std::string line;
@ -62,7 +63,8 @@ static std::vector<std::string> read_lines(const std::string &filename) {
return lines;
}
static bool file_exists(const std::string &filename) {
static bool file_exists(const std::string &filename)
{
struct stat result;
return stat(filename.c_str(), &result) == 0;
}

View File

@ -1,94 +1,81 @@
// THIS FILE USED TO BE EASY TO READ until I added "#if defined" statements.
// (They were added to test for many different kinds of array formats.)
#include <iostream>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <chrono>
#include <random>
#include <algorithm>
#include <vector>
#include <array>
#include "math_eigen_impl.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
using std::cout;
using std::array;
using std::cerr;
using std::cout;
using std::endl;
using std::setprecision;
using std::vector;
using std::array;
using namespace MathEigen;
// This code works with various types of C++ matrices (for example,
// double **, vector<vector<double>> array<array<double,5>,5>).
// I use "#if defined" statements to test different matrix types.
// For some of these (eg. array<array<double,5>,5>), the size of the matrix
// must be known at compile time. I specify that size now.
#if defined USE_ARRAY_OF_ARRAYS
const int NF=5; //(the array size must be known at compile time)
const int NF = 5; //(the array size must be known at compile time)
#elif defined USE_C_FIXED_SIZE_ARRAYS
const int NF=5; //(the array size must be known at compile time)
const int NF = 5; //(the array size must be known at compile time)
#endif
// @brief Are two numbers "similar"?
template<typename Scalar>
inline static bool Similar(Scalar a, Scalar b,
Scalar eps=1.0e-06,
Scalar ratio=1.0e-06,
Scalar ratio_denom=1.0)
template <typename Scalar>
inline static bool Similar(Scalar a, Scalar b, Scalar eps = 1.0e-06, Scalar ratio = 1.0e-06,
Scalar ratio_denom = 1.0)
{
return ((std::abs(a-b)<=std::abs(eps))
||
(std::abs(ratio_denom)*std::abs(a-b)
<=
std::abs(ratio)*0.5*(std::abs(a)+std::abs(b))));
return ((std::abs(a - b) <= std::abs(eps)) ||
(std::abs(ratio_denom) * std::abs(a - b) <=
std::abs(ratio) * 0.5 * (std::abs(a) + std::abs(b))));
}
/// @brief Are two vectors (containing n numbers) similar?
template<typename Scalar, typename Vector>
inline static bool SimilarVec(Vector a, Vector b, int n,
Scalar eps=1.0e-06,
Scalar ratio=1.0e-06,
Scalar ratio_denom=1.0)
template <typename Scalar, typename Vector>
inline static bool SimilarVec(Vector a, Vector b, int n, Scalar eps = 1.0e-06,
Scalar ratio = 1.0e-06, Scalar ratio_denom = 1.0)
{
for (int i = 0; i < n; i++)
if (not Similar(a[i], b[i], eps, ratio, ratio_denom))
return false;
if (not Similar(a[i], b[i], eps, ratio, ratio_denom)) return false;
return true;
}
/// @brief Are two vectors (or their reflections) similar?
template<typename Scalar, typename Vector>
inline static bool SimilarVecUnsigned(Vector a, Vector b, int n,
Scalar eps=1.0e-06,
Scalar ratio=1.0e-06,
Scalar ratio_denom=1.0)
template <typename Scalar, typename Vector>
inline static bool SimilarVecUnsigned(Vector a, Vector b, int n, Scalar eps = 1.0e-06,
Scalar ratio = 1.0e-06, Scalar ratio_denom = 1.0)
{
if (SimilarVec(a, b, n, eps))
return true;
else {
for (int i = 0; i < n; i++)
if (not Similar(a[i], -b[i], eps, ratio, ratio_denom))
return false;
if (not Similar(a[i], -b[i], eps, ratio, ratio_denom)) return false;
return true;
}
}
/// @brief Multiply two matrices A and B, store the result in C. (C = AB).
template<typename Matrix, typename ConstMatrix>
template <typename Matrix, typename ConstMatrix>
void mmult(ConstMatrix A, //<! input array
ConstMatrix B, //<! input array
Matrix C, //<! store result here
int m, //<! number of rows of A
int n=0, //<! optional: number of columns of B (=m by default)
int K=0 //<! optional: number of columns of A = num rows of B (=m by default)
)
int n = 0, //<! optional: number of columns of B (=m by default)
int K = 0 //<! optional: number of columns of A = num rows of B (=m by default)
)
{
if (n == 0) n = m; // if not specified, then assume the matrices are square
if (K == 0) K = m; // if not specified, then assume the matrices are square
@ -104,37 +91,25 @@ void mmult(ConstMatrix A, //<! input array
C[i][j] += A[i][k] * B[k][j];
}
/// @brief
///Sort the rows of a matrix "evec" by the numbers contained in "eval"
/// Sort the rows of a matrix "evec" by the numbers contained in "eval"
///(This is a simple O(n^2) sorting method, but O(n^2) is a lower bound anyway.)
///This is the same as the Jacobi::SortRows(), but that function is private.
template<typename Scalar, typename Vector, typename Matrix>
void
SortRows(Vector eval,
Matrix evec,
int n,
bool sort_decreasing=true,
bool sort_abs=false)
/// This is the same as the Jacobi::SortRows(), but that function is private.
template <typename Scalar, typename Vector, typename Matrix>
void SortRows(Vector eval, Matrix evec, int n, bool sort_decreasing = true, bool sort_abs = false)
{
for (int i = 0; i < n-1; i++) {
for (int i = 0; i < n - 1; i++) {
int i_max = i;
for (int j = i+1; j < n; j++) {
for (int j = i + 1; j < n; j++) {
if (sort_decreasing) {
if (sort_abs) { //sort by absolute value?
if (std::abs(eval[j]) > std::abs(eval[i_max]))
if (sort_abs) { // sort by absolute value?
if (std::abs(eval[j]) > std::abs(eval[i_max])) i_max = j;
} else if (eval[j] > eval[i_max])
i_max = j;
}
else if (eval[j] > eval[i_max])
i_max = j;
}
else {
if (sort_abs) { //sort by absolute value?
if (std::abs(eval[j]) < std::abs(eval[i_max]))
i_max = j;
}
else if (eval[j] < eval[i_max])
} else {
if (sort_abs) { // sort by absolute value?
if (std::abs(eval[j]) < std::abs(eval[i_max])) i_max = j;
} else if (eval[j] < eval[i_max])
i_max = j;
}
}
@ -144,16 +119,12 @@ SortRows(Vector eval,
}
}
/// @brief Generate a random orthonormal n x n matrix
template<typename Scalar, typename Matrix>
void GenRandOrth(Matrix R,
int n,
std::default_random_engine &rand_generator)
template <typename Scalar, typename Matrix>
void GenRandOrth(Matrix R, int n, std::default_random_engine &rand_generator)
{
std::normal_distribution<Scalar> gaussian_distribution(0,1);
std::normal_distribution<Scalar> gaussian_distribution(0, 1);
std::vector<Scalar> v(n);
for (int i = 0; i < n; i++) {
@ -166,8 +137,8 @@ void GenRandOrth(Matrix R,
for (int j = 0; j < n; j++)
v[j] = gaussian_distribution(rand_generator);
//Now subtract from v, the projection of v onto the first i-1 rows of R.
//This will produce a vector which is orthogonal to these i-1 row-vectors.
// Now subtract from v, the projection of v onto the first i-1 rows of R.
// This will produce a vector which is orthogonal to these i-1 row-vectors.
//(They are already normalized and orthogonal to each other.)
for (int k = 0; k < i; k++) {
Scalar v_dot_Rk = 0.0;
@ -179,7 +150,7 @@ void GenRandOrth(Matrix R,
// check if it is linearly independent of the other vectors and non-zero
rsq = 0.0;
for (int j = 0; j < n; j++)
rsq += v[j]*v[j];
rsq += v[j] * v[j];
}
// Now normalize the vector
Scalar r_inv = 1.0 / std::sqrt(rsq);
@ -188,10 +159,8 @@ void GenRandOrth(Matrix R,
// Now copy this vector to the i'th row of R
for (int j = 0; j < n; j++)
R[i][j] = v[j];
} //for (int i = 0; i < n; i++)
} //void GenRandOrth()
} // for (int i = 0; i < n; i++)
} // void GenRandOrth()
/// @brief Generate a random symmetric n x n matrix, M.
/// This function generates random numbers for the eigenvalues ("evals_known")
@ -211,32 +180,31 @@ void GenRandSymm(Matrix M, //<! store the matrix here
int n, //<! matrix size
Vector evals, //<! store the eigenvalues of here
Matrix evecs, //<! store the eigenvectors here
std::default_random_engine &rand_generator,//<! makes random numbers
Scalar min_eval_size=0.1, //<! minimum possible eigenvalue size
Scalar max_eval_size=10.0,//<! maximum possible eigenvalue size
int n_degeneracy=1//<!number of repeated eigevalues(1disables)
)
std::default_random_engine &rand_generator, //<! makes random numbers
Scalar min_eval_size = 0.1, //<! minimum possible eigenvalue size
Scalar max_eval_size = 10.0, //<! maximum possible eigenvalue size
int n_degeneracy = 1 //<!number of repeated eigevalues(1disables)
)
{
assert(n_degeneracy <= n);
std::uniform_real_distribution<Scalar> random_real01;
std::normal_distribution<Scalar> gaussian_distribution(0, max_eval_size);
bool use_log_uniform_distribution = false;
if (min_eval_size > 0.0)
use_log_uniform_distribution = true;
#if defined USE_VECTOR_OF_VECTORS
vector<vector<Scalar> > D(n, vector<Scalar>(n));
vector<vector<Scalar> > tmp(n, vector<Scalar>(n));
#elif defined USE_ARRAY_OF_ARRAYS
if (min_eval_size > 0.0) use_log_uniform_distribution = true;
#if defined USE_VECTOR_OF_VECTORS
vector<vector<Scalar>> D(n, vector<Scalar>(n));
vector<vector<Scalar>> tmp(n, vector<Scalar>(n));
#elif defined USE_ARRAY_OF_ARRAYS
array<array<Scalar, NF>, NF> D;
array<array<Scalar, NF>, NF> tmp;
#elif defined USE_C_FIXED_SIZE_ARRAYS
#elif defined USE_C_FIXED_SIZE_ARRAYS
Scalar D[NF][NF], tmp[NF][NF];
#else
#define USE_C_POINTER_TO_POINTERS
#else
#define USE_C_POINTER_TO_POINTERS
Scalar **D, **tmp;
Alloc2D(n, n, &D);
Alloc2D(n, n, &tmp);
#endif
#endif
// Randomly generate the eigenvalues
for (int i = 0; i < n; i++) {
@ -246,26 +214,24 @@ void GenRandSymm(Matrix M, //<! store the matrix here
assert((min_eval_size > 0.0) && (max_eval_size > 0.0));
Scalar log_min = std::log(std::abs(min_eval_size));
Scalar log_max = std::log(std::abs(max_eval_size));
Scalar log_eval = (log_min + random_real01(rand_generator)*(log_max-log_min));
Scalar log_eval = (log_min + random_real01(rand_generator) * (log_max - log_min));
evals[i] = std::exp(log_eval);
// also consider both positive and negative eigenvalues:
if (random_real01(rand_generator) < 0.5)
evals[i] = -evals[i];
}
else {
if (random_real01(rand_generator) < 0.5) evals[i] = -evals[i];
} else {
evals[i] = gaussian_distribution(rand_generator);
}
}
// Does the user want us to force some of the eigenvalues to be the same?
if (n_degeneracy > 1) {
int *permutation = new int[n]; //a random permutation from 0...n-1
int *permutation = new int[n]; // a random permutation from 0...n-1
for (int i = 0; i < n; i++)
permutation[i] = i;
std::shuffle(permutation, permutation+n, rand_generator);
for (int i = 1; i < n_degeneracy; i++) //set the first n_degeneracy to same
std::shuffle(permutation, permutation + n, rand_generator);
for (int i = 1; i < n_degeneracy; i++) // set the first n_degeneracy to same
evals[permutation[i]] = evals[permutation[0]];
delete [] permutation;
delete[] permutation;
}
// D is a diagonal matrix whose diagonal elements are the eigenvalues
@ -276,62 +242,59 @@ void GenRandSymm(Matrix M, //<! store the matrix here
// Now randomly generate the (transpose of) the "evecs" matrix
GenRandOrth<Scalar, Matrix>(evecs, n, rand_generator); //(will transpose it later)
// Construct the test matrix, M, where M = Rt * D * R
// Construct the test matrix, M, where M = Rt * D * R
// Original code:
//mmult(evecs, D, tmp, n); // <--> tmp = Rt * D
// Unfortunately, C++ guesses the types incorrectly. Must manually specify:
// #ifdefs making the code ugly again:
#if defined USE_VECTOR_OF_VECTORS
mmult<vector<vector<Scalar> >&, const vector<vector<Scalar> >&>
#elif defined USE_ARRAY_OF_ARRAYS
mmult<array<array<Scalar,NF>,NF>&, const array<array<Scalar,NF>,NF>&>
#elif defined USE_C_FIXED_SIZE_ARRAYS
mmult<Scalar (*)[NF], Scalar (*)[NF]>
#else
mmult<Scalar**, Scalar const *const *>
#endif
// Original code:
// mmult(evecs, D, tmp, n); // <--> tmp = Rt * D
// Unfortunately, C++ guesses the types incorrectly. Must manually specify:
// #ifdefs making the code ugly again:
#if defined USE_VECTOR_OF_VECTORS
mmult<vector<vector<Scalar>> &, const vector<vector<Scalar>> &>
#elif defined USE_ARRAY_OF_ARRAYS
mmult<array<array<Scalar, NF>, NF> &, const array<array<Scalar, NF>, NF> &>
#elif defined USE_C_FIXED_SIZE_ARRAYS
mmult<Scalar(*)[NF], Scalar(*)[NF]>
#else
mmult<Scalar **, Scalar const *const *>
#endif
(evecs, D, tmp, n);
for (int i = 0; i < n-1; i++)
for (int j = i+1; j < n; j++)
std::swap(evecs[i][j], evecs[j][i]); //transpose "evecs"
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
std::swap(evecs[i][j], evecs[j][i]); // transpose "evecs"
// Original code:
//mmult(tmp, evecs, M, n);
// Unfortunately, C++ guesses the types incorrectly. Must manually specify:
// #ifdefs making the code ugly again:
#if defined USE_VECTOR_OF_VECTORS
mmult<vector<vector<Scalar> >&, const vector<vector<Scalar> >&>
#elif defined USE_ARRAY_OF_ARRAYS
mmult<array<array<Scalar,NF>,NF>&, const array<array<Scalar,NF>,NF>&>
#elif defined USE_C_FIXED_SIZE_ARRAYS
mmult<Scalar (*)[NF], Scalar (*)[NF]>
#else
mmult<Scalar**, Scalar const *const *>
#endif
// Original code:
// mmult(tmp, evecs, M, n);
// Unfortunately, C++ guesses the types incorrectly. Must manually specify:
// #ifdefs making the code ugly again:
#if defined USE_VECTOR_OF_VECTORS
mmult<vector<vector<Scalar>> &, const vector<vector<Scalar>> &>
#elif defined USE_ARRAY_OF_ARRAYS
mmult<array<array<Scalar, NF>, NF> &, const array<array<Scalar, NF>, NF> &>
#elif defined USE_C_FIXED_SIZE_ARRAYS
mmult<Scalar(*)[NF], Scalar(*)[NF]>
#else
mmult<Scalar **, Scalar const *const *>
#endif
(tmp, evecs, M, n);
//at this point M = Rt*D*R (where "R"="evecs")
// at this point M = Rt*D*R (where "R"="evecs")
#if defined USE_C_POINTER_TO_POINTERS
#if defined USE_C_POINTER_TO_POINTERS
Dealloc2D(&D);
Dealloc2D(&tmp);
#endif
#endif
} // GenRandSymm()
template <typename Scalar>
void TestJacobi(int n, //<! matrix size
int n_matrices=100, //<! number of matrices to test
Scalar min_eval_size=0.1, //<! minimum possible eigenvalue sizw
Scalar max_eval_size=10.0, //<! maximum possible eigenvalue size
int n_tests_per_matrix=1, //<! repeat test for benchmarking?
int n_matrices = 100, //<! number of matrices to test
Scalar min_eval_size = 0.1, //<! minimum possible eigenvalue sizw
Scalar max_eval_size = 10.0, //<! maximum possible eigenvalue size
int n_tests_per_matrix = 1, //<! repeat test for benchmarking?
int n_degeneracy=1, //<! repeated eigenvalues?
unsigned seed=0, //<! random seed (if 0 then use the clock)
Scalar eps=1.0e-06
)
int n_degeneracy = 1, //<! repeated eigenvalues?
unsigned seed = 0, //<! random seed (if 0 then use the clock)
Scalar eps = 1.0e-06)
{
bool test_code_coverage = false;
if (n_tests_per_matrix < 1) {
@ -347,39 +310,35 @@ void TestJacobi(int n, //<! matrix size
seed = std::chrono::system_clock::now().time_since_epoch().count();
std::default_random_engine rand_generator(seed);
// Create an instance of the Jacobi diagonalizer, and allocate the matrix
// we will test it on, as well as the arrays that will store the resulting
// eigenvalues and eigenvectors.
// The way we do this depends on what version of the code we are using.
// This is controlled by "#if defined" statements.
#if defined USE_VECTOR_OF_VECTORS
#if defined USE_VECTOR_OF_VECTORS
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& > ecalc(n);
Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &, const vector<vector<Scalar>> &>
ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors
vector<vector<Scalar> > M(n, vector<Scalar>(n));
vector<vector<Scalar> > evecs(n, vector<Scalar>(n));
vector<vector<Scalar> > evecs_known(n, vector<Scalar>(n));
vector<vector<Scalar>> M(n, vector<Scalar>(n));
vector<vector<Scalar>> evecs(n, vector<Scalar>(n));
vector<vector<Scalar>> evecs_known(n, vector<Scalar>(n));
vector<Scalar> evals(n);
vector<Scalar> evals_known(n);
vector<Scalar> test_evec(n);
#elif defined USE_ARRAY_OF_ARRAYS
#elif defined USE_ARRAY_OF_ARRAYS
n = NF;
cout << "Testing std::array (fixed size).\n"
"(Ignoring first argument, and setting matrix size to " << n << ")" << endl;
"(Ignoring first argument, and setting matrix size to "
<< n << ")" << endl;
Jacobi<Scalar,
array<Scalar, NF>&,
array<array<Scalar, NF>, NF>&,
const array<array<Scalar, NF>, NF>&> ecalc(n);
Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
const array<array<Scalar, NF>, NF> &>
ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors
array<array<Scalar, NF>, NF> M;
@ -389,15 +348,13 @@ void TestJacobi(int n, //<! matrix size
array<Scalar, NF> evals_known;
array<Scalar, NF> test_evec;
#elif defined USE_C_FIXED_SIZE_ARRAYS
#elif defined USE_C_FIXED_SIZE_ARRAYS
n = NF;
cout << "Testing C fixed size arrays.\n"
"(Ignoring first argument, and setting matrix size to " << n << ")" << endl;
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]> ecalc(n);
"(Ignoring first argument, and setting matrix size to "
<< n << ")" << endl;
Jacobi<Scalar, Scalar *, Scalar(*)[NF], Scalar const(*)[NF]> ecalc(n);
// allocate the matrix, eigenvalues, eigenvectors
Scalar M[NF][NF];
@ -407,9 +364,9 @@ void TestJacobi(int n, //<! matrix size
Scalar evals_known[NF];
Scalar test_evec[NF];
#else
#else
#define USE_C_POINTER_TO_POINTERS
#define USE_C_POINTER_TO_POINTERS
// Note: Normally, you would just use this to instantiate Jacobi:
// Jacobi<Scalar, Scalar*, Scalar**, Scalar const*const*> ecalc(n);
@ -417,12 +374,12 @@ void TestJacobi(int n, //<! matrix size
// ..but since Jacobi manages its own memory using new and delete, I also want
// to test that the copy constructors, copy operators, and destructors work.
// The following lines do this:
Jacobi<Scalar, Scalar*, Scalar**, Scalar const*const*> ecalc_test_mem1(n);
Jacobi<Scalar, Scalar*, Scalar**, Scalar const*const*> ecalc_test_mem2(2);
Jacobi<Scalar, Scalar *, Scalar **, Scalar const *const *> ecalc_test_mem1(n);
Jacobi<Scalar, Scalar *, Scalar **, Scalar const *const *> ecalc_test_mem2(2);
// test the = operator
ecalc_test_mem2 = ecalc_test_mem1;
// test the copy constructor
Jacobi<Scalar, Scalar*, Scalar**, Scalar const*const*> ecalc(ecalc_test_mem2);
Jacobi<Scalar, Scalar *, Scalar **, Scalar const *const *> ecalc(ecalc_test_mem2);
// allocate the matrix, eigenvalues, eigenvectors
Scalar **M, **evecs, **evecs_known;
Alloc2D(n, n, &M);
@ -432,53 +389,45 @@ void TestJacobi(int n, //<! matrix size
Scalar *evals_known = new Scalar[n];
Scalar *test_evec = new Scalar[n];
#endif
#endif
// --------------------------------------------------------------------
// Now, generate random matrices and test Jacobi::Diagonalize() on them.
// --------------------------------------------------------------------
for(int imat = 0; imat < n_matrices; imat++) {
for (int imat = 0; imat < n_matrices; imat++) {
// Create a randomly generated symmetric matrix.
//This function generates random numbers for the eigenvalues ("evals_known")
//as well as the eigenvectors ("evecs_known"), and uses them to generate M.
// This function generates random numbers for the eigenvalues ("evals_known")
// as well as the eigenvectors ("evecs_known"), and uses them to generate M.
#if defined USE_VECTOR_OF_VECTORS
GenRandSymm<Scalar, vector<Scalar>&, vector<vector<Scalar> >&>
#elif defined USE_ARRAY_OF_ARRAYS
GenRandSymm<Scalar, array<Scalar,NF>&, array<array<Scalar,NF>,NF>&>
#elif defined USE_C_FIXED_SIZE_ARRAYS
GenRandSymm<Scalar, Scalar*, Scalar (*)[NF]>
#else
GenRandSymm<Scalar, Scalar*, Scalar**>
#endif
(M,
n,
evals_known,
evecs_known,
rand_generator,
min_eval_size,
max_eval_size,
#if defined USE_VECTOR_OF_VECTORS
GenRandSymm<Scalar, vector<Scalar> &, vector<vector<Scalar>> &>
#elif defined USE_ARRAY_OF_ARRAYS
GenRandSymm<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &>
#elif defined USE_C_FIXED_SIZE_ARRAYS
GenRandSymm<Scalar, Scalar *, Scalar(*)[NF]>
#else
GenRandSymm<Scalar, Scalar *, Scalar **>
#endif
(M, n, evals_known, evecs_known, rand_generator, min_eval_size, max_eval_size,
n_degeneracy);
// Sort the matrix evals and eigenvector rows:
// Original code:
//SortRows<Scalar>(evals_known, evecs_known, n);
// Unfortunately, C++ guesses the types incorrectly. Must use #ifdefs again:
#if defined USE_VECTOR_OF_VECTORS
SortRows<Scalar, vector<Scalar>&, vector<vector<Scalar> >&>
#elif defined USE_ARRAY_OF_ARRAYS
SortRows<Scalar, array<Scalar,NF>&, array<array<Scalar,NF>,NF>&>
#elif defined USE_C_FIXED_SIZE_ARRAYS
SortRows<Scalar, Scalar*, Scalar (*)[NF]>
#else
SortRows<Scalar, Scalar*, Scalar**>
#endif
// Sort the matrix evals and eigenvector rows:
// Original code:
// SortRows<Scalar>(evals_known, evecs_known, n);
// Unfortunately, C++ guesses the types incorrectly. Must use #ifdefs again:
#if defined USE_VECTOR_OF_VECTORS
SortRows<Scalar, vector<Scalar> &, vector<vector<Scalar>> &>
#elif defined USE_ARRAY_OF_ARRAYS
SortRows<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &>
#elif defined USE_C_FIXED_SIZE_ARRAYS
SortRows<Scalar, Scalar *, Scalar(*)[NF]>
#else
SortRows<Scalar, Scalar *, Scalar **>
#endif
(evals_known, evecs_known, n);
if (n_matrices == 1) {
cout << "Eigenvalues (after sorting):\n";
for (int i = 0; i < n; i++)
@ -490,169 +439,111 @@ void TestJacobi(int n, //<! matrix size
cout << evecs_known[i][j] << " ";
cout << "\n";
}
cout << " (The eigenvectors calculated by Jacobi::Diagonalize() should match these.)\n";
cout
<< " (The eigenvectors calculated by Jacobi::Diagonalize() should match these.)\n";
}
for (int i_test = 0; i_test < n_tests_per_matrix; i_test++) {
if (test_code_coverage) {
// test SORT_INCREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& >::SORT_INCREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar,NF>,NF>&>::SORT_INCREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]>::SORT_INCREASING_ABS_EVALS);
#else
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const*const*>::SORT_INCREASING_ABS_EVALS);
#endif
// test SORT_INCREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
const vector<vector<Scalar>> &>::SORT_INCREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar(*)[NF],
Scalar const(*)[NF]>::SORT_INCREASING_ABS_EVALS);
#else
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar **,
Scalar const *const *>::SORT_INCREASING_ABS_EVALS);
#endif
for (int i = 1; i < n; i++)
assert(std::abs(evals[i-1])<=std::abs(evals[i]));
assert(std::abs(evals[i - 1]) <= std::abs(evals[i]));
// test SORT_DECREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& >::SORT_DECREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar,NF>,NF>&>::SORT_DECREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]>::SORT_DECREASING_ABS_EVALS);
#else
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const*const*>::SORT_DECREASING_ABS_EVALS);
#endif
// test SORT_DECREASING_ABS_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
const vector<vector<Scalar>> &>::SORT_DECREASING_ABS_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
const array<array<Scalar, NF>, NF> &>::SORT_DECREASING_ABS_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar(*)[NF],
Scalar const(*)[NF]>::SORT_DECREASING_ABS_EVALS);
#else
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar **,
Scalar const *const *>::SORT_DECREASING_ABS_EVALS);
#endif
for (int i = 1; i < n; i++)
assert(std::abs(evals[i-1])>=std::abs(evals[i]));
assert(std::abs(evals[i - 1]) >= std::abs(evals[i]));
// test SORT_INCREASING_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& >::SORT_INCREASING_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar,NF>,NF>&>::SORT_INCREASING_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]>::SORT_INCREASING_EVALS);
#else
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const*const*>::SORT_INCREASING_EVALS);
#endif
// test SORT_INCREASING_EVALS:
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
const vector<vector<Scalar>> &>::SORT_INCREASING_EVALS);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
const array<array<Scalar, NF>, NF> &>::SORT_INCREASING_EVALS);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar(*)[NF],
Scalar const(*)[NF]>::SORT_INCREASING_EVALS);
#else
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar **,
Scalar const *const *>::SORT_INCREASING_EVALS);
#endif
for (int i = 1; i < n; i++)
assert(evals[i-1] <= evals[i]);
assert(evals[i - 1] <= evals[i]);
// test DO_NOT_SORT
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
vector<Scalar>&,
vector<vector<Scalar> >&,
const vector<vector<Scalar> >& >::DO_NOT_SORT);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
array<Scalar,NF>&,
array<array<Scalar,NF>,NF>&,
const array<array<Scalar,NF>,NF>&>::DO_NOT_SORT);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar (*)[NF],
Scalar const (*)[NF]>::DO_NOT_SORT);
#else
ecalc.Diagonalize(M,
evals,
evecs,
Jacobi<Scalar,
Scalar*,
Scalar**,
Scalar const*const*>::DO_NOT_SORT);
#endif
} //if (test_code_coverage)
// test DO_NOT_SORT
#if defined USE_VECTOR_OF_VECTORS
ecalc.Diagonalize(M, evals, evecs,
Jacobi<Scalar, vector<Scalar> &, vector<vector<Scalar>> &,
const vector<vector<Scalar>> &>::DO_NOT_SORT);
#elif defined USE_ARRAY_OF_ARRAYS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, array<Scalar, NF> &, array<array<Scalar, NF>, NF> &,
const array<array<Scalar, NF>, NF> &>::DO_NOT_SORT);
#elif defined USE_C_FIXED_SIZE_ARRAYS
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar(*)[NF], Scalar const(*)[NF]>::DO_NOT_SORT);
#else
ecalc.Diagonalize(
M, evals, evecs,
Jacobi<Scalar, Scalar *, Scalar **, Scalar const *const *>::DO_NOT_SORT);
#endif
} // if (test_code_coverage)
// Now (finally) calculate the eigenvalues and eigenvectors
int n_sweeps = ecalc.Diagonalize(M, evals, evecs);
if ((n_matrices == 1) && (i_test == 0)) {
cout <<"Jacobi::Diagonalize() ran for "<<n_sweeps<<" iters (sweeps).\n";
cout << "Jacobi::Diagonalize() ran for " << n_sweeps << " iters (sweeps).\n";
cout << "Eigenvalues calculated by Jacobi::Diagonalize()\n";
for (int i = 0; i < n; i++)
cout << evals[i] << " ";
@ -665,40 +556,39 @@ void TestJacobi(int n, //<! matrix size
}
}
assert(SimilarVec(evals, evals_known, n, eps*max_eval_size, eps));
//Check that each eigenvector satisfies Mv = λv
assert(SimilarVec(evals, evals_known, n, eps * max_eval_size, eps));
// Check that each eigenvector satisfies Mv = λv
// <--> Σ_b M[a][b]*evecs[i][b] = evals[i]*evecs[i][b] (for all a)
for (int i = 0; i < n; i++) {
for (int a = 0; a < n; a++) {
test_evec[a] = 0.0;
for (int b = 0; b < n; b++)
test_evec[a] += M[a][b] * evecs[i][b];
assert(Similar(test_evec[a],
evals[i] * evecs[i][a],
assert(Similar(test_evec[a], evals[i] * evecs[i][a],
eps, // tolerance (absolute difference)
eps*max_eval_size, // tolerance ratio (numerator)
eps * max_eval_size, // tolerance ratio (numerator)
evals_known[i] // tolerance ration (denominator)
));
}
}
} //for (int i_test = 0; i_test < n_tests_per_matrix; i++)
} // for (int i_test = 0; i_test < n_tests_per_matrix; i++)
} //for(int imat = 0; imat < n_matrices; imat++) {
} // for(int imat = 0; imat < n_matrices; imat++) {
#if defined USE_C_POINTER_TO_POINTERS
#if defined USE_C_POINTER_TO_POINTERS
Dealloc2D(&M);
Dealloc2D(&evecs);
Dealloc2D(&evecs_known);
delete [] evals;
delete [] evals_known;
delete [] test_evec;
#endif
delete[] evals;
delete[] evals_known;
delete[] test_evec;
#endif
} //TestJacobi()
} // TestJacobi()
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
int n_size = 2;
int n_matr = 1;
double emin = 0.0;
@ -708,8 +598,7 @@ int main(int argc, char **argv) {
unsigned seed = 0;
if (argc <= 1) {
cerr <<
"Error: This program requires at least 1 argument.\n"
cerr << "Error: This program requires at least 1 argument.\n"
"\n"
"Description: Run Jacobi::Diagonalize() on randomly generated matrices.\n"
"\n"
@ -743,21 +632,14 @@ int main(int argc, char **argv) {
}
n_size = std::stoi(argv[1]);
if (argc > 2)
n_matr = std::stoi(argv[2]);
if (argc > 3)
emin = std::stof(argv[3]);
if (argc > 4)
emax = std::stof(argv[4]);
if (argc > 5)
n_degeneracy = std::stoi(argv[5]);
if (argc > 6)
n_tests = std::stoi(argv[6]);
if (argc > 7)
seed = std::stoi(argv[7]);
if (argc > 2) n_matr = std::stoi(argv[2]);
if (argc > 3) emin = std::stof(argv[3]);
if (argc > 4) emax = std::stof(argv[4]);
if (argc > 5) n_degeneracy = std::stoi(argv[5]);
if (argc > 6) n_tests = std::stoi(argv[6]);
if (argc > 7) seed = std::stoi(argv[7]);
double eps = 1.0e-06;
if (argc > 8)
eps = std::stof(argv[8]);
if (argc > 8) eps = std::stof(argv[8]);
TestJacobi(n_size, n_matr, emin, emax, n_tests, n_degeneracy, seed, eps);

View File

@ -19,329 +19,333 @@
using namespace LAMMPS_NS;
TEST(MyPage, int) {
TEST(MyPage, int)
{
MyPage<int> p;
// default init. maxchunk=1, pagesize=1024
int rv = p.init();
ASSERT_EQ(rv,0);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
int *iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(1);
++iptr;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
ASSERT_EQ(iptr, p.vget());
// use too large chunk size
p.vgot(2);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(1);
++iptr;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(1));
ASSERT_EQ(p.ndatum,3);
ASSERT_EQ(p.nchunk,3);
ASSERT_EQ(iptr, p.get(1));
ASSERT_EQ(p.ndatum, 3);
ASSERT_EQ(p.nchunk, 3);
// restart with custom init. maxchunk=16, pagesize=256
rv = p.init(16,64,2);
ASSERT_EQ(rv,0);
rv = p.init(16, 64, 2);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(16);
iptr += 16;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,16);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 16);
ASSERT_EQ(p.nchunk, 1);
// use too large chunk size
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(32);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(16);
iptr = p.vget();
p.vgot(4);
iptr += 4;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(int)*128.0);
ASSERT_EQ(p.ndatum,37);
ASSERT_EQ(p.nchunk,4);
ASSERT_EQ(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(int) * 128.0);
ASSERT_EQ(p.ndatum, 37);
ASSERT_EQ(p.nchunk, 4);
p.get(16);
p.get(16);
// allocation on the same page
iptr = p.get(16);
iptr += 16;
ASSERT_EQ(iptr,p.get(16));
ASSERT_EQ(iptr, p.get(16));
// allocation on different pages
p.get(16);
iptr += 16;
ASSERT_NE(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(int)*256.0);
ASSERT_EQ(p.ndatum,133);
ASSERT_EQ(p.nchunk,10);
ASSERT_NE(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(int) * 256.0);
ASSERT_EQ(p.ndatum, 133);
ASSERT_EQ(p.nchunk, 10);
}
TEST(MyPage, double) {
TEST(MyPage, double)
{
MyPage<double> p;
// default init. maxchunk=1, pagesize=1024
int rv = p.init();
ASSERT_EQ(rv,0);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
double *iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(1);
++iptr;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
ASSERT_EQ(iptr, p.vget());
// use too large chunk size
p.vgot(2);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(1);
++iptr;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(1));
ASSERT_EQ(p.ndatum,3);
ASSERT_EQ(p.nchunk,3);
ASSERT_EQ(iptr, p.get(1));
ASSERT_EQ(p.ndatum, 3);
ASSERT_EQ(p.nchunk, 3);
// restart with custom init. maxchunk=16, pagesize=256
rv = p.init(16,64,2);
ASSERT_EQ(rv,0);
rv = p.init(16, 64, 2);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(16);
iptr += 16;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,16);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 16);
ASSERT_EQ(p.nchunk, 1);
// use too large chunk size
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(32);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(16);
iptr = p.vget();
p.vgot(4);
iptr += 4;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(double)*128.0);
ASSERT_EQ(p.ndatum,37);
ASSERT_EQ(p.nchunk,4);
ASSERT_EQ(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(double) * 128.0);
ASSERT_EQ(p.ndatum, 37);
ASSERT_EQ(p.nchunk, 4);
p.get(16);
p.get(16);
// allocation on the same page
iptr = p.get(16);
iptr += 16;
ASSERT_EQ(iptr,p.get(16));
ASSERT_EQ(iptr, p.get(16));
// allocation on different pages
p.get(16);
iptr += 16;
ASSERT_NE(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(double)*256.0);
ASSERT_EQ(p.ndatum,133);
ASSERT_EQ(p.nchunk,10);
ASSERT_NE(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(double) * 256.0);
ASSERT_EQ(p.ndatum, 133);
ASSERT_EQ(p.nchunk, 10);
}
TEST(MyPage, bigint) {
TEST(MyPage, bigint)
{
MyPage<bigint> p;
// default init. maxchunk=1, pagesize=1024
int rv = p.init();
ASSERT_EQ(rv,0);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
bigint *iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(1);
++iptr;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
ASSERT_EQ(iptr, p.vget());
// use too large chunk size
p.vgot(2);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(1);
++iptr;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(1));
ASSERT_EQ(p.ndatum,3);
ASSERT_EQ(p.nchunk,3);
ASSERT_EQ(iptr, p.get(1));
ASSERT_EQ(p.ndatum, 3);
ASSERT_EQ(p.nchunk, 3);
// restart with custom init. maxchunk=16, pagesize=256
rv = p.init(16,64,2);
ASSERT_EQ(rv,0);
rv = p.init(16, 64, 2);
ASSERT_EQ(rv, 0);
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
// second call to vget() should give same pointer without vgot()
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(16);
iptr += 16;
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,16);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 16);
ASSERT_EQ(p.nchunk, 1);
// use too large chunk size
ASSERT_EQ(iptr,p.vget());
ASSERT_EQ(iptr, p.vget());
p.vgot(32);
ASSERT_EQ(1,p.status());
ASSERT_EQ(1, p.status());
p.reset();
ASSERT_EQ(0,p.status());
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(0, p.status());
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
iptr = p.vget();
p.vgot(16);
iptr = p.vget();
p.vgot(4);
iptr += 4;
ASSERT_EQ(iptr,p.get());
ASSERT_EQ(iptr, p.get());
++iptr;
ASSERT_EQ(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(bigint)*128.0);
ASSERT_EQ(p.ndatum,37);
ASSERT_EQ(p.nchunk,4);
ASSERT_EQ(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(bigint) * 128.0);
ASSERT_EQ(p.ndatum, 37);
ASSERT_EQ(p.nchunk, 4);
p.get(16);
p.get(16);
// allocation on the same page
iptr = p.get(16);
iptr += 16;
ASSERT_EQ(iptr,p.get(16));
ASSERT_EQ(iptr, p.get(16));
// allocation on different pages
p.get(16);
iptr += 16;
ASSERT_NE(iptr,p.get(16));
ASSERT_DOUBLE_EQ(p.size(),(double)sizeof(bigint)*256.0);
ASSERT_EQ(p.ndatum,133);
ASSERT_EQ(p.nchunk,10);
ASSERT_NE(iptr, p.get(16));
ASSERT_DOUBLE_EQ(p.size(), (double)sizeof(bigint) * 256.0);
ASSERT_EQ(p.ndatum, 133);
ASSERT_EQ(p.nchunk, 10);
}
TEST(MyPoolChunk, int) {
TEST(MyPoolChunk, int)
{
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
MyPoolChunk<int> p;
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.size(),0.0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
ASSERT_EQ(p.size(), 0.0);
int idx=~0x0000;
int idx = ~0x0000;
int *iptr = p.get(idx);
ASSERT_NE(iptr,nullptr);
ASSERT_EQ(idx,0);
ASSERT_NE(iptr, nullptr);
ASSERT_EQ(idx, 0);
iptr = p.get(1,idx);
ASSERT_NE(iptr,nullptr);
ASSERT_EQ(idx,1);
iptr = p.get(1, idx);
ASSERT_NE(iptr, nullptr);
ASSERT_EQ(idx, 1);
// we have only one page allocated
ASSERT_EQ(p.size(),1024*sizeof(int)+1024*sizeof(int)+sizeof(void *)+sizeof(int));
ASSERT_EQ(p.ndatum,2);
ASSERT_EQ(p.nchunk,2);
ASSERT_EQ(p.size(), 1024 * sizeof(int) + 1024 * sizeof(int) + sizeof(void *) + sizeof(int));
ASSERT_EQ(p.ndatum, 2);
ASSERT_EQ(p.nchunk, 2);
p.put(0);
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
iptr = p.get(2,idx);
ASSERT_EQ(iptr,nullptr);
ASSERT_EQ(p.status(),3);
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
iptr = p.get(2, idx);
ASSERT_EQ(iptr, nullptr);
ASSERT_EQ(p.status(), 3);
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
}
TEST(MyPoolChunk, double) {
TEST(MyPoolChunk, double)
{
// defaults to minchunk=1, maxchunk=1, nbin=1, chunksperpage=1024, pagedelta=1
MyPoolChunk<double> p;
ASSERT_EQ(p.ndatum,0);
ASSERT_EQ(p.nchunk,0);
ASSERT_EQ(p.size(),0.0);
ASSERT_EQ(p.ndatum, 0);
ASSERT_EQ(p.nchunk, 0);
ASSERT_EQ(p.size(), 0.0);
int idx=~0x0000;
int idx = ~0x0000;
double *dptr = p.get(idx);
ASSERT_NE(dptr,nullptr);
ASSERT_EQ(idx,0);
ASSERT_NE(dptr, nullptr);
ASSERT_EQ(idx, 0);
dptr = p.get(1,idx);
ASSERT_NE(dptr,nullptr);
ASSERT_EQ(idx,1);
dptr = p.get(1, idx);
ASSERT_NE(dptr, nullptr);
ASSERT_EQ(idx, 1);
// we have only one page allocated
ASSERT_EQ(p.size(),1024*sizeof(int)+1024*sizeof(double)+sizeof(void *)+sizeof(int));
ASSERT_EQ(p.size(), 1024 * sizeof(int) + 1024 * sizeof(double) + sizeof(void *) + sizeof(int));
p.put(0);
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
dptr = p.get(2,idx);
ASSERT_EQ(dptr,nullptr);
ASSERT_EQ(p.status(),3);
ASSERT_EQ(p.ndatum,1);
ASSERT_EQ(p.nchunk,1);
dptr = p.get(2, idx);
ASSERT_EQ(dptr, nullptr);
ASSERT_EQ(p.status(), 3);
ASSERT_EQ(p.ndatum, 1);
ASSERT_EQ(p.nchunk, 1);
}

View File

@ -158,13 +158,15 @@ TEST(ValueTokenizer, valid_double_with_exponential)
ASSERT_DOUBLE_EQ(values.next_double(), 3.14e22);
}
TEST(ValueTokenizer, contains) {
TEST(ValueTokenizer, contains)
{
ValueTokenizer values("test word");
ASSERT_TRUE(values.contains("test"));
ASSERT_TRUE(values.contains("word"));
}
TEST(ValueTokenizer, not_contains) {
TEST(ValueTokenizer, not_contains)
{
ValueTokenizer values("test word");
ASSERT_FALSE(values.contains("test2"));
}

View File

@ -27,7 +27,7 @@ using ::testing::Eq;
using ::testing::StrEq;
#if !defined(FLERR)
#define FLERR __FILE__,__LINE__
#define FLERR __FILE__, __LINE__
#endif
TEST(Utils, trim)
@ -373,11 +373,11 @@ TEST(Utils, bounds_case1)
nlo = nhi = -1;
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,9);
ASSERT_EQ(nhi,9);
ASSERT_EQ(nlo, 9);
ASSERT_EQ(nhi, 9);
utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,1);
ASSERT_EQ(nhi,1);
ASSERT_EQ(nlo, 1);
ASSERT_EQ(nhi, 1);
}
TEST(Utils, bounds_case2)
@ -386,11 +386,11 @@ TEST(Utils, bounds_case2)
nlo = nhi = -1;
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,0);
ASSERT_EQ(nhi,10);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-10);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 5);
}
TEST(Utils, bounds_case3)
@ -399,11 +399,11 @@ TEST(Utils, bounds_case3)
nlo = nhi = -1;
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,2);
ASSERT_EQ(nhi,10);
ASSERT_EQ(nlo, 2);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,3);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, 3);
ASSERT_EQ(nhi, 5);
}
TEST(Utils, bounds_case4)
@ -412,11 +412,11 @@ TEST(Utils, bounds_case4)
nlo = nhi = -1;
utils::bounds(FLERR, "*2", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,0);
ASSERT_EQ(nhi,2);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 2);
utils::bounds(FLERR, "*3", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-10);
ASSERT_EQ(nhi,3);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 3);
}
TEST(Utils, bounds_case5)
@ -425,11 +425,11 @@ TEST(Utils, bounds_case5)
nlo = nhi = -1;
utils::bounds(FLERR, "2*5", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,2);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, 2);
ASSERT_EQ(nhi, 5);
utils::bounds(FLERR, "-2*3", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-2);
ASSERT_EQ(nhi,3);
ASSERT_EQ(nlo, -2);
ASSERT_EQ(nhi, 3);
}
TEST(Utils, boundsbig_case1)
@ -438,11 +438,11 @@ TEST(Utils, boundsbig_case1)
nlo = nhi = -1;
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,9);
ASSERT_EQ(nhi,9);
ASSERT_EQ(nlo, 9);
ASSERT_EQ(nhi, 9);
utils::bounds(FLERR, "1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,1);
ASSERT_EQ(nhi,1);
ASSERT_EQ(nlo, 1);
ASSERT_EQ(nhi, 1);
}
TEST(Utils, boundsbig_case2)
@ -451,11 +451,11 @@ TEST(Utils, boundsbig_case2)
nlo = nhi = -1;
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,0);
ASSERT_EQ(nhi,10);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-10);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 5);
}
TEST(Utils, boundsbig_case3)
@ -464,11 +464,11 @@ TEST(Utils, boundsbig_case3)
nlo = nhi = -1;
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,2);
ASSERT_EQ(nhi,10);
ASSERT_EQ(nlo, 2);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "3*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,3);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, 3);
ASSERT_EQ(nhi, 5);
}
TEST(Utils, boundsbig_case4)
@ -477,11 +477,11 @@ TEST(Utils, boundsbig_case4)
nlo = nhi = -1;
utils::bounds(FLERR, "*2", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,0);
ASSERT_EQ(nhi,2);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 2);
utils::bounds(FLERR, "*3", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-10);
ASSERT_EQ(nhi,3);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 3);
}
TEST(Utils, boundsbig_case5)
@ -490,11 +490,11 @@ TEST(Utils, boundsbig_case5)
nlo = nhi = -1;
utils::bounds(FLERR, "2*5", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo,2);
ASSERT_EQ(nhi,5);
ASSERT_EQ(nlo, 2);
ASSERT_EQ(nhi, 5);
utils::bounds(FLERR, "-2*3", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo,-2);
ASSERT_EQ(nhi,3);
ASSERT_EQ(nlo, -2);
ASSERT_EQ(nhi, 3);
}
TEST(Utils, guesspath)
@ -628,19 +628,18 @@ TEST(Utils, timespec2seconds_hhmmss)
ASSERT_DOUBLE_EQ(utils::timespec2seconds("2:10:45"), 7845.0);
}
TEST(Utils, date2num)
{
ASSERT_EQ(utils::date2num("1Jan05"),20050101);
ASSERT_EQ(utils::date2num("10Feb2005"),20050210);
ASSERT_EQ(utils::date2num("02Mar10"),20100302);
ASSERT_EQ(utils::date2num(" 5Apr1900"),19000405);
ASSERT_EQ(utils::date2num("10May22 "),20220510);
ASSERT_EQ(utils::date2num("1 Jun 05"),20050601);
ASSERT_EQ(utils::date2num("10 Jul 2005"),20050710);
ASSERT_EQ(utils::date2num("02 Aug 10"),20100802);
ASSERT_EQ(utils::date2num(" 5 September 99"),20990905);
ASSERT_EQ(utils::date2num("10October22 "),20221010);
ASSERT_EQ(utils::date2num("30November 02"),20021130);
ASSERT_EQ(utils::date2num("31December100"),1001231);
ASSERT_EQ(utils::date2num("1Jan05"), 20050101);
ASSERT_EQ(utils::date2num("10Feb2005"), 20050210);
ASSERT_EQ(utils::date2num("02Mar10"), 20100302);
ASSERT_EQ(utils::date2num(" 5Apr1900"), 19000405);
ASSERT_EQ(utils::date2num("10May22 "), 20220510);
ASSERT_EQ(utils::date2num("1 Jun 05"), 20050601);
ASSERT_EQ(utils::date2num("10 Jul 2005"), 20050710);
ASSERT_EQ(utils::date2num("02 Aug 10"), 20100802);
ASSERT_EQ(utils::date2num(" 5 September 99"), 20990905);
ASSERT_EQ(utils::date2num("10October22 "), 20221010);
ASSERT_EQ(utils::date2num("30November 02"), 20021130);
ASSERT_EQ(utils::date2num("31December100"), 1001231);
}