diff options
author | Martin Braun <martin.braun@ettus.com> | 2018-06-21 16:12:51 -0700 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-06-23 00:17:18 +0200 |
commit | 1f30b5b14f6d5a189a44565d0f7e4e8618bfa864 (patch) | |
tree | 38c38c2e2e98ee04e721cc01b9251052835a110f /gnuradio-runtime/lib/math | |
parent | 136fc7225ea99fae34813b0b2968dced6abdf95f (diff) |
runtime: Replace QA test framework w/ Boost UTF
Diffstat (limited to 'gnuradio-runtime/lib/math')
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fast_atan2f.cc | 35 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fast_atan2f.h | 41 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt.cc | 57 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt.h | 47 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt_nco.cc | 39 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt_nco.h | 47 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt_vco.cc | 36 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_fxpt_vco.h | 47 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_math.cc | 28 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_math.h | 42 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_sincos.cc | 21 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/qa_sincos.h | 41 |
12 files changed, 85 insertions, 396 deletions
diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc index 9584a578a1..423a8bc415 100644 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.cc +++ b/gnuradio-runtime/lib/math/qa_fast_atan2f.cc @@ -24,9 +24,8 @@ #include <config.h> #endif -#include <qa_fast_atan2f.h> #include <gnuradio/math.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <cmath> #include <limits> @@ -36,9 +35,7 @@ #define ISNAN std::isnan #endif -void -qa_fast_atan2f::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { static const unsigned int N = 100; float c_atan2; float gr_atan2f; @@ -51,14 +48,12 @@ qa_fast_atan2f::t1() gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); } } } -void -qa_fast_atan2f::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { float c_atan2; float gr_atan2f; float x, y; @@ -71,13 +66,13 @@ qa_fast_atan2f::t2() y = 0; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); x = -inf; y = 0; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); /* Test y as INF */ @@ -85,53 +80,53 @@ qa_fast_atan2f::t2() y = inf; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); x = 0; y = -inf; c_atan2 = atan2(y, x); gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_atan2, gr_atan2f, 0.0); + BOOST_CHECK_CLOSE(c_atan2, gr_atan2f, 0.0); /* Test x and y as INF */ x = inf; y = inf; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); /* Test x as NAN */ x = nan; y = 0; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); x = -nan; y = 0; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); /* Test y as NAN */ x = 0; y = nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); x = 0; y = -nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0f, gr_atan2f, 0.0001); + BOOST_CHECK_CLOSE(0.0f, gr_atan2f, 0.0001); /* Test mixed NAN and INF */ x = inf; y = nan; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); x = nan; y = inf; gr_atan2f = gr::fast_atan2f(y, x); - CPPUNIT_ASSERT(ISNAN(gr_atan2f)); + BOOST_CHECK(ISNAN(gr_atan2f)); } diff --git a/gnuradio-runtime/lib/math/qa_fast_atan2f.h b/gnuradio-runtime/lib/math/qa_fast_atan2f.h deleted file mode 100644 index d72ad671d7..0000000000 --- a/gnuradio-runtime/lib/math/qa_fast_atan2f.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _QA_FAST_ATAN2F_H_ -#define _QA_FAST_ATAN2F_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fast_atan2f : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fast_atan2f); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST_SUITE_END(); - -private: - void t1(); - void t2(); -}; - -#endif /* _QA_FAST_ATAN2F_H_ */ diff --git a/gnuradio-runtime/lib/math/qa_fxpt.cc b/gnuradio-runtime/lib/math/qa_fxpt.cc index d3aadf85b1..f369cd356a 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt.cc @@ -24,9 +24,8 @@ #include <config.h> #endif -#include <qa_fxpt.h> #include <gnuradio/fxpt.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -34,12 +33,10 @@ static const float SIN_COS_TOLERANCE = 1e-5; -void -qa_fxpt::t0() -{ - CPPUNIT_ASSERT_DOUBLES_EQUAL(M_PI/2, gr::fxpt::fixed_to_float(0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, gr::fxpt::fixed_to_float(0x00000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-M_PI, gr::fxpt::fixed_to_float(0x80000000), SIN_COS_TOLERANCE); +BOOST_AUTO_TEST_CASE(t0) { + BOOST_CHECK(std::abs(M_PI/2 - gr::fxpt::fixed_to_float(0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(0.0 - gr::fxpt::fixed_to_float(0x00000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-M_PI - gr::fxpt::fixed_to_float(0x80000000)) <= SIN_COS_TOLERANCE); if(0) { /* @@ -51,52 +48,46 @@ qa_fxpt::t0() * sometimes the answer is off by a few bits at the bottom. * Hence, the disabled check. */ - CPPUNIT_ASSERT_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(M_PI/2)); - CPPUNIT_ASSERT_EQUAL((int32_t)0, gr::fxpt::float_to_fixed(0)); - CPPUNIT_ASSERT_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-M_PI)); + BOOST_CHECK_EQUAL((int32_t)0x40000000, gr::fxpt::float_to_fixed(M_PI/2)); + BOOST_CHECK_EQUAL((int32_t)0, gr::fxpt::float_to_fixed(0)); + BOOST_CHECK_EQUAL((int32_t)0x80000000, gr::fxpt::float_to_fixed(-M_PI)); } } -void -qa_fxpt::t1() -{ - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x00000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106781, gr::fxpt::sin(0x20000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 1, gr::fxpt::sin(0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106781, gr::fxpt::sin(0x60000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x7fffffff), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x80000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, gr::fxpt::sin(0x80000001), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-1, gr::fxpt::sin(-0x40000000), SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(-0.707106781, gr::fxpt::sin(-0x20000000), SIN_COS_TOLERANCE); +BOOST_AUTO_TEST_CASE(t1) { + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x00000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0.707106781 - gr::fxpt::sin(0x20000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 1 - gr::fxpt::sin(0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0.707106781 - gr::fxpt::sin(0x60000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x7fffffff)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x80000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs( 0 - gr::fxpt::sin(0x80000001)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-1 - gr::fxpt::sin(-0x40000000)) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(-0.707106781 - gr::fxpt::sin(-0x20000000)) <= SIN_COS_TOLERANCE); for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) { float expected = sin(p); float actual = gr::fxpt::sin(gr::fxpt::float_to_fixed (p)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE); } } -void -qa_fxpt::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) { float expected = cos(p); float actual = gr::fxpt::cos(gr::fxpt::float_to_fixed(p)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected - actual) <= SIN_COS_TOLERANCE); } } -void -qa_fxpt::t3() -{ +BOOST_AUTO_TEST_CASE(t3) { for(float p = -M_PI; p < M_PI; p += 2 * M_PI / 3600) { float expected_sin = sin(p); float expected_cos = cos(p); float actual_sin; float actual_cos; gr::fxpt::sincos(gr::fxpt::float_to_fixed (p), &actual_sin, &actual_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_sin, actual_sin, SIN_COS_TOLERANCE); - CPPUNIT_ASSERT_DOUBLES_EQUAL(expected_cos, actual_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected_sin - actual_sin) <= SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(expected_cos - actual_cos) <= SIN_COS_TOLERANCE); } } diff --git a/gnuradio-runtime/lib/math/qa_fxpt.h b/gnuradio-runtime/lib/math/qa_fxpt.h deleted file mode 100644 index 58a6f02d1b..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_H -#define INCLUDED_QA_GR_FXPT_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - - private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc index 16ea120381..cd05747630 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt_nco.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt_nco.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2013 Free Software Foundation, Inc. + * Copyright 2004,2013,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,10 +24,9 @@ #include <config.h> #endif -#include <qa_fxpt_nco.h> #include <gnuradio/fxpt_nco.h> #include <gnuradio/nco.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -45,9 +44,8 @@ static double max_d(double a, double b) return fabs(a) > fabs(b) ? a : b; } -void -qa_fxpt_nco::t0() -{ + +BOOST_AUTO_TEST_CASE(t0) { gr::nco<float,float> ref_nco; gr::fxpt_nco new_nco; double max_error = 0, max_phase_error = 0; @@ -55,35 +53,33 @@ qa_fxpt_nco::t0() ref_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ)); new_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { float ref_sin = ref_nco.sin(); float new_sin = new_nco.sin(); //printf ("i = %6d\n", i); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_sin, new_sin, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_sin - new_sin) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_sin-new_sin); float ref_cos = ref_nco.cos(); float new_cos = new_nco.cos(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_cos, new_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_cos - new_cos) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_cos-new_cos); ref_nco.step(); new_nco.step(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_phase() - new_nco.get_phase()) <= SIN_COS_TOLERANCE); max_phase_error = max_d(max_phase_error, ref_nco.get_phase()-new_nco.get_phase()); } // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); } -void -qa_fxpt_nco::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { gr::nco<float,float> ref_nco; gr::fxpt_nco new_nco; gr_complex* ref_block = new gr_complex[SIN_COS_BLOCK_SIZE]; @@ -93,30 +89,21 @@ qa_fxpt_nco::t1() ref_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ)); new_nco.set_freq((float)(2 * M_PI / SIN_COS_FREQ)); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_nco.get_freq(), new_nco.get_freq(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_freq() - new_nco.get_freq()) <= SIN_COS_TOLERANCE); ref_nco.sincos((gr_complex*)ref_block, SIN_COS_BLOCK_SIZE); new_nco.sincos((gr_complex*)new_block, SIN_COS_BLOCK_SIZE); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].real(), new_block[i].real(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i].real() - new_block[i].real()) <= SIN_COS_TOLERANCE); max_error = max_d (max_error, ref_block[i].real()-new_block[i].real()); - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_block[i].imag(), new_block[i].imag(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i].imag() - new_block[i].imag()) <= SIN_COS_TOLERANCE); max_error = max_d (max_error, ref_block[i].imag()-new_block[i].imag()); } - CPPUNIT_ASSERT_DOUBLES_EQUAL (ref_nco.get_phase(), new_nco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_nco.get_phase() - new_nco.get_phase()) <= SIN_COS_TOLERANCE); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); delete[] ref_block; delete[] new_block; } -void -qa_fxpt_nco::t2() -{ -} - -void -qa_fxpt_nco::t3() -{ -} diff --git a/gnuradio-runtime/lib/math/qa_fxpt_nco.h b/gnuradio-runtime/lib/math/qa_fxpt_nco.h deleted file mode 100644 index 1b2cdaede6..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt_nco.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_NCO_H -#define INCLUDED_QA_GR_FXPT_NCO_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt_nco : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt_nco); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - -private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_NCO_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_fxpt_vco.cc b/gnuradio-runtime/lib/math/qa_fxpt_vco.cc index a406c12c0f..d4952fe25c 100644 --- a/gnuradio-runtime/lib/math/qa_fxpt_vco.cc +++ b/gnuradio-runtime/lib/math/qa_fxpt_vco.cc @@ -24,10 +24,9 @@ #include <config.h> #endif -#include <qa_fxpt_vco.h> +#include "vco.h" #include <gnuradio/fxpt_vco.h> -#include <vco.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <iostream> #include <stdio.h> #include <unistd.h> @@ -45,9 +44,7 @@ static double max_d(double a, double b) return fabs(a) > fabs(b) ? a : b; } -void -qa_fxpt_vco::t0() -{ +BOOST_AUTO_TEST_CASE(t0) { gr::vco<float,float> ref_vco; gr::fxpt_vco new_vco; double max_error = 0, max_phase_error = 0; @@ -60,23 +57,21 @@ qa_fxpt_vco::t0() for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { float ref_cos = ref_vco.cos(); float new_cos = new_vco.cos(); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_cos, new_cos, SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_cos - new_cos) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_cos-new_cos); ref_vco.adjust_phase(input[i]); new_vco.adjust_phase(input[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE); max_phase_error = max_d(max_phase_error, ref_vco.get_phase()-new_vco.get_phase()); } // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, max_phase_error); } -void -qa_fxpt_vco::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { gr::vco<float,float> ref_vco; gr::fxpt_vco new_vco; float *ref_block = new float[SIN_COS_BLOCK_SIZE]; @@ -92,19 +87,18 @@ qa_fxpt_vco::t1() new_vco.cos(new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_block[i], new_block[i], SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i] - new_block[i]) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, ref_block[i]-new_block[i]); } - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase()); delete[] ref_block; delete[] new_block; delete[] input; } -void -qa_fxpt_vco::t2() -{ + +BOOST_AUTO_TEST_CASE(t2) { gr::vco<gr_complex,float> ref_vco; gr::fxpt_vco new_vco; gr_complex *ref_block = new gr_complex[SIN_COS_BLOCK_SIZE]; @@ -120,17 +114,15 @@ qa_fxpt_vco::t2() new_vco.sincos(new_block, input, SIN_COS_BLOCK_SIZE, SIN_COS_K, SIN_COS_AMPL); for(int i = 0; i < SIN_COS_BLOCK_SIZE; i++) { - CPPUNIT_ASSERT_COMPLEXES_EQUAL(ref_block[i], new_block[i], SIN_COS_TOLERANCE); + BOOST_CHECK(std::abs(ref_block[i] - new_block[i]) <= SIN_COS_TOLERANCE); max_error = max_d(max_error, abs(ref_block[i]-new_block[i])); } - CPPUNIT_ASSERT_DOUBLES_EQUAL(ref_vco.get_phase(), new_vco.get_phase(), SIN_COS_TOLERANCE); + BOOST_CHECK( + std::abs(ref_vco.get_phase() - new_vco.get_phase()) <= SIN_COS_TOLERANCE + ); // printf ("Fxpt max error %.9f, max phase error %.9f\n", max_error, ref_vco.get_phase()-new_vco.get_phase()); delete[] ref_block; delete[] new_block; delete[] input; } -void -qa_fxpt_vco::t3() -{ -} diff --git a/gnuradio-runtime/lib/math/qa_fxpt_vco.h b/gnuradio-runtime/lib/math/qa_fxpt_vco.h deleted file mode 100644 index 72693f32e2..0000000000 --- a/gnuradio-runtime/lib/math/qa_fxpt_vco.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2004,2005,2013 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDED_QA_GR_FXPT_VCO_H -#define INCLUDED_QA_GR_FXPT_VCO_H - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_fxpt_vco : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_fxpt_vco); - CPPUNIT_TEST(t0); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST(t3); - CPPUNIT_TEST_SUITE_END(); - -private: - void t0(); - void t1(); - void t2(); - void t3(); -}; - -#endif /* INCLUDED_QA_GR_FXPT_VCO_H */ - - diff --git a/gnuradio-runtime/lib/math/qa_math.cc b/gnuradio-runtime/lib/math/qa_math.cc index 1fb43cc67f..da8322059c 100644 --- a/gnuradio-runtime/lib/math/qa_math.cc +++ b/gnuradio-runtime/lib/math/qa_math.cc @@ -20,13 +20,11 @@ */ #include <gnuradio/math.h> -#include <qa_math.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <stdio.h> +#include <cmath> -void -qa_math::test_binary_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_binary_slicer1) { float x[5] = {-1, -0.5, 0, 0.5, 1.0}; unsigned int z[5] = {0, 0, 1, 1, 1}; unsigned int y; @@ -36,7 +34,7 @@ qa_math::test_binary_slicer1() y = gr::binary_slicer(x[i]); //printf("in: %f out: %d desired: %d\n", x[i], y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Binary\n"); @@ -44,13 +42,11 @@ qa_math::test_binary_slicer1() y = gr::branchless_binary_slicer(x[i]); //printf("in: %f out: %d desired: %d\n", x[i], y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } -void -qa_math::test_quad_0deg_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_quad_0deg_slicer1) { gr_complex x[4] = {gr_complex(1, 0), gr_complex(0, 1), gr_complex(-1, 0), @@ -64,7 +60,7 @@ qa_math::test_quad_0deg_slicer1() y = gr::quad_0deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Quad0\n"); @@ -72,13 +68,11 @@ qa_math::test_quad_0deg_slicer1() y = gr::branchless_quad_0deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } -void -qa_math::test_quad_45deg_slicer1() -{ +BOOST_AUTO_TEST_CASE(test_quad_45deg_slicer1) { gr_complex x[4] = {gr_complex(0.707, 0.707), gr_complex(-0.707, 0.707), gr_complex(-0.707, -0.707), @@ -92,7 +86,7 @@ qa_math::test_quad_45deg_slicer1() y = gr::quad_45deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } //printf("\nBranchless Quad45\n"); @@ -100,6 +94,6 @@ qa_math::test_quad_45deg_slicer1() y = gr::branchless_quad_45deg_slicer(x[i]); //printf("in: %.4f+j%.4f out: %d desired: %d\n", x[i].real(), x[i].imag(), y, z[i]); - CPPUNIT_ASSERT_DOUBLES_EQUAL(y, z[i], 1e-9); + BOOST_CHECK_EQUAL(y, z[i]); } } diff --git a/gnuradio-runtime/lib/math/qa_math.h b/gnuradio-runtime/lib/math/qa_math.h deleted file mode 100644 index 3621283b37..0000000000 --- a/gnuradio-runtime/lib/math/qa_math.h +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2008 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ -#ifndef _QA_GR_MATH_H_ -#define _QA_GR_MATH_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_math : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_math); - CPPUNIT_TEST(test_binary_slicer1); - CPPUNIT_TEST(test_quad_0deg_slicer1); - CPPUNIT_TEST(test_quad_45deg_slicer1); - CPPUNIT_TEST_SUITE_END(); - - private: - void test_binary_slicer1(); - void test_quad_0deg_slicer1(); - void test_quad_45deg_slicer1(); -}; - -#endif /* _QA_GR_MATH_H_ */ diff --git a/gnuradio-runtime/lib/math/qa_sincos.cc b/gnuradio-runtime/lib/math/qa_sincos.cc index a6234d19d6..4ce81fb4f8 100644 --- a/gnuradio-runtime/lib/math/qa_sincos.cc +++ b/gnuradio-runtime/lib/math/qa_sincos.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012,2018 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -24,14 +24,11 @@ #include <config.h> #endif -#include <qa_sincos.h> #include <gnuradio/sincos.h> -#include <cppunit/TestAssert.h> +#include <boost/test/unit_test.hpp> #include <cmath> -void -qa_sincos::t1() -{ +BOOST_AUTO_TEST_CASE(t1) { static const unsigned int N = 1000; double c_sin, c_cos; double gr_sin, gr_cos; @@ -43,14 +40,12 @@ qa_sincos::t1() gr::sincos(x, &gr_sin, &gr_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + BOOST_CHECK_CLOSE(c_sin, gr_sin, 0.0001); + BOOST_CHECK_CLOSE(c_cos, gr_cos, 0.0001); } } -void -qa_sincos::t2() -{ +BOOST_AUTO_TEST_CASE(t2) { static const unsigned int N = 1000; float c_sin, c_cos; float gr_sin, gr_cos; @@ -62,7 +57,7 @@ qa_sincos::t2() gr::sincosf(x, &gr_sin, &gr_cos); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_sin, gr_sin, 0.0001); - CPPUNIT_ASSERT_DOUBLES_EQUAL(c_cos, gr_cos, 0.0001); + BOOST_CHECK_CLOSE(c_sin, gr_sin, 0.0001); + BOOST_CHECK_CLOSE(c_cos, gr_cos, 0.0001); } } diff --git a/gnuradio-runtime/lib/math/qa_sincos.h b/gnuradio-runtime/lib/math/qa_sincos.h deleted file mode 100644 index 9fec5958c0..0000000000 --- a/gnuradio-runtime/lib/math/qa_sincos.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _QA_SINCOS_H_ -#define _QA_SINCOS_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/TestCase.h> - -class qa_sincos : public CppUnit::TestCase -{ - CPPUNIT_TEST_SUITE(qa_sincos); - CPPUNIT_TEST(t1); - CPPUNIT_TEST(t2); - CPPUNIT_TEST_SUITE_END(); - -private: - void t1(); - void t2(); -}; - -#endif /* _QA_SINCOS_H_ */ |