APM:Libraries
test_gps.cpp
Go to the documentation of this file.
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 
22 
24 {
25 public:
26  int32_t parse_decimal_100(const char *p) const
27  {
29  }
30 };
31 
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()
const HAL & get_HAL()
NMEA protocol parser.
TEST(AP_GPS_NMEA, parse_decimal_100)
Definition: test_gps.cpp:32
static int32_t _parse_decimal_100(const char *p)
int32_t parse_decimal_100(const char *p) const
Definition: test_gps.cpp:26
const AP_HAL::HAL & hal
-*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
Definition: test_gps.cpp:21