1 #include <marnav/ais/rate_of_turn.hpp>
2 #include <gtest/gtest.h>
6 template <class T
> constexpr T
sqr(T 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
)
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
;
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;
59 EXPECT_TRUE(r
.available());
63 EXPECT_FALSE(r
.available());
67 TEST_F(Test_ais_rate_of_turn
, not_turning
)
70 const rate_of_turn::value_type val
= 1;
72 EXPECT_FALSE(r
.is_not_turning());
75 const rate_of_turn::value_type val
= rate_of_turn::not_turning
;
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;
86 EXPECT_FALSE(r
.is_more_5deg30s_right());
89 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_right
;
91 EXPECT_TRUE(r
.is_more_5deg30s_right());
94 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_right
;
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
;
101 EXPECT_FALSE(r
.is_more_5deg30s_right());
104 const rate_of_turn::value_type val
= rate_of_turn::not_turning
;
106 EXPECT_FALSE(r
.is_more_5deg30s_right());
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;
119 EXPECT_FALSE(r
.is_more_5deg30s_left());
122 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_right
;
124 EXPECT_FALSE(r
.is_more_5deg30s_left());
127 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_left
;
129 EXPECT_TRUE(r
.is_more_5deg30s_left());
132 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_left
;
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
;
139 EXPECT_FALSE(r
.is_more_5deg30s_left());
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
;
152 EXPECT_ANY_THROW(r
.value());
155 const rate_of_turn::value_type val
= rate_of_turn::more_5deg_per_30s_left
;
157 EXPECT_ANY_THROW(r
.value());
161 EXPECT_ANY_THROW(r
.value());
164 const rate_of_turn::value_type val
= rate_of_turn::not_turning
;
166 EXPECT_NEAR(r
.value(), 0.0, 1.0e-5);
169 const rate_of_turn::value_type val
= 126;
171 EXPECT_NEAR(r
.value(), 708, 1.0);
174 const rate_of_turn::value_type val
= -126;
176 EXPECT_NEAR(r
.value(), -708.0, 1.0);
179 const rate_of_turn::value_type val
= 1;
181 EXPECT_NEAR(r
.value(), sqr(1.0 / 4.733), 0.001);