8#include <framework/utilities/Angle.h>
10#include <gtest/gtest.h>
16 double constexpr epsilon = 1e-7;
22 TestBaseAngle(
double angle,
double error) :
BaseAngle(angle, error) {};
25 const double angle = TMath::PiOver2();
26 const double error = TMath::PiOver4();
28 TestBaseAngle myBaseAngle(angle, error);
29 EXPECT_DOUBLE_EQ(angle, myBaseAngle.getAngle());
30 EXPECT_DOUBLE_EQ(error, myBaseAngle.getError());
31 EXPECT_DOUBLE_EQ(angle * TMath::RadToDeg(), myBaseAngle.getAngleInDeg());
32 EXPECT_DOUBLE_EQ(error * TMath::RadToDeg(), myBaseAngle.getErrorInDeg());
37 const double angle = 0.4;
38 const double error = 0.2;
41 EXPECT_FALSE(myThetaAngle.contains(
ThetaAngle(0., 0.)));
42 EXPECT_FALSE(myThetaAngle.contains(
ThetaAngle(1.6, 0.)));
43 EXPECT_TRUE(myThetaAngle.contains(
ThetaAngle(angle - error / 2, 0.)));
44 EXPECT_TRUE(myThetaAngle.contains(
ThetaAngle(angle + error / 2, 0.)));
46 EXPECT_FLOAT_EQ(TMath::PiOver2(),
ThetaAngle(TMath::Pi() + TMath::PiOver2(), 0.).getAngle());
49 TEST(Angle, PhiAngleIntervalNormalCase)
54 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(0., 0.)));
55 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi(), 0.)));
56 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.)));
57 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.)));
59 EXPECT_FLOAT_EQ(TMath::Pi(),
PhiAngle(TMath::TwoPi() + TMath::Pi(), 0.).getAngle());
62 TEST(Angle, PhiAngleIntervalBreaksZero)
64 const double angle = 0.1;
65 const double error = 0.3;
67 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 + epsilon, 0.)));
68 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 - epsilon, 0.)));
69 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() + epsilon, 0.)));
70 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() - epsilon, 0.)));
71 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.)));
72 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.)));
75 TEST(Angle, PhiAngleIntervalBreaksTwoPi)
77 const double angle = TMath::TwoPi() - 0.1;
78 const double error = 0.3;
80 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 + epsilon, 0.)));
81 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 - epsilon, 0.)));
82 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() + epsilon, 0.)));
83 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() - epsilon, 0.)));
84 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.)));
85 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.)));
88 TEST(Angle, PhiAngleNormalCase)
90 const double angle = TMath::Pi();
91 const double error = 0.0;
93 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(0 + epsilon, 0.2)));
94 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(0 - epsilon, 0.2)));
95 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
96 EXPECT_FALSE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
97 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.2)));
98 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.2)));
101 TEST(Angle, PhiAngleBreaksZero)
103 const double angle = 0.1;
104 const double error = 0.0;
106 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 + epsilon, 0.2)));
107 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 - epsilon, 0.2)));
108 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
109 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
110 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.2)));
111 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.2)));
114 TEST(Angle, PhiAngleBreaksTwoPi)
116 const double angle = TMath::TwoPi() - 0.1;
117 const double error = 0.0;
119 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 + epsilon, 0.2)));
120 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(0 - epsilon, 0.2)));
121 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() + epsilon, 0.2)));
122 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(TMath::TwoPi() - epsilon, 0.2)));
123 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle - error / 2, 0.2)));
124 EXPECT_TRUE(myPhiAngle.contains(
PhiAngle(angle + error / 2, 0.2)));
127 TEST(Angle, PhiAngleAndErrorBreakTwoPi)
129 const double angle = -0.0275 + TMath::TwoPi();
130 const double error = 3 * 0.0104;
132 EXPECT_FALSE(myPhiAngle.containsIn(
PhiAngle(2.6, 0), 1));
Class to compare if two angles are compatible withing a given error range.
Abstract base class for different kinds of events.