angles.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Includes
13 *****************************************************************************/
14 
15 #include <gtest/gtest.h>
16 #include <ecl/math/constants.hpp>
17 #include "../../include/ecl/geometry/angle.hpp"
18 
19 /*****************************************************************************
20 ** Using
21 *****************************************************************************/
22 
23 using ecl::pi;
24 using ecl::Angle;
25 using ecl::wrap_angle;
26 
27 /*****************************************************************************
28 ** Tests
29 *****************************************************************************/
30 
31 TEST(AngleTests,setters) {
32  Angle<double> angle;
33  double d = angle; // default
34  EXPECT_EQ(0.0,d);
35  angle = Angle<double>::Degrees(45.0);
36  d = angle;
37  EXPECT_GT(0.786,d); // Allow some roundoff error here
38  EXPECT_LT(0.785,d);
39  angle = Angle<double>::Radians(0.3);
40  d = angle;
41  EXPECT_EQ(0.3,d);
42  Angle<float> angle_f;
43  float f = angle_f; // default
44  EXPECT_EQ(0.0,f);
45  angle_f = Angle<float>::Degrees(45.0);
46  f = angle_f;
47  EXPECT_GT(0.786,f); // Allow some roundoff error here
48  EXPECT_LT(0.785,f);
49  angle_f = Angle<float>::Radians(0.3);
50  f = angle_f;
51  EXPECT_EQ(0.3,d);
52 }
53 
54 TEST(AngleTests,conversions) {
55  Angle<double> angle(0.3);
56  double d = angle.degrees();
57  EXPECT_GT(17.19,d); // Allow some roundoff error here
58  EXPECT_LT(17.18,d);
59  Angle<float> angle_f(0.3);
60  float f = angle.degrees();
61  EXPECT_GT(17.19,f); // Allow some roundoff error here
62  EXPECT_LT(17.18,f);
63 }
64 
65 TEST(AngleTests,wrap) {
66  double angle = 2*pi+0.1;
67  wrap_angle(angle);
68  EXPECT_GT(0.11,angle); // Allow some roundoff error here
69  EXPECT_LT(0.09,angle);
70  angle = 2*pi+0.1;
71  double wa = wrap_angle(angle);
72  EXPECT_GT(0.11,wa); // Allow some roundoff error here
73  EXPECT_LT(0.09,wa);
74  float angle_f = 2*pi+0.1;
75  wrap_angle(angle_f);
76  EXPECT_GT(0.11,angle_f); // Allow some roundoff error here
77  EXPECT_LT(0.09,angle_f);
78  angle_f = 2*pi+0.1;
79  float wa_f = wrap_angle(angle_f);
80  EXPECT_GT(0.11,wa_f); // Allow some roundoff error here
81  EXPECT_LT(0.09,wa_f);
82 }
83 
84 TEST(AngleTests,assignment) {
85  Angle<double> angle;
86  angle = 0.3;
87  double d = angle;
88  EXPECT_GT(0.31,d); // Allow some roundoff error here
89  EXPECT_LT(0.29,d);
90  Angle<float> angle_f;
91  angle_f = 0.3;
92  float f = angle_f;
93  EXPECT_GT(0.31,f); // Allow some roundoff error here
94  EXPECT_LT(0.29,f);
95 }
96 
97 // operator tests
98 
99 /*****************************************************************************
100 ** Main program
101 *****************************************************************************/
102 
103 int main(int argc, char **argv) {
104 
105  testing::InitGoogleTest(&argc,argv);
106  return RUN_ALL_TESTS();
107 }
108 
109 
int main(int argc, char **argv)
Definition: angles.cpp:103
double const pi
ecl_geometry_PUBLIC const float & wrap_angle(float &angle)
Wrap the angle on -pi,pi (float types).
Definition: angle.cpp:29
Parent template definition for angles.
Definition: angle.hpp:113
TEST(AngleTests, setters)
Definition: angles.cpp:31
void f(int i) ecl_debug_throw_decl(StandardException)


ecl_geometry
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:37