Belle II Software  release-08-01-10
CallIfApplicable.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 #include <tracking/trackFindingCDC/utilities/Functional.h>
9 
10 #include <gtest/gtest.h>
11 
12 using namespace Belle2;
13 using namespace TrackFindingCDC;
14 
15 namespace {
16  TEST(TrackFindingCDCTest, utilities_clearIfApplicable)
17  {
18  float f = 2;
19  std::vector<float> v{0, 1};
20  EXPECT_FALSE(v.empty());
21 
22  clearIfApplicable(f);
23  invokeIfApplicable(Clear(), v);
24 
25 
26  EXPECT_TRUE(v.empty());
27  EXPECT_EQ(2, f);
28  }
29 
30  struct Back {
31  template <class T>
32  const typename T::value_type& operator()(const T& container) const
33  {
34  return container.back();
35  }
36  };
37 
38  TEST(TrackFindingCDCTest, utilities_getIfApplicable)
39  {
40  const float f = 2;
41  const std::vector<float> v{0.0, 1.0};
42  EXPECT_FALSE(v.empty());
43 
44  // Test if the back getter works without the magic
45  Back back;
46  EXPECT_EQ(1.0, back(v));
47 
48  // Valid get case
49  EXPECT_EQ(1.0, Back()(v));
50  EXPECT_EQ(1.0, getIfApplicable<float>(Back(), v, -1.0));
51 
52  // Default case
53  EXPECT_EQ(-1.0, getIfApplicable<float>(Back(), f, -1.0));
54 
55 
56  }
57 }
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Abstract base class for different kinds of events.
Functor to get the .clear() from an abitrary objects.
Definition: Functional.h:338