update advanced utils tests. include test for expand args

This commit is contained in:
Axel Kohlmeyer
2022-04-26 16:16:44 -04:00
parent 7663fc6256
commit 7eb6c2652f

View File

@ -3,6 +3,7 @@
#include "error.h"
#include "input.h"
#include "lammps.h"
#include "memory.h"
#include "utils.h"
#include "../testing/core.h"
@ -26,6 +27,25 @@ protected:
LAMMPSTest::SetUp();
error = lmp->error;
}
void atomic_system()
{
BEGIN_HIDE_OUTPUT();
command("units real");
command("lattice sc 1.0 origin 0.125 0.125 0.125");
command("region box block -2 2 -2 2 -2 2");
command("create_box 8 box");
command("create_atoms 1 box");
command("pair_style zero 3.5");
command("pair_coeff * *");
command("mass * 1.0");
command("region left block -2.0 -1.0 INF INF INF INF");
command("region right block 0.5 2.0 INF INF INF INF");
command("region top block INF INF -2.0 -1.0 INF INF");
command("set region left type 2");
command("set region right type 3");
END_HIDE_OUTPUT();
}
};
TEST_F(Advanced_utils, missing_cmd_args)
@ -52,118 +72,111 @@ TEST_F(Advanced_utils, logmesg)
EXPECT_EQ(output, "test message from test " + testbinary);
};
TEST_F(Advanced_utils, bounds_case1)
// death tests only. the other cases are tested in the basic utils unit tester
TEST_F(Advanced_utils, bounds_int_fail)
{
int nlo, nhi;
nlo = nhi = -1;
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
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);
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
TEST_FAILURE("ERROR: Invalid range string: 1x ",
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: -1 ",
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\+1 ",
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 1:3 ",
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\? ",
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 3\\*:2 ",
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, error););
}
TEST_F(Advanced_utils, bounds_case2)
{
int nlo, nhi;
nlo = nhi = -1;
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 5);
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
}
TEST_F(Advanced_utils, bounds_case3)
{
int nlo, nhi;
nlo = nhi = -1;
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
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);
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
}
TEST_F(Advanced_utils, boundsbig_case1)
TEST_F(Advanced_utils, bounds_bigint_fail)
{
bigint nlo, nhi;
nlo = nhi = -1;
utils::bounds(FLERR, "9", 0, 10, nlo, nhi, nullptr);
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);
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
TEST_FAILURE("ERROR: Invalid range string: 1x ",
utils::bounds(FLERR, "1x", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: -1 ",
utils::bounds(FLERR, "-1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\+1 ",
utils::bounds(FLERR, "+1", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 1:3 ",
utils::bounds(FLERR, "1:3", 1, 10, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: \\? ",
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, error););
TEST_FAILURE("ERROR: Invalid range string: 3\\*:2 ",
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, error););
}
TEST_F(Advanced_utils, boundsbig_case2)
TEST_F(Advanced_utils, expand_args)
{
bigint nlo, nhi;
atomic_system();
BEGIN_CAPTURE_OUTPUT();
command("compute temp all temp");
command("variable temp vector c_temp");
command("variable step equal step");
command("variable pe equal pe");
command("variable pe equal pe");
command("variable epair equal epair");
command("compute gofr all rdf 20 1 1 1 2");
command("fix 1 all ave/time 1 1 1 v_step v_pe v_epair");
command("fix 2 all nve");
command("run 1 post no");
auto output = END_CAPTURE_OUTPUT();
nlo = nhi = -1;
utils::bounds(FLERR, "*", 0, 10, nlo, nhi, nullptr);
ASSERT_EQ(nlo, 0);
ASSERT_EQ(nhi, 10);
utils::bounds(FLERR, "*", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -10);
ASSERT_EQ(nhi, 5);
utils::bounds(FLERR, "?", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
}
char **args, **earg;
args = new char *[9];
args[0] = utils::strdup("v_step");
args[1] = utils::strdup("c_temp");
args[2] = utils::strdup("f_1[*]");
args[3] = utils::strdup("c_temp[*]");
args[4] = utils::strdup("v_temp[*]");
args[5] = utils::strdup("c_rdf[*]");
args[6] = utils::strdup("c_rdf[1][*]");
args[7] = utils::strdup("c_rdf[*][2]");
args[8] = utils::strdup("c_rdf[*][*]");
TEST_F(Advanced_utils, boundsbig_case3)
{
bigint nlo, nhi;
auto narg = utils::expand_args(FLERR, 9, args, 0, earg, lmp);
EXPECT_EQ(narg, 16);
EXPECT_STREQ(earg[0], "v_step");
EXPECT_STREQ(earg[1], "c_temp");
EXPECT_STREQ(earg[2], "f_1[1]");
EXPECT_STREQ(earg[3], "f_1[2]");
EXPECT_STREQ(earg[4], "f_1[3]");
EXPECT_STREQ(earg[5], "c_temp[1]");
EXPECT_STREQ(earg[6], "c_temp[2]");
EXPECT_STREQ(earg[7], "c_temp[3]");
EXPECT_STREQ(earg[8], "c_temp[4]");
EXPECT_STREQ(earg[9], "c_temp[5]");
EXPECT_STREQ(earg[10], "c_temp[6]");
EXPECT_STREQ(earg[11], "v_temp[*]");
EXPECT_STREQ(earg[12], "c_rdf[*]");
EXPECT_STREQ(earg[13], "c_rdf[1][*]");
EXPECT_STREQ(earg[14], "c_rdf[*][2]");
EXPECT_STREQ(earg[15], "c_rdf[*][*]");
nlo = nhi = -1;
utils::bounds(FLERR, "2*", 0, 10, nlo, nhi, nullptr);
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);
utils::bounds(FLERR, "3*:2", -10, 5, nlo, nhi, nullptr);
ASSERT_EQ(nlo, -1);
ASSERT_EQ(nhi, -1);
for (int i = 0; i < narg; ++i)
delete[] earg[i];
lmp->memory->sfree(earg);
narg = utils::expand_args(FLERR, 9, args, 1, earg, lmp);
EXPECT_EQ(narg, 9);
EXPECT_NE(args, earg);
EXPECT_STREQ(earg[0], "v_step");
EXPECT_STREQ(earg[1], "c_temp");
EXPECT_STREQ(earg[2], "f_1[*]");
EXPECT_STREQ(earg[3], "c_temp[*]");
EXPECT_STREQ(earg[4], "v_temp[*]");
EXPECT_STREQ(earg[5], "c_rdf[*]");
EXPECT_STREQ(earg[6], "c_rdf[1][*]");
EXPECT_STREQ(earg[7], "c_rdf[*][2]");
EXPECT_STREQ(earg[8], "c_rdf[*][*]");
for (int i = 0; i < 9; ++i)
delete[] args[i];
delete[] args;
for (int i = 0; i < narg; ++i)
delete[] earg[i];
lmp->memory->sfree(earg);
}
} // namespace LAMMPS_NS