From 859185ac72877a305b3e08d98a6ace8ae8196c92 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Fri, 2 Jan 2015 17:44:28 -0500 Subject: move autodeclination unittest to gtest and delete the sample --- unittests/autodeclination_test.cpp | 53 +++++++------------------------------- 1 file changed, 9 insertions(+), 44 deletions(-) (limited to 'unittests/autodeclination_test.cpp') diff --git a/unittests/autodeclination_test.cpp b/unittests/autodeclination_test.cpp index 1bda6eb79..a27d5f100 100644 --- a/unittests/autodeclination_test.cpp +++ b/unittests/autodeclination_test.cpp @@ -1,52 +1,17 @@ - +#include #include #include -#include #include -#include -#include -#include +#include + #include -#include -// #include "../../src/systemcmds/tests/tests.h" #include +#include +#include +#include -int main(int argc, char *argv[]) { - warnx("autodeclination test started"); - - char* latstr = 0; - char* lonstr = 0; - char* declstr = 0; - - if (argc < 4) { - warnx("Too few arguments. Using default lat / lon and declination"); - latstr = "47.0"; - lonstr = "8.0"; - declstr = "0.6"; - } else { - latstr = argv[1]; - lonstr = argv[2]; - declstr = argv[3]; - } - - char* p_end; - - float lat = strtod(latstr, &p_end); - float lon = strtod(lonstr, &p_end); - float decl_truth = strtod(declstr, &p_end); - - float declination = get_mag_declination(lat, lon); - - printf("lat: %f lon: %f, expected dec: %f, estimated dec: %f\n", lat, lon, declination, decl_truth); - - int ret = 0; - - // Fail if the declination differs by more than one degree - float decldiff = fabs(decl_truth - declination); - if (decldiff > 0.5f) { - warnx("declination differs more than 1 degree: difference: %12.8f", decldiff); - ret = 1; - } +#include "gtest/gtest.h" - return ret; +TEST(AutoDeclinationTest, AutoDeclination) { + ASSERT_NEAR(get_mag_declination(47.0, 8.0), 0.6, 0.5) << "declination differs more than 1 degree"; } -- cgit v1.2.3