Belle II Software development
sandBox4Testing.h
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 <framework/logging/Logger.h>
9#include <gtest/gtest.h>
10#include <vector>
11
12namespace Belle2 {
19 template <int Verbosity> class VerbosityClass {
20 public:
21 VerbosityClass() /*: state(Verbosity)*/ {}
22
23
26 {
27 double bla = 5;
28
30 }
31
33 static inline void GiveVerboseOutput(double& result) { /*state = */result++; }
34 protected:
35 };
36
37
39 class SandBox4TestingTest : public ::testing::Test {
40 public:
41
43 bool doStuffHere(std::vector<double> testVector = { 42})
44 {
45 if (testVector[0] == 42) return true;
46 return false;
47 }
48
49 protected:
50 };
51
53 TEST_F(SandBox4TestingTest, testingVerbosityViaTemplates)
54 {
55 VerbosityClass<4> class4;
56 VerbosityClass<1> class1;
57
58 class4.SomeCleverMethod();
59 class1.SomeCleverMethod();
60 }
61
63 TEST_F(SandBox4TestingTest, JustSomePlayingAroundWithfunction)
64 {
65 EXPECT_TRUE(doStuffHere());
66 EXPECT_FALSE(doStuffHere({23}));
67
68 if (doStuffHere() == false) {
69 B2WARNING("it didn't work!");
70 } else {
71 B2WARNING("yay, it worked!");
72 }
73 }
74
75
77 TEST_F(SandBox4TestingTest, TestIsNanAndIsInfBehavior)
78 {
79 EXPECT_TRUE(std::isinf(1. / 0.));
80 EXPECT_FALSE(std::isnan(1. / 0.));
81 EXPECT_TRUE(std::isnan(std::sqrt(-1)));
82 EXPECT_FALSE(std::isinf(std::sqrt(-1)));
83 EXPECT_TRUE(std::isnan(0. / 0.));
84 EXPECT_FALSE(std::isinf(0. / 0.));
85
86// EXPECT_FALSE(std::isnan(std::pow(0.,0.))); // this should be nan, but actually it is implementation dependent, therefore here we get for 0^0 = 1, which is mathematically not correct
87 EXPECT_FALSE(std::isinf(std::pow(0., 0.)));
88 }
90} // namespace
Testing autoAssignment of vectors for functions.
bool doStuffHere(std::vector< double > testVector={ 42})
just a small dummy-function to test the expected behavior
should behave differently for different verbosity-levels given - class
void SomeCleverMethod()
should behave differently for different verbosity-levels given - function
static void GiveVerboseOutput(double &result)
do nothing relevant here just needing a dummy functhion
Abstract base class for different kinds of events.