mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-23 00:05:28 +03:00
Adding unit test for some gps conversion code to demystify it.
This commit is contained in:
parent
b81f73cb5d
commit
b0e1c934d4
6 changed files with 112 additions and 43 deletions
50
test/gps_conversion_unittest.cc
Normal file
50
test/gps_conversion_unittest.cc
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include "gps_conversion.h"
|
||||
|
||||
#include "unittest_macros.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
// See http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
|
||||
|
||||
TEST(GpsConversionTest, GPSCoordToDegrees_BadString)
|
||||
{
|
||||
// expect
|
||||
uint32_t result = GPS_coord_to_degrees("diediedie");
|
||||
EXPECT_EQ(result, 0);
|
||||
}
|
||||
|
||||
typedef struct gpsConversionExpectation_s {
|
||||
char *coord;
|
||||
uint32_t degrees;
|
||||
} gpsConversionExpectation_t;
|
||||
|
||||
TEST(GpsConversionTest, GPSCoordToDegrees_NMEA_Values)
|
||||
{
|
||||
gpsConversionExpectation_t gpsConversionExpectations[] = {
|
||||
{"0.0", 0},
|
||||
{"000.0", 0},
|
||||
{"00000.0000", 0},
|
||||
{"0.0001", 16}, // smallest value
|
||||
{"25599.9999", 2566666650}, // largest value
|
||||
{"25599.99999", 2566666650}, // too many fractional digits
|
||||
{"25699.9999", 16666650}, // overflowed without detection
|
||||
{"5321.6802", 533613366},
|
||||
{"00630.3372", 65056200},
|
||||
};
|
||||
|
||||
// expect
|
||||
|
||||
uint8_t testIterationCount = sizeof(gpsConversionExpectations) / sizeof(gpsConversionExpectation_t);
|
||||
|
||||
// expect
|
||||
|
||||
for (uint8_t index = 0; index < testIterationCount; index ++) {
|
||||
gpsConversionExpectation_t *expectation = &gpsConversionExpectations[index];
|
||||
printf("iteration: %d\n", index);
|
||||
|
||||
uint32_t result = GPS_coord_to_degrees(expectation->coord);
|
||||
EXPECT_EQ(result, expectation->degrees);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue