Belle II Software  release-05-01-25
CallIfApplicable.test.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2014 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost <oliver.frost@desy.de> *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <tracking/trackFindingCDC/utilities/Functional.h>
11 
12 #include <gtest/gtest.h>
13 
14 using namespace Belle2;
15 using namespace TrackFindingCDC;
16 
17 namespace {
18  TEST(TrackFindingCDCTest, utilities_clearIfApplicable)
19  {
20  float f = 2;
21  std::vector<float> v{0, 1};
22  EXPECT_FALSE(v.empty());
23 
24  clearIfApplicable(f);
25  invokeIfApplicable(Clear(), v);
26 
27 
28  EXPECT_TRUE(v.empty());
29  EXPECT_EQ(2, f);
30  }
31 
32  struct Back {
33  template <class T>
34  const typename T::value_type& operator()(const T& container) const
35  {
36  return container.back();
37  }
38  };
39 
40  TEST(TrackFindingCDCTest, utilities_getIfApplicable)
41  {
42  const float f = 2;
43  const std::vector<float> v{0.0, 1.0};
44  EXPECT_FALSE(v.empty());
45 
46  // Test if the back getter works without the magic
47  Back back;
48  EXPECT_EQ(1.0, back(v));
49 
50  // Valid get case
51  EXPECT_EQ(1.0, Back()(v));
52  EXPECT_EQ(1.0, getIfApplicable<float>(Back(), v, -1.0));
53 
54  // Default case
55  EXPECT_EQ(-1.0, getIfApplicable<float>(Back(), f, -1.0));
56 
57 
58  }
59 }
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TEST
TEST(TestgetDetectorRegion, TestgetDetectorRegion)
Test Constructors.
Definition: utilityFunctions.cc:18