CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_GPS/tests/test_gps.cpp
Views: 1799
1
/*
2
* Copyright (C) 2016 Intel Corporation. All rights reserved.
3
*
4
* This file is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This file is distributed in the hope that it will be useful, but
10
* WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
* See the GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
#include <AP_gtest.h>
18
19
#include <AP_GPS/AP_GPS_NMEA.h>
20
21
const AP_HAL::HAL &hal = AP_HAL::get_HAL();
22
23
class AP_GPS_NMEA_Test
24
{
25
public:
26
int32_t parse_decimal_100(const char *p) const
27
{
28
return AP_GPS_NMEA::_parse_decimal_100(p);
29
}
30
};
31
32
TEST(AP_GPS_NMEA, parse_decimal_100)
33
{
34
AP_GPS_NMEA_Test test;
35
36
/* Positive numbers with possible round/truncate */
37
ASSERT_EQ(100, test.parse_decimal_100("1.0"));
38
ASSERT_EQ(100, test.parse_decimal_100("1.00"));
39
ASSERT_EQ(100, test.parse_decimal_100("1.001"));
40
ASSERT_EQ(101, test.parse_decimal_100("1.006"));
41
42
/* Positive numbers with possible round/truncate with + signal */
43
ASSERT_EQ(100, test.parse_decimal_100("+1.0"));
44
ASSERT_EQ(100, test.parse_decimal_100("+1.00"));
45
ASSERT_EQ(100, test.parse_decimal_100("+1.001"));
46
ASSERT_EQ(101, test.parse_decimal_100("+1.006"));
47
48
/* Positive numbers in (0, 1) range, with possible round/truncate */
49
ASSERT_EQ(0, test.parse_decimal_100("0.0"));
50
ASSERT_EQ(0, test.parse_decimal_100("0.00"));
51
ASSERT_EQ(0, test.parse_decimal_100("0.001"));
52
ASSERT_EQ(1, test.parse_decimal_100("0.006"));
53
54
/* Negative numbers with possible round/truncate */
55
ASSERT_EQ(-100, test.parse_decimal_100("-1.0"));
56
ASSERT_EQ(-100, test.parse_decimal_100("-1.00"));
57
ASSERT_EQ(-100, test.parse_decimal_100("-1.001"));
58
ASSERT_EQ(-101, test.parse_decimal_100("-1.006"));
59
60
/* Integer numbers */
61
ASSERT_EQ(100, test.parse_decimal_100("1"));
62
ASSERT_EQ(-100, test.parse_decimal_100("-1"));
63
}
64
65
AP_GTEST_MAIN()
66
67