ParameterSet.cc
Go to the documentation of this file.
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 #include <catch.hpp>
26 
27 #include <momemta/InputTag.h>
28 #include <momemta/ParameterSet.h>
29 
30 TEST_CASE("ParameterSet unit tests", "[core]") {
31  ParameterSet p;
32 
33  SECTION("Adding bool") {
34  REQUIRE_FALSE(p.existsAs<bool>("parameter"));
35 
36  p.set("parameter", false);
37 
38  REQUIRE(p.existsAs<bool>("parameter"));
39  REQUIRE_FALSE(p.get<bool>("parameter"));
40  }
41 
42  SECTION("Adding string") {
43  REQUIRE_FALSE(p.existsAs<std::string>("parameter"));
44 
45  p.set("parameter", "test");
46 
47  REQUIRE(p.existsAs<std::string>("parameter"));
48  REQUIRE(p.get<std::string>("parameter") == "test");
49  }
50 
51  SECTION("Adding InputTag") {
52  REQUIRE_FALSE(p.existsAs<InputTag>("parameter"));
53 
54  auto v = InputTag("module_name", "parameter");
55  p.set("parameter", v);
56 
57  REQUIRE(p.existsAs<InputTag>("parameter"));
58  REQUIRE(p.get<InputTag>("parameter") == v);
59  }
60 
61  SECTION("Adding vectors") {
62  REQUIRE_FALSE(p.existsAs<std::vector<double>>("parameter"));
63 
64  p.set("parameter", std::vector<double>({10, 20, 30}));
65 
66  REQUIRE(p.existsAs<std::vector<double>>("parameter"));
67  }
68 
69  SECTION("Implicit int64_t cast") {
70  REQUIRE_FALSE(p.existsAs<int64_t>("parameter"));
71 
72  p.set("parameter", 10);
73 
74  REQUIRE(p.existsAs<int64_t>("parameter"));
75  REQUIRE(p.get<int64_t>("parameter") == 10);
76  }
77 
78  SECTION("Implicit double cast") {
79  REQUIRE_FALSE(p.existsAs<double>("parameter"));
80 
81  p.set("parameter", 10.f);
82 
83  REQUIRE(p.existsAs<double>("parameter"));
84  REQUIRE(p.get<double>("parameter") == Approx(10));
85  }
86 
87  SECTION("Names should return the list of keys") {
88  p.set("p1", false);
89  p.set("p2", true);
90 
91  auto names = p.getNames();
92  REQUIRE(names.size() == 2);
93  REQUIRE(names[0] == "p1");
94  REQUIRE(names[1] == "p2");
95  }
96 }
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&#39;s first created...
Definition: ParameterSet.h:160
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
A class encapsulating a lua table.
Definition: ParameterSet.h:82