Build: update docker build scripts
[marnav.git] / test / ais / Test_ais_rate_of_turn.cpp
blob3b61ce25ed11a00373b81b443c592756e7db6d8c
1 #include <marnav/ais/rate_of_turn.hpp>
2 #include <gtest/gtest.h>
4 namespace
6 template <class T> constexpr T sqr(T x)
8 return x * x;
11 using marnav::ais::rate_of_turn;
13 class Test_ais_rate_of_turn : public ::testing::Test
17 TEST_F(Test_ais_rate_of_turn, construction_default)
19 rate_of_turn r;
20 EXPECT_EQ(rate_of_turn::no_information_available, r.raw());
23 TEST_F(Test_ais_rate_of_turn, construction_explicit_raw_data)
25 const rate_of_turn::value_type a = rate_of_turn::no_information_available;
26 rate_of_turn r(a);
27 EXPECT_EQ(rate_of_turn::no_information_available, r.raw());
30 TEST_F(Test_ais_rate_of_turn, construction_angle_throwing)
32 EXPECT_ANY_THROW(rate_of_turn(1000.0));
33 EXPECT_ANY_THROW(rate_of_turn(714.35)); // approx. the nearest value to +0.0 that throws
34 EXPECT_ANY_THROW(rate_of_turn(-1000.0));
35 EXPECT_ANY_THROW(rate_of_turn(-714.35)); // approx. the nearest value to -0.0 that throws
38 TEST_F(Test_ais_rate_of_turn, construction_angle_not_turning)
40 const rate_of_turn r(0.0);
41 EXPECT_TRUE(r.is_not_turning());
44 TEST_F(Test_ais_rate_of_turn, construction_angle_read_back)
46 static constexpr double data[] = {1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 500.0};
48 for (const auto val : data) {
49 const rate_of_turn r(val);
50 EXPECT_NEAR(r.value(), val, 2.0);
54 TEST_F(Test_ais_rate_of_turn, available)
57 const rate_of_turn::value_type val = 1;
58 rate_of_turn r(val);
59 EXPECT_TRUE(r.available());
62 rate_of_turn r;
63 EXPECT_FALSE(r.available());
67 TEST_F(Test_ais_rate_of_turn, not_turning)
70 const rate_of_turn::value_type val = 1;
71 rate_of_turn r(val);
72 EXPECT_FALSE(r.is_not_turning());
75 const rate_of_turn::value_type val = rate_of_turn::not_turning;
76 rate_of_turn r(val);
77 EXPECT_TRUE(r.is_not_turning());
81 TEST_F(Test_ais_rate_of_turn, more_5deg_per_30s_right)
84 const rate_of_turn::value_type val = 1;
85 rate_of_turn r(val);
86 EXPECT_FALSE(r.is_more_5deg30s_right());
89 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
90 rate_of_turn r(val);
91 EXPECT_TRUE(r.is_more_5deg30s_right());
94 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
95 rate_of_turn r(val);
96 EXPECT_EQ(rate_of_turn::more_5deg_per_30s_right, r.raw());
99 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
100 rate_of_turn r(val);
101 EXPECT_FALSE(r.is_more_5deg30s_right());
104 const rate_of_turn::value_type val = rate_of_turn::not_turning;
105 rate_of_turn r(val);
106 EXPECT_FALSE(r.is_more_5deg30s_right());
109 rate_of_turn r;
110 EXPECT_FALSE(r.is_more_5deg30s_right());
114 TEST_F(Test_ais_rate_of_turn, more_5deg_per_30s_left)
117 const rate_of_turn::value_type val = 1;
118 rate_of_turn r(val);
119 EXPECT_FALSE(r.is_more_5deg30s_left());
122 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
123 rate_of_turn r(val);
124 EXPECT_FALSE(r.is_more_5deg30s_left());
127 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
128 rate_of_turn r(val);
129 EXPECT_TRUE(r.is_more_5deg30s_left());
132 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
133 rate_of_turn r(val);
134 EXPECT_EQ(rate_of_turn::more_5deg_per_30s_left, r.raw());
137 const rate_of_turn::value_type val = rate_of_turn::not_turning;
138 rate_of_turn r(val);
139 EXPECT_FALSE(r.is_more_5deg30s_left());
142 rate_of_turn r;
143 EXPECT_FALSE(r.is_more_5deg30s_left());
147 TEST_F(Test_ais_rate_of_turn, value)
150 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
151 rate_of_turn r(val);
152 EXPECT_ANY_THROW(r.value());
155 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
156 rate_of_turn r(val);
157 EXPECT_ANY_THROW(r.value());
160 rate_of_turn r;
161 EXPECT_ANY_THROW(r.value());
164 const rate_of_turn::value_type val = rate_of_turn::not_turning;
165 rate_of_turn r(val);
166 EXPECT_NEAR(r.value(), 0.0, 1.0e-5);
169 const rate_of_turn::value_type val = 126;
170 rate_of_turn r(val);
171 EXPECT_NEAR(r.value(), 708, 1.0);
174 const rate_of_turn::value_type val = -126;
175 rate_of_turn r(val);
176 EXPECT_NEAR(r.value(), -708.0, 1.0);
179 const rate_of_turn::value_type val = 1;
180 rate_of_turn r(val);
181 EXPECT_NEAR(r.value(), sqr(1.0 / 4.733), 0.001);