aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/math_test.cpp
blob: 12ede7f0613a1ad9fb9703e9a17d1fd28b6e4a3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//
// 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);
}