NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / test / geo / Test_geo_angle.cpp
blobf283394250c9d072a49befc49e67e5d6e10572bd
1 #include <marnav/geo/angle.hpp>
2 #include <gtest/gtest.h>
4 namespace
7 using namespace marnav;
9 class Test_geo_angle : public ::testing::Test
13 TEST_F(Test_geo_angle, construction_default)
15 geo::angle{};
18 TEST_F(Test_geo_angle, construction_value)
20 geo::angle{1.0};
23 TEST_F(Test_geo_angle, angle_type_check)
25 EXPECT_TRUE(std::is_move_constructible<geo::angle>::value);
26 EXPECT_TRUE(std::is_nothrow_move_constructible<geo::angle>::value);
27 EXPECT_TRUE(std::is_move_assignable<geo::angle>::value);
28 EXPECT_TRUE(std::is_nothrow_move_assignable<geo::angle>::value);
29 EXPECT_TRUE(std::is_copy_constructible<geo::angle>::value);
30 EXPECT_TRUE(std::is_copy_assignable<geo::angle>::value);
31 EXPECT_TRUE(std::is_nothrow_copy_assignable<geo::angle>::value);
34 TEST_F(Test_geo_angle, latitude_type_check)
36 EXPECT_TRUE(std::is_move_constructible<geo::latitude>::value);
37 EXPECT_TRUE(std::is_nothrow_move_constructible<geo::latitude>::value);
38 EXPECT_TRUE(std::is_move_assignable<geo::latitude>::value);
39 EXPECT_TRUE(std::is_nothrow_move_assignable<geo::latitude>::value);
40 EXPECT_TRUE(std::is_copy_constructible<geo::latitude>::value);
41 EXPECT_TRUE(std::is_copy_assignable<geo::latitude>::value);
42 EXPECT_TRUE(std::is_nothrow_copy_assignable<geo::latitude>::value);
45 TEST_F(Test_geo_angle, longitude_type_check)
47 EXPECT_TRUE(std::is_move_constructible<geo::longitude>::value);
48 EXPECT_TRUE(std::is_nothrow_move_constructible<geo::longitude>::value);
49 EXPECT_TRUE(std::is_move_assignable<geo::longitude>::value);
50 EXPECT_TRUE(std::is_nothrow_move_assignable<geo::longitude>::value);
51 EXPECT_TRUE(std::is_copy_constructible<geo::longitude>::value);
52 EXPECT_TRUE(std::is_copy_assignable<geo::longitude>::value);
53 EXPECT_TRUE(std::is_nothrow_copy_assignable<geo::longitude>::value);
56 TEST_F(Test_geo_angle, hemisphere)
58 EXPECT_NEAR(30, (geo::latitude{30, 0, 0, geo::latitude::hemisphere::north}.get()), 1e-5);
59 EXPECT_NEAR(-30, (geo::latitude{30, 0, 0, geo::latitude::hemisphere::south}.get()), 1e-5);
60 EXPECT_NEAR(30, (geo::longitude{30, 0, 0, geo::longitude::hemisphere::east}.get()), 1e-5);
61 EXPECT_NEAR(-30, (geo::longitude{30, 0, 0, geo::longitude::hemisphere::west}.get()), 1e-5);
64 TEST_F(Test_geo_angle, comparison)
66 geo::angle a{1.0};
67 geo::angle b{1.0};
68 geo::angle c{2.0};
70 EXPECT_TRUE(a == a);
71 EXPECT_TRUE(b == b);
72 EXPECT_TRUE(c == c);
74 EXPECT_TRUE(a == b);
75 EXPECT_TRUE(b == a);
76 EXPECT_FALSE(a == c);
77 EXPECT_FALSE(c == a);
78 EXPECT_FALSE(b == c);
79 EXPECT_FALSE(c == b);
82 TEST_F(Test_geo_angle, degrees)
84 EXPECT_EQ(0u, geo::angle{0.0}.degrees());
85 EXPECT_EQ(1u, geo::angle{1.0}.degrees());
86 EXPECT_EQ(2u, geo::angle{2.0}.degrees());
87 EXPECT_EQ(10u, geo::angle{10.0}.degrees());
90 TEST_F(Test_geo_angle, minutes)
92 EXPECT_EQ(0u, geo::angle{0.0}.minutes());
93 EXPECT_EQ(30u, geo::angle{0.5}.minutes());
96 TEST_F(Test_geo_angle, seconds)
98 EXPECT_NEAR(0.00, geo::angle{0.0000}.seconds(), 1e-4);
99 EXPECT_NEAR(0.72, geo::angle{0.0002}.seconds(), 1e-4);
100 EXPECT_NEAR(1.80, geo::angle{0.0005}.seconds(), 1e-4);
101 EXPECT_NEAR(3.60, geo::angle{0.0010}.seconds(), 1e-4);
104 TEST_F(Test_geo_angle, latitude_invalid_value)
106 EXPECT_ANY_THROW(geo::latitude{91.0});
109 TEST_F(Test_geo_angle, longitude_invalid_value)
111 EXPECT_ANY_THROW(geo::longitude{181.0});
114 TEST_F(Test_geo_angle, latitude_hemisphere)
116 EXPECT_EQ(geo::latitude::hemisphere::north, geo::latitude{+1.0}.hem());
117 EXPECT_EQ(geo::latitude::hemisphere::south, geo::latitude{-1.0}.hem());
120 TEST_F(Test_geo_angle, latitude_forced_hemisphere)
122 EXPECT_EQ(geo::latitude::hemisphere::north,
123 (geo::latitude{+1.0, geo::latitude::hemisphere::north}.hem()));
124 EXPECT_EQ(geo::latitude::hemisphere::south,
125 (geo::latitude{+1.0, geo::latitude::hemisphere::south}.hem()));
126 EXPECT_EQ(geo::latitude::hemisphere::north,
127 (geo::latitude{-1.0, geo::latitude::hemisphere::north}.hem()));
128 EXPECT_EQ(geo::latitude::hemisphere::south,
129 (geo::latitude{-1.0, geo::latitude::hemisphere::south}.hem()));
132 TEST_F(Test_geo_angle, longitude_hemisphere)
134 EXPECT_EQ(geo::longitude::hemisphere::west, geo::longitude{-1.0}.hem());
135 EXPECT_EQ(geo::longitude::hemisphere::east, geo::longitude{+1.0}.hem());
138 TEST_F(Test_geo_angle, longitude_forced_hemisphere)
140 EXPECT_EQ(geo::longitude::hemisphere::east,
141 (geo::longitude{+1.0, geo::longitude::hemisphere::east}.hem()));
142 EXPECT_EQ(geo::longitude::hemisphere::west,
143 (geo::longitude{+1.0, geo::longitude::hemisphere::west}.hem()));
144 EXPECT_EQ(geo::longitude::hemisphere::east,
145 (geo::longitude{-1.0, geo::longitude::hemisphere::east}.hem()));
146 EXPECT_EQ(geo::longitude::hemisphere::west,
147 (geo::longitude{-1.0, geo::longitude::hemisphere::west}.hem()));
150 TEST_F(Test_geo_angle, latitude_literal_north)
152 using namespace marnav::geo;
154 const latitude expected{12.34};
155 const latitude t = 12.34_lat;
157 EXPECT_DOUBLE_EQ(expected, t);
158 EXPECT_EQ(geo::latitude::hemisphere::north, t.hem());
161 TEST_F(Test_geo_angle, latitude_literal_explicit_north)
163 using namespace marnav::geo;
165 const latitude expected{12.34};
166 const latitude t = 12.34_north;
168 EXPECT_DOUBLE_EQ(expected, t);
169 EXPECT_EQ(geo::latitude::hemisphere::north, t.hem());
172 TEST_F(Test_geo_angle, latitude_literal_south)
174 using namespace marnav::geo;
176 const latitude expected{-12.34};
177 const latitude t = -12.34_lat;
179 EXPECT_DOUBLE_EQ(expected, t);
180 EXPECT_EQ(geo::latitude::hemisphere::south, t.hem());
183 TEST_F(Test_geo_angle, latitude_literal_explicit_south)
185 using namespace marnav::geo;
187 const latitude expected{-12.34};
188 const latitude t = 12.34_south;
190 EXPECT_DOUBLE_EQ(expected, t);
191 EXPECT_EQ(geo::latitude::hemisphere::south, t.hem());
194 TEST_F(Test_geo_angle, longitude_literal_east)
196 using namespace marnav::geo;
198 const longitude expected{123.45};
199 const longitude t = 123.45_lon;
201 EXPECT_DOUBLE_EQ(expected, t);
202 EXPECT_EQ(geo::longitude::hemisphere::east, t.hem());
205 TEST_F(Test_geo_angle, longitude_literal_explicit_east)
207 using namespace marnav::geo;
209 const longitude expected{123.45};
210 const longitude t = 123.45_east;
212 EXPECT_DOUBLE_EQ(expected, t);
213 EXPECT_EQ(geo::longitude::hemisphere::east, t.hem());
216 TEST_F(Test_geo_angle, longitude_literal_west)
218 using namespace marnav::geo;
220 const longitude expected{-123.45};
221 const longitude t = -123.45_lon;
223 EXPECT_DOUBLE_EQ(expected, t);
224 EXPECT_EQ(geo::longitude::hemisphere::west, t.hem());
227 TEST_F(Test_geo_angle, longitude_literal_explicit_west)
229 using namespace marnav::geo;
231 const longitude expected{-123.45};
232 const longitude t = 123.45_west;
234 EXPECT_DOUBLE_EQ(expected, t);
235 EXPECT_EQ(geo::longitude::hemisphere::west, t.hem());