diff options
author | Daniel Agar <daniel@agar.ca> | 2015-01-02 17:44:28 -0500 |
---|---|---|
committer | Daniel Agar <daniel@agar.ca> | 2015-01-02 23:05:43 -0500 |
commit | 859185ac72877a305b3e08d98a6ace8ae8196c92 (patch) | |
tree | b4220aca15696e803cb7eacfc2d02f198fa56087 /unittests/autodeclination_test.cpp | |
parent | 61d57539fb534a7f99ed8416a4102fb5fc0138d2 (diff) | |
download | px4-firmware-859185ac72877a305b3e08d98a6ace8ae8196c92.tar.gz px4-firmware-859185ac72877a305b3e08d98a6ace8ae8196c92.tar.bz2 px4-firmware-859185ac72877a305b3e08d98a6ace8ae8196c92.zip |
move autodeclination unittest to gtest and delete the sample
Diffstat (limited to 'unittests/autodeclination_test.cpp')
-rw-r--r-- | unittests/autodeclination_test.cpp | 53 |
1 files changed, 9 insertions, 44 deletions
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 <math.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <math.h> -#include <systemlib/mixer/mixer.h> -#include <systemlib/err.h> +#include <unistd.h> + #include <drivers/drv_hrt.h> -#include <px4iofirmware/px4io.h> -// #include "../../src/systemcmds/tests/tests.h" #include <geo/geo.h> +#include <px4iofirmware/px4io.h> +#include <systemlib/err.h> +#include <systemlib/mixer/mixer.h> -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"; } |