test_gps.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #include <AP_GPS/AP_GPS_NMEA.h>
  19. const AP_HAL::HAL &hal = AP_HAL::get_HAL();
  20. class AP_GPS_NMEA_Test
  21. {
  22. public:
  23. int32_t parse_decimal_100(const char *p) const
  24. {
  25. return AP_GPS_NMEA::_parse_decimal_100(p);
  26. }
  27. };
  28. TEST(AP_GPS_NMEA, parse_decimal_100)
  29. {
  30. AP_GPS_NMEA_Test test;
  31. /* Positive numbers with possible round/truncate */
  32. ASSERT_EQ(100, test.parse_decimal_100("1.0"));
  33. ASSERT_EQ(100, test.parse_decimal_100("1.00"));
  34. ASSERT_EQ(100, test.parse_decimal_100("1.001"));
  35. ASSERT_EQ(101, test.parse_decimal_100("1.006"));
  36. /* Positive numbers with possible round/truncate with + signal */
  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. /* Positive numbers in (0, 1) range, with possible round/truncate */
  42. ASSERT_EQ(0, test.parse_decimal_100("0.0"));
  43. ASSERT_EQ(0, test.parse_decimal_100("0.00"));
  44. ASSERT_EQ(0, test.parse_decimal_100("0.001"));
  45. ASSERT_EQ(1, test.parse_decimal_100("0.006"));
  46. /* Negative numbers with possible round/truncate */
  47. ASSERT_EQ(-100, test.parse_decimal_100("-1.0"));
  48. ASSERT_EQ(-100, test.parse_decimal_100("-1.00"));
  49. ASSERT_EQ(-100, test.parse_decimal_100("-1.001"));
  50. ASSERT_EQ(-101, test.parse_decimal_100("-1.006"));
  51. /* Integer numbers */
  52. ASSERT_EQ(100, test.parse_decimal_100("1"));
  53. ASSERT_EQ(-100, test.parse_decimal_100("-1"));
  54. }
  55. AP_GTEST_MAIN()