aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2020-03-31 21:38:13 -0700
committerAaron Rossetto <aaron.rossetto@ni.com>2020-04-07 07:24:19 -0500
commitd9f4d540ef334013eb404ce91b3b446e5fc917ff (patch)
treee5b7b405f567d414b24f5acca2aae78bc27267a5 /host/tests
parentff17d7428be5af109a2a74f916271761505ebee7 (diff)
downloaduhd-d9f4d540ef334013eb404ce91b3b446e5fc917ff.tar.gz
uhd-d9f4d540ef334013eb404ce91b3b446e5fc917ff.tar.bz2
uhd-d9f4d540ef334013eb404ce91b3b446e5fc917ff.zip
uhd: math: Add interpolation.hpp
- Moves linear_interp from cal to utils - Moves the interp_mode enum class to interpolation.hpp - Adds three interpolation methods for maps: at_interpolate_1d(), at_nearest(), at_lin_interp() - Adds unit tests
Diffstat (limited to 'host/tests')
-rw-r--r--host/tests/CMakeLists.txt1
-rw-r--r--host/tests/cal_data_iq_test.cpp1
-rw-r--r--host/tests/interpolation_test.cpp35
-rw-r--r--host/tests/math_test.cpp10
4 files changed, 37 insertions, 10 deletions
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 3665a9d17..33bcdb734 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -36,6 +36,7 @@ set(test_sources
fp_compare_delta_test.cpp
fp_compare_epsilon_test.cpp
gain_group_test.cpp
+ interpolation_test.cpp
isatty_test.cpp
log_test.cpp
math_test.cpp
diff --git a/host/tests/cal_data_iq_test.cpp b/host/tests/cal_data_iq_test.cpp
index 97b35a331..523a4310e 100644
--- a/host/tests/cal_data_iq_test.cpp
+++ b/host/tests/cal_data_iq_test.cpp
@@ -10,6 +10,7 @@
#include <iostream>
using namespace uhd::usrp::cal;
+using namespace uhd::math;
BOOST_AUTO_TEST_CASE(test_iq_cal_api)
{
diff --git a/host/tests/interpolation_test.cpp b/host/tests/interpolation_test.cpp
new file mode 100644
index 000000000..b3314c34a
--- /dev/null
+++ b/host/tests/interpolation_test.cpp
@@ -0,0 +1,35 @@
+//
+// Copyright 2020 Ettus Research, a National Instruments Brand
+//
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+
+#include <uhdlib/utils/interpolation.hpp>
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(test_interp)
+{
+ const double x0 = 1.0, x1 = 2.0;
+ const double y0 = 2.0, y1 = 4.0;
+ const double x = 1.5;
+ const double y_exp = 3.0;
+
+ BOOST_CHECK_EQUAL(uhd::math::linear_interp<double>(x, x0, y0, x1, y1), y_exp);
+}
+
+BOOST_AUTO_TEST_CASE(test_map_interp)
+{
+ using namespace uhd::math;
+ std::map<double, double> test_data{{1.0, 1.0}, {2.0, 2.0}, {3.0, 3.0}};
+
+ BOOST_CHECK_EQUAL(at_nearest(test_data, 1.1), 1.0);
+ BOOST_CHECK_EQUAL(at_nearest(test_data, 1.9), 2.0);
+ BOOST_CHECK_EQUAL(at_nearest(test_data, 2.1), 2.0);
+ BOOST_CHECK_EQUAL(at_nearest(test_data, 1e9), 3.0);
+
+ BOOST_CHECK_CLOSE(at_lin_interp(test_data, 1.5), 1.5, 1e-6);
+ BOOST_CHECK_EQUAL(at_lin_interp(test_data, 0.1), 1.0);
+ BOOST_CHECK_EQUAL(at_lin_interp(test_data, 2.0), 2.0);
+ BOOST_CHECK_EQUAL(at_lin_interp(test_data, 137.0), 3.0);
+}
+
diff --git a/host/tests/math_test.cpp b/host/tests/math_test.cpp
index bff6fc16f..c1b6793bb 100644
--- a/host/tests/math_test.cpp
+++ b/host/tests/math_test.cpp
@@ -17,13 +17,3 @@ BOOST_AUTO_TEST_CASE(test_gcd)
{
BOOST_CHECK_EQUAL(uhd::math::gcd<int>(6, 15), 3);
}
-
-BOOST_AUTO_TEST_CASE(test_interp)
-{
- const double x0 = 1.0, x1 = 2.0;
- const double y0 = 2.0, y1 = 4.0;
- const double x = 1.5;
- const double y_exp = 3.0;
-
- BOOST_CHECK_EQUAL(uhd::math::linear_interp<double>(x, x0, y0, x1, y1), y_exp);
-}