From fc34eef53ab7535699f4169c77138df7ee01a137 Mon Sep 17 00:00:00 2001 From: Stephan Brown Date: Thu, 2 Feb 2017 12:09:35 -0800 Subject: [PATCH] unittests: Add unittests for geo_mag_declination. --- unittests/CMakeLists.txt | 2 ++ unittests/geomag_test.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 unittests/geomag_test.cpp diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 2c76e6f2d3..f338d4ddee 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -110,3 +110,5 @@ add_executable(param_test param_test.cpp uorb_stub.cpp ${PX4_SRC}/modules/systemlib/param/param.c) target_link_libraries(param_test ${PX4_PLATFORM}) add_gtest(param_test) +add_executable(geomag_test geomag_test.cpp) +add_gtest(geomag_test) diff --git a/unittests/geomag_test.cpp b/unittests/geomag_test.cpp new file mode 100644 index 0000000000..d924dd0446 --- /dev/null +++ b/unittests/geomag_test.cpp @@ -0,0 +1,16 @@ +#include + +#include "gtest/gtest.h" + +TEST(GeoMagTest, IndexBoundsCheck) +{ + unsigned index = get_lookup_table_index(90.0f, SAMPLING_MIN_LAT, SAMPLING_MAX_LAT); + ASSERT_EQ((unsigned)11, index); + index = get_lookup_table_index(-90.0f, SAMPLING_MIN_LAT, SAMPLING_MAX_LAT); + ASSERT_EQ((unsigned)0, index); + index = get_lookup_table_index(180.0f, SAMPLING_MIN_LON, SAMPLING_MAX_LON); + ASSERT_EQ((unsigned)35, index); + index = get_lookup_table_index(-180.0f, SAMPLING_MIN_LON, SAMPLING_MAX_LON); + ASSERT_EQ((unsigned)0, index); +} +