NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / test / ais / Test_ais_rate_of_turn.cpp
blobed80ca6902abde23ed31df5635522714e5123171
1 #include <marnav/ais/rate_of_turn.hpp>
2 #include <gtest/gtest.h>
4 namespace
6 template <class T>
7 constexpr T sqr(T x)
9 return x * x;
12 using marnav::ais::rate_of_turn;
14 class Test_ais_rate_of_turn : public ::testing::Test
18 TEST_F(Test_ais_rate_of_turn, construction_default)
20 rate_of_turn r;
21 EXPECT_EQ(rate_of_turn::no_information_available, r.raw());
24 TEST_F(Test_ais_rate_of_turn, construction_explicit_raw_data)
26 const rate_of_turn::value_type a = rate_of_turn::no_information_available;
27 rate_of_turn r(a);
28 EXPECT_EQ(rate_of_turn::no_information_available, r.raw());
31 TEST_F(Test_ais_rate_of_turn, construction_angle_throwing)
33 EXPECT_ANY_THROW(rate_of_turn(1000.0));
34 EXPECT_ANY_THROW(rate_of_turn(714.35)); // approx. the nearest value to +0.0 that throws
35 EXPECT_ANY_THROW(rate_of_turn(-1000.0));
36 EXPECT_ANY_THROW(rate_of_turn(-714.35)); // approx. the nearest value to -0.0 that throws
39 TEST_F(Test_ais_rate_of_turn, construction_angle_not_turning)
41 const rate_of_turn r(0.0);
42 EXPECT_TRUE(r.is_not_turning());
45 TEST_F(Test_ais_rate_of_turn, construction_angle_read_back)
47 static constexpr double data[] = {1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 500.0};
49 for (const auto val : data) {
50 const rate_of_turn r(val);
51 EXPECT_NEAR(r.value(), val, 2.0);
55 TEST_F(Test_ais_rate_of_turn, available)
58 const rate_of_turn::value_type val = 1;
59 rate_of_turn r(val);
60 EXPECT_TRUE(r.available());
63 rate_of_turn r;
64 EXPECT_FALSE(r.available());
68 TEST_F(Test_ais_rate_of_turn, not_turning)
71 const rate_of_turn::value_type val = 1;
72 rate_of_turn r(val);
73 EXPECT_FALSE(r.is_not_turning());
76 const rate_of_turn::value_type val = rate_of_turn::not_turning;
77 rate_of_turn r(val);
78 EXPECT_TRUE(r.is_not_turning());
82 TEST_F(Test_ais_rate_of_turn, more_5deg_per_30s_right)
85 const rate_of_turn::value_type val = 1;
86 rate_of_turn r(val);
87 EXPECT_FALSE(r.is_more_5deg30s_right());
90 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
91 rate_of_turn r(val);
92 EXPECT_TRUE(r.is_more_5deg30s_right());
95 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
96 rate_of_turn r(val);
97 EXPECT_EQ(rate_of_turn::more_5deg_per_30s_right, r.raw());
100 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
101 rate_of_turn r(val);
102 EXPECT_FALSE(r.is_more_5deg30s_right());
105 const rate_of_turn::value_type val = rate_of_turn::not_turning;
106 rate_of_turn r(val);
107 EXPECT_FALSE(r.is_more_5deg30s_right());
110 rate_of_turn r;
111 EXPECT_FALSE(r.is_more_5deg30s_right());
115 TEST_F(Test_ais_rate_of_turn, more_5deg_per_30s_left)
118 const rate_of_turn::value_type val = 1;
119 rate_of_turn r(val);
120 EXPECT_FALSE(r.is_more_5deg30s_left());
123 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
124 rate_of_turn r(val);
125 EXPECT_FALSE(r.is_more_5deg30s_left());
128 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
129 rate_of_turn r(val);
130 EXPECT_TRUE(r.is_more_5deg30s_left());
133 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
134 rate_of_turn r(val);
135 EXPECT_EQ(rate_of_turn::more_5deg_per_30s_left, r.raw());
138 const rate_of_turn::value_type val = rate_of_turn::not_turning;
139 rate_of_turn r(val);
140 EXPECT_FALSE(r.is_more_5deg30s_left());
143 rate_of_turn r;
144 EXPECT_FALSE(r.is_more_5deg30s_left());
148 TEST_F(Test_ais_rate_of_turn, value)
151 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_right;
152 rate_of_turn r(val);
153 EXPECT_ANY_THROW(r.value());
156 const rate_of_turn::value_type val = rate_of_turn::more_5deg_per_30s_left;
157 rate_of_turn r(val);
158 EXPECT_ANY_THROW(r.value());
161 rate_of_turn r;
162 EXPECT_ANY_THROW(r.value());
165 const rate_of_turn::value_type val = rate_of_turn::not_turning;
166 rate_of_turn r(val);
167 EXPECT_NEAR(r.value(), 0.0, 1.0e-5);
170 const rate_of_turn::value_type val = 126;
171 rate_of_turn r(val);
172 EXPECT_NEAR(r.value(), 708, 1.0);
175 const rate_of_turn::value_type val = -126;
176 rate_of_turn r(val);
177 EXPECT_NEAR(r.value(), -708.0, 1.0);
180 const rate_of_turn::value_type val = 1;
181 rate_of_turn r(val);
182 EXPECT_NEAR(r.value(), sqr(1.0 / 4.733), 0.001);