27 #include <momemta/InputTag.h> 28 #include <momemta/ParameterSet.h> 30 TEST_CASE(
"ParameterSet unit tests",
"[core]") {
33 SECTION(
"Adding bool") {
34 REQUIRE_FALSE(p.existsAs<
bool>(
"parameter"));
36 p.
set(
"parameter",
false);
38 REQUIRE(p.existsAs<
bool>(
"parameter"));
39 REQUIRE_FALSE(p.get<
bool>(
"parameter"));
42 SECTION(
"Adding string") {
43 REQUIRE_FALSE(p.existsAs<std::string>(
"parameter"));
45 p.
set(
"parameter",
"test");
47 REQUIRE(p.existsAs<std::string>(
"parameter"));
48 REQUIRE(p.get<std::string>(
"parameter") ==
"test");
51 SECTION(
"Adding InputTag") {
52 REQUIRE_FALSE(p.existsAs<
InputTag>(
"parameter"));
54 auto v =
InputTag(
"module_name",
"parameter");
55 p.
set(
"parameter", v);
57 REQUIRE(p.existsAs<
InputTag>(
"parameter"));
58 REQUIRE(p.get<
InputTag>(
"parameter") == v);
61 SECTION(
"Adding vectors") {
62 REQUIRE_FALSE(p.existsAs<std::vector<double>>(
"parameter"));
64 p.
set(
"parameter", std::vector<double>({10, 20, 30}));
66 REQUIRE(p.existsAs<std::vector<double>>(
"parameter"));
69 SECTION(
"Implicit int64_t cast") {
70 REQUIRE_FALSE(p.existsAs<int64_t>(
"parameter"));
72 p.
set(
"parameter", 10);
74 REQUIRE(p.existsAs<int64_t>(
"parameter"));
75 REQUIRE(p.get<int64_t>(
"parameter") == 10);
78 SECTION(
"Implicit double cast") {
79 REQUIRE_FALSE(p.existsAs<
double>(
"parameter"));
81 p.
set(
"parameter", 10.f);
83 REQUIRE(p.existsAs<
double>(
"parameter"));
84 REQUIRE(p.get<
double>(
"parameter") == Approx(10));
87 SECTION(
"Names should return the list of keys") {
91 auto names = p.getNames();
92 REQUIRE(names.size() == 2);
93 REQUIRE(names[0] ==
"p1");
94 REQUIRE(names[1] ==
"p2");
std::enable_if< std::is_same< T, bool >::value||std::is_same< T, InputTag >::value >::type set(const std::string &name, const T &value)
Change the value of a given parameter. If the parameter does not exist, it's first created...
A class encapsulating a lua table.