1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +03:00
betaflight/test/gps_conversion_unittest.cc
Dominic Clifton 10279c0178 Updated GPS logitude/latitude calculation.
The existing implementation that was ported over was trying to work with
different values.  By writing a unit test for the code that stores
values in GPS_coord it was possible to have known values which could
then also be used to write a unit test for the HoTT telemetry which
finally enabled production code to be written.

Hopefully it will work, unable to test further since my GPS unit is
playing up.
2014-05-24 21:16:02 +01:00

52 lines
1.4 KiB
C++

#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", 2566666650UL}, // largest value
{"25599.99999", 2566666650UL}, // too many fractional digits
{"25699.9999", 16666650UL}, // overflowed without detection
{"5128.3727", 514728783UL},
{"5321.6802", 533613366UL},
{"00630.3372", 65056200UL},
};
// 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);
}
}