Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SelectorListTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SelectorListTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 #define BOOST_TEST_MODULE AbortList Tests
11 
12 #include <boost/test/included/unit_test.hpp>
13 // leave blank line
14 
15 #include <boost/test/data/test_case.hpp>
16 // leave blank line
17 
18 #include <boost/test/output_test_stream.hpp>
19 // leave blank line
20 
22 
23 namespace bdata = boost::unit_test::data;
24 namespace tt = boost::test_tools;
25 
26 namespace Fatras {
27 
28 namespace Test {
29 
31 struct Object {
32  int feature = 0;
34 };
35 
36 struct Environment {
37  int pickFeature = 1;
38 };
39 
43 
44  int select_on = 0;
45 
47  template <typename detector_t, typename particle_t>
48  bool operator()(const detector_t &, const particle_t &object) const {
49  return object.feature == select_on;
50  }
51 };
52 
55 struct NameSelector {
56 
58 
60  template <typename detector_t, typename particle_t>
61  bool operator()(const detector_t &environment,
62  const particle_t &object) const {
63  return object.name == select_on;
64  }
65 };
66 
70 
72  template <typename detector_t, typename particle_t>
73  bool operator()(const detector_t &environmet,
74  const particle_t &object) const {
75  return object.feature == environmet.pickFeature;
76  }
77 };
78 
79 // This tests the implementation of the selector list
80 BOOST_AUTO_TEST_CASE(SelectorList_test) {
81 
82  // An object with name and features
83  Object o1;
84  o1.name = "o";
85  o1.feature = 1;
86 
87  Environment en1;
88  en1.pickFeature = 1;
89 
90  // Selector that trifers on the feature
91  FeatureSelector selector1;
92  selector1.select_on = 1;
93  // the wrong feature value
94  FeatureSelector selector2;
95  selector2.select_on = 2;
96 
97  // test that the feature value 1 is selected
98  BOOST_TEST(selector1(en1, o1));
99  // test that the feature value 2 is selected
100  BOOST_TEST(!selector2(en1, o1));
101 
102  // Let's test this with the selector list
103  SelectorListAND<FeatureSelector> selectorList11;
104  auto &sl11 = selectorList11.template get<FeatureSelector>();
105  sl11.select_on = 1;
106 
107  SelectorListAND<FeatureSelector> selectorList12;
108  auto &sl12 = selectorList12.template get<FeatureSelector>();
109  sl12.select_on = 2;
110 
111  // test that the feature value 1 is selected
112  BOOST_TEST(selectorList11(en1, o1));
113  // test that the feature value 2 is selected
114  BOOST_TEST(!selectorList12(en1, o1));
115 
116  // make a combined selector lsit
118  auto &s1 = o1List.get<FeatureSelector>();
119  s1.select_on = 1;
120  auto &so = o1List.get<NameSelector>();
121  so.select_on = "o";
122 
123  // test that the feature value 1 is selected
124  BOOST_TEST(o1List(en1, o1));
125 
126  // make a combined selector lsit
128  auto &s2 = o2List.template get<FeatureSelector>();
129  s2.select_on = 2;
130  so = o2List.template get<NameSelector>();
131  so.select_on = "o";
132 
133  // test that the feature value 1 is selected
134  BOOST_TEST(!o2List(en1, o1));
135 
136  // Pick ont he environment
137  EnvironmentSelector eselector1;
138  BOOST_TEST(eselector1(en1, o1));
139 }
140 
141 } // namespace Test
142 } // namespace Fatras