uhd/host/tests/math_test.cpp
Martin Braun 5ee6b828de uhd: math: Replace wrap-frequency math with a single function
In multiple places in the UHD code, we were doing the same calculation
for a wrapped frequency (wrap it into the first Nyquist zone). This math
was using boost::math, too. Instead of editing every instance, we create
a new function, uhd::math::wrap_frequency(), and replace all of its
separate implementations with this function. The new function also no
longer relies on boost::math::sign.
2021-10-19 12:21:33 -07:00

34 lines
915 B
C++

//
// Copyright 2014 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
#include <uhd/utils/math.hpp>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test_lcm)
{
BOOST_CHECK_EQUAL(uhd::math::lcm<int>(2, 3), 6);
}
BOOST_AUTO_TEST_CASE(test_gcd)
{
BOOST_CHECK_EQUAL(uhd::math::gcd<int>(6, 15), 3);
}
BOOST_AUTO_TEST_CASE(test_sign)
{
BOOST_CHECK_EQUAL(uhd::math::sign(2.3), +1);
BOOST_CHECK_EQUAL(uhd::math::sign(-2.3), -1);
BOOST_CHECK_EQUAL(uhd::math::sign(0.0), 0);
}
BOOST_AUTO_TEST_CASE(test_wrap_frequency)
{
BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(10e6, 200e6), 10e6);
BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(250e6, 200e6), 50e6);
BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(120e6, 200e6), -80e6);
BOOST_CHECK_EQUAL(uhd::math::wrap_frequency(-250e6, 200e6), -50e6);
}