File indexing completed on 2025-08-03 08:09:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #define BOOST_TEST_MODULE AbortList Tests
0011
0012 #include <boost/test/included/unit_test.hpp>
0013
0014
0015 #include <boost/test/data/test_case.hpp>
0016
0017
0018 #include <boost/test/output_test_stream.hpp>
0019
0020
0021 #include "Fatras/Kernel/SelectorList.hpp"
0022
0023 namespace bdata = boost::unit_test::data;
0024 namespace tt = boost::test_tools;
0025
0026 namespace Fatras {
0027
0028 namespace Test {
0029
0030
0031 struct Object {
0032 int feature = 0;
0033 std::string name = "";
0034 };
0035
0036 struct Environment {
0037 int pickFeature = 1;
0038 };
0039
0040
0041
0042 struct FeatureSelector {
0043
0044 int select_on = 0;
0045
0046
0047 template <typename detector_t, typename particle_t>
0048 bool operator()(const detector_t &, const particle_t &object) const {
0049 return object.feature == select_on;
0050 }
0051 };
0052
0053
0054
0055 struct NameSelector {
0056
0057 std::string select_on = "";
0058
0059
0060 template <typename detector_t, typename particle_t>
0061 bool operator()(const detector_t &environment,
0062 const particle_t &object) const {
0063 return object.name == select_on;
0064 }
0065 };
0066
0067
0068
0069 struct EnvironmentSelector {
0070
0071
0072 template <typename detector_t, typename particle_t>
0073 bool operator()(const detector_t &environmet,
0074 const particle_t &object) const {
0075 return object.feature == environmet.pickFeature;
0076 }
0077 };
0078
0079
0080 BOOST_AUTO_TEST_CASE(SelectorList_test) {
0081
0082
0083 Object o1;
0084 o1.name = "o";
0085 o1.feature = 1;
0086
0087 Environment en1;
0088 en1.pickFeature = 1;
0089
0090
0091 FeatureSelector selector1;
0092 selector1.select_on = 1;
0093
0094 FeatureSelector selector2;
0095 selector2.select_on = 2;
0096
0097
0098 BOOST_TEST(selector1(en1, o1));
0099
0100 BOOST_TEST(!selector2(en1, o1));
0101
0102
0103 SelectorListAND<FeatureSelector> selectorList11;
0104 auto &sl11 = selectorList11.template get<FeatureSelector>();
0105 sl11.select_on = 1;
0106
0107 SelectorListAND<FeatureSelector> selectorList12;
0108 auto &sl12 = selectorList12.template get<FeatureSelector>();
0109 sl12.select_on = 2;
0110
0111
0112 BOOST_TEST(selectorList11(en1, o1));
0113
0114 BOOST_TEST(!selectorList12(en1, o1));
0115
0116
0117 SelectorListAND<FeatureSelector, NameSelector> o1List;
0118 auto &s1 = o1List.get<FeatureSelector>();
0119 s1.select_on = 1;
0120 auto &so = o1List.get<NameSelector>();
0121 so.select_on = "o";
0122
0123
0124 BOOST_TEST(o1List(en1, o1));
0125
0126
0127 SelectorListAND<FeatureSelector, NameSelector> o2List;
0128 auto &s2 = o2List.template get<FeatureSelector>();
0129 s2.select_on = 2;
0130 so = o2List.template get<NameSelector>();
0131 so.select_on = "o";
0132
0133
0134 BOOST_TEST(!o2List(en1, o1));
0135
0136
0137 EnvironmentSelector eselector1;
0138 BOOST_TEST(eselector1(en1, o1));
0139 }
0140
0141 }
0142 }