11 #include <tracking/trackFindingCDC/collectors/selectors/SingleMatchSelector.h>
13 #include <tracking/trackFindingCDC/numerics/WeightComperator.h>
15 #include <gtest/gtest.h>
18 using namespace TrackFindingCDC;
22 TEST(TrackFindingCDCTest, single_match_selector)
24 SingleMatchSelector<int, double> selector;
27 double c = 3, d = 4,
e = 5;
29 std::vector<WeightedRelation<int, const double>> relations = {
30 WeightedRelation<int, const double>(&a, 1.1, &c),
31 WeightedRelation<int, const double>(&a, 1.0, &d),
32 WeightedRelation<int, const double>(&b, 0.8, &c),
33 WeightedRelation<int, const double>(&b, 0.6, &e)
36 std::sort(relations.begin(), relations.end());
37 selector.apply(relations);
39 std::sort(relations.begin(), relations.end(), GreaterWeight());
41 ASSERT_EQ(relations.size(), 2);
42 ASSERT_EQ(relations[0].getWeight(), 1.0);
43 ASSERT_EQ(relations[0].getFrom(), &a);
44 ASSERT_EQ(relations[0].getTo(), &d);
45 ASSERT_EQ(relations[1].getWeight(), 0.6);
46 ASSERT_EQ(relations[1].getFrom(), &b);
47 ASSERT_EQ(relations[1].getTo(), &e);
52 TEST(TrackFindingCDCTest, single_best_match_selector)
54 SingleMatchSelector<int, double> selector;
55 selector.setUseOnlySingleBestCandidate(
false);
57 int a = 1, b = 2, c = 3;
58 double d = 4,
e = 5, f = 6;
60 std::vector<WeightedRelation<int, const double>> relations = {
61 WeightedRelation<int, const double>(&a, 1.1, &d),
62 WeightedRelation<int, const double>(&a, 1.0, &e),
63 WeightedRelation<int, const double>(&b, 0.8, &d),
64 WeightedRelation<int, const double>(&b, 0.6, &f),
65 WeightedRelation<int, const double>(&c, 0.6, &d),
68 std::sort(relations.begin(), relations.end());
69 selector.apply(relations);
71 std::sort(relations.begin(), relations.end(), GreaterWeight());
73 ASSERT_EQ(relations.size(), 3);
74 ASSERT_EQ(relations[0].getWeight(), 1.1);
75 ASSERT_EQ(relations[0].getFrom(), &a);
76 ASSERT_EQ(relations[0].getTo(), &d);
77 ASSERT_EQ(relations[1].getWeight(), 1.0);
78 ASSERT_EQ(relations[1].getFrom(), &a);
79 ASSERT_EQ(relations[1].getTo(), &e);
80 ASSERT_EQ(relations[2].getWeight(), 0.6);
81 ASSERT_EQ(relations[2].getFrom(), &b);
82 ASSERT_EQ(relations[2].getTo(), &f);
86 struct CustomComparer {
87 bool operator()(
const double* lhs,
const double* rhs)
const
89 return (
static_cast<int>(*lhs) % 2) < (
static_cast<int>(*rhs) % 2);
94 TEST(TrackFindingCDCTest, single_match_selector_with_comparer)
96 SingleMatchSelector<int, double, CustomComparer> selector;
99 double c = 3, d = 4,
e = 5;
101 std::vector<WeightedRelation<int, const double>> relations = {
102 WeightedRelation<int, const double>(&a, 1.1, &c),
103 WeightedRelation<int, const double>(&a, 1.0, &d),
104 WeightedRelation<int, const double>(&b, 0.8, &c),
105 WeightedRelation<int, const double>(&b, 0.6, &e)
108 std::sort(relations.begin(), relations.end());
109 selector.apply(relations);
111 std::sort(relations.begin(), relations.end(), GreaterWeight());
113 ASSERT_EQ(relations.size(), 1);
114 ASSERT_EQ(relations[0].getWeight(), 1.0);
115 ASSERT_EQ(relations[0].getFrom(), &a);
116 ASSERT_EQ(relations[0].getTo(), &d);