Belle II Software development
SingleMatchSelector.test.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <tracking/trackFindingCDC/collectors/selectors/SingleMatchSelector.h>
10
11#include <tracking/trackFindingCDC/numerics/WeightComperator.h>
12
13#include <gtest/gtest.h>
14
15using namespace Belle2;
16using namespace TrackFindingCDC;
17
18namespace {
20 TEST(TrackFindingCDCTest, single_match_selector)
21 {
23
24 int a = 1, b = 2;
25 double c = 3, d = 4, e = 5;
26
27 std::vector<WeightedRelation<int, const double>> relations = {
32 };
33
34 std::sort(relations.begin(), relations.end());
35 selector.apply(relations);
36
37 std::sort(relations.begin(), relations.end(), GreaterWeight());
38
39 ASSERT_EQ(relations.size(), 2);
40 ASSERT_EQ(relations[0].getWeight(), 1.0);
41 ASSERT_EQ(relations[0].getFrom(), &a);
42 ASSERT_EQ(relations[0].getTo(), &d);
43 ASSERT_EQ(relations[1].getWeight(), 0.6);
44 ASSERT_EQ(relations[1].getFrom(), &b);
45 ASSERT_EQ(relations[1].getTo(), &e);
46
47 }
48
50 TEST(TrackFindingCDCTest, single_best_match_selector)
51 {
53 selector.setUseOnlySingleBestCandidate(false);
54
55 int a = 1, b = 2, c = 3;
56 double d = 4, e = 5, f = 6;
57
58 std::vector<WeightedRelation<int, const double>> relations = {
64 };
65
66 std::sort(relations.begin(), relations.end());
67 selector.apply(relations);
68
69 std::sort(relations.begin(), relations.end(), GreaterWeight());
70
71 ASSERT_EQ(relations.size(), 3);
72 ASSERT_EQ(relations[0].getWeight(), 1.1);
73 ASSERT_EQ(relations[0].getFrom(), &a);
74 ASSERT_EQ(relations[0].getTo(), &d);
75 ASSERT_EQ(relations[1].getWeight(), 1.0);
76 ASSERT_EQ(relations[1].getFrom(), &a);
77 ASSERT_EQ(relations[1].getTo(), &e);
78 ASSERT_EQ(relations[2].getWeight(), 0.6);
79 ASSERT_EQ(relations[2].getFrom(), &b);
80 ASSERT_EQ(relations[2].getTo(), &f);
81 }
82
84 struct CustomComparer {
85 bool operator()(const double* lhs, const double* rhs) const
86 {
87 return (static_cast<int>(*lhs) % 2) < (static_cast<int>(*rhs) % 2);
88 }
89 };
90
92 TEST(TrackFindingCDCTest, single_match_selector_with_comparer)
93 {
95
96 int a = 1, b = 2;
97 double c = 3, d = 4, e = 5;
98
99 std::vector<WeightedRelation<int, const double>> relations = {
104 };
105
106 std::sort(relations.begin(), relations.end());
107 selector.apply(relations);
108
109 std::sort(relations.begin(), relations.end(), GreaterWeight());
110
111 ASSERT_EQ(relations.size(), 1);
112 ASSERT_EQ(relations[0].getWeight(), 1.0);
113 ASSERT_EQ(relations[0].getFrom(), &a);
114 ASSERT_EQ(relations[0].getTo(), &d);
115 }
116}
Selector to remove all relations in the list, which share the same collection item - except one in ca...
Type for two related objects with a weight.
Abstract base class for different kinds of events.
Functor factory turning a binary functor and two functors into a new functor which executes the binar...
Definition: Functional.h:127